英文:
Find if a word is plural of another
问题
我正在使用Go编写一个程序,用于生成我大学的犯罪报告。我遇到了一个难题,需要判断一个单词是否是另一个单词的复数形式。首先,我创建了一个犯罪映射:
crimes := make(map[string]int)
然后,将犯罪添加到映射中,并记录其出现次数:
for i := 0; i < len(feed.Items); i++ {
crimes[feed.Items[i].Title[11:]]++
}
现在,问题出现在这样的条目上,比如"Armed Robberies(计数为1)"和"Armed Robbery(计数为2)"。我想检查一个词是否是另一个词的复数形式。在这种情况下,我希望将它们合并为一个条目"Armed Robbery(计数为3)"。我找不到一个可以做到这一点的包。有没有办法实现这个功能?
英文:
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?
答案1
得分: 4
你要找的是词形变化。基本上,它是确定一个词的各种形式的黑魔法,特别是单数和复数之间的转换。
有一些库可以实现这个功能,大多数是受到 Ruby On Rails 的 ActiveSupport::Inflector
系统的启发,例如可以参考 https://github.com/jinzhu/inflection。
此外,你还可以阅读 http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html,了解关于英语复数形式算法的非常有趣的内容。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论