Skip to content

Commit bbec6ad

Browse files
committed
1.1.4
Improve handling of cases where multiple related clades redirect to the same Wikipedia article. Also hard-code "Badger" to refer to subfamily "Melinae".
1 parent 8b5b6c9 commit bbec6ad

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "wikiClade"
22

3-
version := "1.1.3"
3+
version := "1.1.4"
44

55
scalaVersion := "2.12.8"
66

src/main/scala/cladograms/WikiClade.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ object WikiClade {
5353
val path = "/wiki/" + name.replaceAll(" ", "_")
5454
val url = baseUrl + path
5555
val docOpt = WikiProxy.fetchPage(url)
56-
//TODO Check for paraphyly
57-
//TODO Check for polyphyly
58-
val taxPathOpt = getTaxoboxLink(docOpt)
59-
val taxDocOpt = getDoc(taxPathOpt)
6056
val title = getTitle(Some(path))
57+
val isBadger = title.contains("Badger - Wikipedia") // yes, I'm hard-coding badgers. I blame Wikipedia.
58+
val taxPathOpt = getTaxoboxLink(if (isBadger) "Melinae" else name, docOpt)
59+
val taxDocOpt = getDoc(taxPathOpt)
6160
val ttitle = getTitle(taxoboxGetPageLink(taxDocOpt))
6261
title match {
6362
case None => new WikiPageClade(name, taxPathOpt, 0)
6463
case Some(_) =>
65-
if (title == ttitle) new WikiTaxoboxClade(name, taxPathOpt, priorityOverride = 0)
64+
if (title == ttitle || isBadger) new WikiTaxoboxClade(name, taxPathOpt, priorityOverride = 0)
6665
else new WikiPageClade(name, Some(path), 0)
6766
}
6867
}
@@ -96,7 +95,15 @@ object WikiClade {
9695
case None => new Elements()
9796
}
9897

99-
private def getTaxoboxLink(docOpt: Option[Document]): Option[String] = {
98+
private def getTaxoboxLink(name: String, docOpt: Option[Document]): Option[String] = {
99+
val possibleTaxPath = "/wiki/Template:Taxonomy/" + name.replaceAll(" ", "_")
100+
getTitle(Some(possibleTaxPath)) match {
101+
case Some(_) => Some(possibleTaxPath)
102+
case None => getTaxoboxLinkFromEditButton(docOpt)
103+
}
104+
}
105+
106+
private def getTaxoboxLinkFromEditButton(docOpt: Option[Document]): Option[String] = {
100107
val elements = getInfoTable(docOpt)
101108
def iter(i: Int): Option[String] = {
102109
def iter2(as: Elements, j: Int): Option[String] = {

0 commit comments

Comments
 (0)