java 英语单词复数形式的Java API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5907296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java API for plural forms of English words
提问by Joe
Are there any Java API(s) which will provide plural form of English words (e.g. cacti
for cactus
)?
是否有任何 Java API 可以提供英文单词的复数形式(例如cacti
for cactus
)?
采纳答案by Meng Lu
Wolfram|Alpha return a list of inflection forms for a given word.
Wolfram|Alpha 返回给定单词的屈折形式列表。
See this as an example:
以这个为例:
http://www.wolframalpha.com/input/?i=word+cactus+inflected+forms
http://www.wolframalpha.com/input/?i=word+cactus+inflected+forms
And here is their API:
这是他们的 API:
回答by S?awek
Check Evo Inflectorwhich implements English pluralization algorithm based on Damian Conway paper "An Algorithmic Approach to English Pluralization". The library is tested against data from Wiktionary and reports 100% success rate for 1000 most used English words and 70% success rate for all the words listed in Wiktionary.
检查Evo Inflector,它基于 Damian Conway 论文“英语多元化的算法方法”实现了英语复数算法。该库针对来自维基词典的数据进行了测试,报告 1000 个最常用的英语单词的成功率为 100%,维基词典中列出的所有单词的成功率为 70%。
If you want even more accuracy you can take Wiktionary dump and parse it to create the database of singular to plural mappings. Take into account that due to the open nature of Wiktionary some data there might by incorrect.
如果您想要更高的准确性,您可以使用维基词典转储并解析它以创建单数到复数映射的数据库。考虑到由于维基词典的开放性,某些数据可能不正确。
Example Usage:
示例用法:
English.plural("Facility", 1)); // == "Facility"
English.plural("Facility", 2)); // == "Facilities"
回答by jkschneider
jibx-toolsprovides a convenient pluralizer/depluralizer.
jibx-tools提供了一个方便的复数/去复数。
Groovy test:
常规测试:
NameConverter nameTools = new DefaultNameConverter();
assert nameTools.depluralize("apples") == "apple"
nameTools.pluralize("apple") == "apples"
回答by Gabriel ??erbák
I know there is simple pluralize() function in Ruby on Rails, maybe you could get that through JRuby. The problem really isn't easy, I saw pages of rules on how to pluralize and it wasn't even complete. Some rules are not algorithmic - they depend on stem origin etc. which isn't easily obtained. So you have to decide how perfect you want to be.
我知道 Ruby on Rails 中有一个简单的 Multipleize() 函数,也许您可以通过 JRuby 获得它。这个问题真的不容易,我看到了关于如何复数的几页规则,它甚至不完整。有些规则不是算法——它们取决于词干起源等,这不容易获得。所以你必须决定你想成为多么完美。
回答by Sebastian Schmitt
considering java, have a look at modeshapesInflector-Class as member of the package org.modeshape.common.text. Or google for "inflector" and "randall hauch".
考虑到 java,看看作为包org.modeshape.common.text 的成员的modeshapesInflector-Class 。或者谷歌搜索“inflector”和“randall hauch”。
回答by Nirmit Shah
Its hard to find this kind of API. rather you need to find out some websservice which can serve your purpose. Check this. I am not sure if this can help you.. (I tried to put word cacti and got cactus somewhere in the response).
很难找到这种API。相反,您需要找出一些可以满足您目的的网络服务。检查这个。我不确定这是否可以帮助您..(我尝试在回复中输入仙人掌一词并在某处找到仙人掌)。
回答by Ronnie Royston
If you can harness javascript, I created a lightweight (7.19 KB) javascript for this. Or you could port my script over to Java. Very easy to use:
如果您可以利用 javascript,我为此创建了一个轻量级 (7.19 KB) javascript。或者您可以将我的脚本移植到 Java。非常容易使用:
pluralizer.run('goose') --> 'geese'
pluralizer.run('deer') --> 'deer'
pluralizer.run('can') --> 'cans'
https://github.com/rhroyston/pluralizer-js
https://github.com/rhroyston/pluralizer-js
BTW: It looks like cacti to cactus is a super special conversion (most ppl are going to say '1 cactus' anyway). Easy to add that if you want to. The source code is easy to read / update.
顺便说一句:看起来仙人掌到仙人掌是一种超级特殊的转换(无论如何,大多数人都会说“1 个仙人掌”)。如果您愿意,可以轻松添加。源代码易于阅读/更新。