I'm writing a Scala method to pluralise Strings:
def plural(value: String) = {
value match {
case "fish" | "dice" | "sheep" => value
case "foot" => value.dropRight(3) + "eet"
case "woman" | "man" => value.dropRight(2) + "en"
case "tooth" => value.dropRight(4) + "eeth"
case _ => value.takeRight(2).toLowerCase() match {
case "sh" | "ch" => value + "es"
case "ay" => value + "s"
case _ => value.takeRight(1).toLowerCase() match {
case "s" => value + "es"
case "y" => value.dropRight(1) + "ies"
case _ => value + "s"
}
}
}
}
This clearly doesn't cover all the special cases in the English language. I'd like to know if there exists a library method for this? (and for finding the set of possible singulars of a plural String).
Thanks in advance for your help.