From cf2b7763173d5c3e5052b1f6d1b06b0eeed02939 Mon Sep 17 00:00:00 2001 From: Brian Schlining Date: Thu, 29 Feb 2024 12:37:52 -0800 Subject: [PATCH] fathomnet/fathomnet-py#25 - prepping release --- .../org/fathomnet/worms/StateController.scala | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/scala/org/fathomnet/worms/StateController.scala b/src/main/scala/org/fathomnet/worms/StateController.scala index 54dee81..0c3d35d 100644 --- a/src/main/scala/org/fathomnet/worms/StateController.scala +++ b/src/main/scala/org/fathomnet/worms/StateController.scala @@ -90,6 +90,7 @@ object StateController: else candidate.map(c => { val alternateNames = (outdated.flatMap(n => n.names) ++ c.alternateNames) + .filter(s => s != c.acceptedName) .toSet .toSeq .sorted @@ -138,15 +139,18 @@ object StateController: ) def synonyms(name: String): Either[ErrorMsg, List[String]] = - def search(data: Data): List[String] = - data.findNodeByName(name) match - case None => Nil - case Some(node) => node.names.toList + for + node <- taxaInfo(name) + names <- findNamesByAphiaId(node.acceptedAphiaId) + yield + val alternativeNames = if (names.acceptedName == name) + names.alternateNames.toList + else + names.name :: names.alternateNames.toList + + names.acceptedName +: alternativeNames.filter(s => s != names.acceptedName).distinct.sorted + - runSearch(search).fold( - e => Left(e), - v => if (v.isEmpty) Left(NotFound(s"Unable to find `$name`")) else Right(v) - ) def descendantTaxa(name: String): Either[ErrorMsg, WormsNode] = def search(data: Data): Option[WormsNode] =