1

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.

Chris Beach
  • 4,302
  • 2
  • 31
  • 50
  • If you can't find a library, check out this link and the table that shows general rules for pluralization of things that don't follow the "Just add an 's'" approach: http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html – cmbaxter Jun 06 '13 at 12:47

1 Answers1

2

There's already a very nice discussion on stack-overflow: Pluralizer

Main take-away:
Evo Inflector can be used to generate plural forms of words. It uses algorithm from Damian Conway's paper An Algorithmic Approach to English Pluralization. Success rate is about 70% for words from wiki dictionary and 100% for 1000 most common English words.

Community
  • 1
  • 1
vitalii
  • 3,335
  • 14
  • 18
  • Thank you and apologies - the problem was another error on my part. I have updated the question. – Chris Beach Jun 06 '13 at 12:43
  • I'm not sure stemming is the solution. Can you demonstrate how to use snowball to tell me that the plural form of alga is algae? Remember, the problem is that he's trying to pluralize a singular form, not match two possible words based on their stems. – cmbaxter Jun 06 '13 at 12:46