Search code examples
gopluralize

Find if a word is plural of another


I am writing a program in Go to generate a report of crimes in my University. I have run into a roadblock where I need to find if one word is a plural of another. I am making a map of crimes first

crimes := make(map[string]int)

then, adding crimes to the map with the number of occurrences as int

for i := 0; i < len(feed.Items); i++ {
  crimes[feed.Items[i].Title[11:]]++
}

Now, the problem arises when there are entries like, "Armed Robberies (with a count of 1)" and "Armed Robbery (with a count of 2)". I want to check if a word is a plural of another. In this case, I want to make a single entry for "Armed Robbery (with a count of 3)". I could not find a package for doing this. Is there a way to do this?


Solution

  • What you are looking for is called inflections. Basically, it is the black art of determining the various forms of a word, in particular singular from plural, or the opposite.

    There are libraries for this, mostly inspired from the Ruby On Rails ActiveSupport::Inflector system, see for example https://github.com/jinzhu/inflection.

    Also see http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html for a very interesting read about algorithms for english pluralization.