From 1b14464a6c7594997ae2bf595ba9c69b3dd6a74a Mon Sep 17 00:00:00 2001 From: Brian Schlining Date: Mon, 21 Oct 2024 16:52:15 -0700 Subject: [PATCH] empty values are returned as null --- project/build.properties | 2 +- src/main/scala/org/fathomnet/worms/Data.scala | 2 ++ .../fathomnet/worms/io/MutableWormsNode.scala | 2 +- .../org/fathomnet/worms/io/WormsConcept.scala | 10 +++++----- .../scala/org/fathomnet/worms/io/model.scala | 16 +++++++++------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/project/build.properties b/project/build.properties index ee4c672..bc73906 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.10.1 +sbt.version=1.10.3 diff --git a/src/main/scala/org/fathomnet/worms/Data.scala b/src/main/scala/org/fathomnet/worms/Data.scala index 217aebc..8e19010 100644 --- a/src/main/scala/org/fathomnet/worms/Data.scala +++ b/src/main/scala/org/fathomnet/worms/Data.scala @@ -69,3 +69,5 @@ final case class Data(rootNode: WormsNode, wormsConcepts: Seq[WormsConcept]): case (parent, Some(child)) => val newParent = parent.copy(children = Seq(child)) Some(newParent) + + diff --git a/src/main/scala/org/fathomnet/worms/io/MutableWormsNode.scala b/src/main/scala/org/fathomnet/worms/io/MutableWormsNode.scala index 23e4351..621b861 100644 --- a/src/main/scala/org/fathomnet/worms/io/MutableWormsNode.scala +++ b/src/main/scala/org/fathomnet/worms/io/MutableWormsNode.scala @@ -71,7 +71,7 @@ object MutableWormsNodeBuilder: rows.filter(wc => val lr = wc.rank.toLowerCase // (!lr.contains("species") && !lr.contains("variety")) || (!wc.isExtinct && wc.isMarine) - (!lr.contains("species") && !lr.contains("variety")) || (!wc.isExtinct) + (!lr.contains("species") && !lr.contains("variety")) || (!wc.isExtinct.getOrElse(false)) ) /** diff --git a/src/main/scala/org/fathomnet/worms/io/WormsConcept.scala b/src/main/scala/org/fathomnet/worms/io/WormsConcept.scala index 717bc05..5c8b696 100644 --- a/src/main/scala/org/fathomnet/worms/io/WormsConcept.scala +++ b/src/main/scala/org/fathomnet/worms/io/WormsConcept.scala @@ -21,11 +21,11 @@ final case class WormsConcept( parentId: Option[Long], names: Seq[WormsConceptName], rank: String, - isMarine: Boolean = false, - isFreshwater: Boolean = false, - isTerrestrial: Boolean = false, - isExtinct: Boolean = false, - isBrackish: Boolean = false + isMarine: Option[Boolean] = None, + isFreshwater: Option[Boolean] = None, + isTerrestrial: Option[Boolean] = None, + isExtinct: Option[Boolean] = None, + isBrackish: Option[Boolean] = None ) object WormsConcept: diff --git a/src/main/scala/org/fathomnet/worms/io/model.scala b/src/main/scala/org/fathomnet/worms/io/model.scala index b3b6317..5811bbc 100644 --- a/src/main/scala/org/fathomnet/worms/io/model.scala +++ b/src/main/scala/org/fathomnet/worms/io/model.scala @@ -62,17 +62,19 @@ object VernacularName: def read(file: String): List[VernacularName] = readFile(file, VernacularName.from) final case class SpeciesProfile(taxonID: String, - isMarine: Boolean, - isFreshwater: Boolean, - isTerrestrial: Boolean, - isExtinct: Boolean, - isBrackish: Boolean): + isMarine: Option[Boolean], + isFreshwater: Option[Boolean], + isTerrestrial: Option[Boolean], + isExtinct: Option[Boolean], + isBrackish: Option[Boolean]): val id = taxonIDToKey(taxonID) object SpeciesProfile: - private def toBool(value: String): Boolean = - value == "1" + private def toBool(value: String): Option[Boolean] = + if value.isBlank then None + else Some(value == "1") + def from(row: String): Option[SpeciesProfile] = Try {