From 710a31531c9e4614ede203542c2146086d55a9ff Mon Sep 17 00:00:00 2001 From: Daniel Shapiro Date: Fri, 21 Jun 2019 17:09:37 -0700 Subject: [PATCH] 1.1.2 handle paraphyly more gracefully --- build.sbt | 2 +- src/main/scala/cladograms/WikiClade.scala | 14 ++++++++++++-- src/main/scala/cladograms/WikiPageClade.scala | 11 ++--------- src/main/scala/cladograms/WikiTaxoboxClade.scala | 8 -------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/build.sbt b/build.sbt index 2ca76f1..a99dcc0 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ name := "wikiClade" -version := "1.1.1" +version := "1.1.2" scalaVersion := "2.12.8" diff --git a/src/main/scala/cladograms/WikiClade.scala b/src/main/scala/cladograms/WikiClade.scala index 87e97bc..a00acf1 100644 --- a/src/main/scala/cladograms/WikiClade.scala +++ b/src/main/scala/cladograms/WikiClade.scala @@ -15,7 +15,8 @@ abstract class WikiClade extends Clade { def priorityOverride: Double - case class WikiCladeMetadata(trueName: String, ancestors: List[Clade], path: Option[String], cladeType: String, docPriority: Double) + case class WikiCladeMetadata(trueName: String, ancestors: List[Clade], path: Option[String], cladeType: String, + docPriority: Double, paraphyletic: Boolean = false) override def DOTDefinition: Option[String] = { val cladeTypeStr = if (meta.cladeType.isEmpty) "" else s"""${meta.cladeType}
""" @@ -23,15 +24,24 @@ abstract class WikiClade extends Clade { case None => "" case Some(p) => s"""href="${WikiClade.baseUrl}${p.replaceAll("&", "&")}",""" } + val asterisk = if (meta.paraphyletic) "*" else "" val dispname = if (meta.trueName == name) name - else s"${meta.trueName}
($name)" + else s"${meta.trueName}
($name)$asterisk" Some(s""""$name" [$hrefStr label=<$cladeTypeStr$dispname>]""") } def priority: Double = Math.min( Math.min(priorityOverride, meta.docPriority), if (WikiClade.importantCladeTypes contains meta.cladeType) 20 else 100) + + def canEqual(obj: Any): Boolean = obj.isInstanceOf[WikiClade] + override def equals(obj: Any): Boolean = obj match { + case obj: WikiClade => obj.canEqual(this) && this.meta.trueName == obj.meta.trueName + case _ => false + } + + override def hashCode(): Int = meta.trueName.hashCode } object WikiClade { diff --git a/src/main/scala/cladograms/WikiPageClade.scala b/src/main/scala/cladograms/WikiPageClade.scala index 3f25ddd..5afaf07 100644 --- a/src/main/scala/cladograms/WikiPageClade.scala +++ b/src/main/scala/cladograms/WikiPageClade.scala @@ -26,7 +26,8 @@ class WikiPageClade(val name: String, path: Option[String], val priorityOverride else WikiClade.newClade(details.name, Some(details.path)) } val docPriority = priorityBasedOnDoc(docOpt) - WikiCladeMetadata(mydetails.name ,ancestors, path, WikiClade.sanitizeCladeType(mydetails.cladeType), docPriority) + WikiCladeMetadata(mydetails.name ,ancestors, path, WikiClade.sanitizeCladeType(mydetails.cladeType), docPriority, + mydetails.path.nonEmpty && !mydetails.cladeType.contains("pecies")) } private def extractTaxonomy(elems: Elements): List[TaxonDetails] = { @@ -95,14 +96,6 @@ class WikiPageClade(val name: String, path: Option[String], val priorityOverride case None => 99 } - def canEqual(obj: Any): Boolean = obj.isInstanceOf[WikiPageClade] - override def equals(obj: Any): Boolean = obj match { - case obj: WikiPageClade => obj.canEqual(this) && this.meta.trueName == obj.meta.trueName - case _ => false - } - - override def hashCode(): Int = meta.trueName.hashCode - private def taxonDetails(name: String, cladeType: String, path: String): TaxonDetails = { TaxonDetails(name, cladeType, false, path, "") } diff --git a/src/main/scala/cladograms/WikiTaxoboxClade.scala b/src/main/scala/cladograms/WikiTaxoboxClade.scala index 0e7495f..fb841a2 100644 --- a/src/main/scala/cladograms/WikiTaxoboxClade.scala +++ b/src/main/scala/cladograms/WikiTaxoboxClade.scala @@ -69,12 +69,4 @@ class WikiTaxoboxClade(val name: String, taxonomyPath: Option[String], details: } iter(elems.size() - 1, List()) } - - def canEqual(obj: Any): Boolean = obj.isInstanceOf[WikiTaxoboxClade] - override def equals(obj: Any): Boolean = obj match { - case obj: WikiTaxoboxClade => obj.canEqual(this) && this.meta.trueName == obj.meta.trueName - case _ => false - } - - override def hashCode(): Int = meta.trueName.hashCode }