org.globalnames.parser.Util.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gnparser_2.11 Show documentation
Show all versions of gnparser_2.11 Show documentation
Fast and elegant parser for taxonomic scientific names
package org.globalnames.parser
import collection.mutable.{Buffer}
object Util {
def normAuthWord(input: String): String = {
if (input.matches("""[\p{Lu}]{3,}[\p{Lu}-]*"""))
input.split("-").map(_.toLowerCase.capitalize).mkString("-")
else input
}
def norm(input: String): String = {
var output: Buffer[Char] = Buffer()
val charFrom = "ÀÂÅÃÄÁÇČËÉÈÍÌÏŇÑÑÓÒÔØÕÖÚÙÜŔŘŖŠŠŞŽ" +
"àâåãäáçčëéèíìïňññóòôøõöúùüŕřŗſššşž"
val charTo = "AAAAAACCEEEIIINNNOOOOOOUUURRRSSSZ" +
"aaaaaacceeeiiinnnoooooouuurrrssssz"
for (chr <- input) {
val index = charFrom.indexOf(chr)
chr match {
case 'Æ' => "Ae".foreach(output += _)
case 'Œ' => "Oe".foreach(output += _)
case 'æ' => "ae".foreach(output += _)
case 'œ' => "oe".foreach(output += _)
case '\'' =>
case _ => output += (if (index > -1) charTo(index) else chr)
}
}
val res = output.mkString
res.replaceFirst("""\?$""", "") //remove question mark from the end
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy