我有一个复数名词列表。例如,苹果,橘子等。我想将它们全部转换为单数名词。有没有用于此目的的工具?喜欢它是Java或Python。
答案 0 :(得分:4)
例如https://pypi.python.org/pypi/inflect库。
示例:
import inflect
p = inflect.engine()
words = ["apples", "sheep", "oranges", "cats", "people", "dice", "pence"]
for word in words:
print("The singular of ", word, " is ", p.singular_noun(word))
输出:
('The singular of ', 'apples', ' is ', 'apple')
('The singular of ', 'sheep', ' is ', 'sheep')
('The singular of ', 'oranges', ' is ', 'orange')
('The singular of ', 'cats', ' is ', 'cat')
('The singular of ', 'people', ' is ', 'person')
('The singular of ', 'dice', ' is ', 'die')
('The singular of ', 'pence', ' is ', 'pence')
来源:
答案 1 :(得分:2)
您可以使用Java库,SimpleNLG(https://github.com/simplenlg/simplenlg) 或者使用它的Python Wrapper,PyNLG(https://github.com/mapado/pynlg)(pip install pynlg)。
它拥有广泛的词典集合,可以识别许多对象的数字形式。您可以设置其功能并打印出其单数形式。它对于简单的任务非常有用。
Lexicon lexicon = Lexicon.getDefaultLexicon();
NLGFactory nlgFactory = new NLGFactory(lexicon);
NPPhraseSpec subject = nlgFactory.createNounPhrase(" apples"); subject.setFeature(Feature.NUMBER,NumberAgreement.SINGULAR);
将给予" Apple"。默认情况下,simpleNLG会将所有可识别的名词短语转换为单数。