我有一个复数名词列表,例如苹果、橙子等。我想把它们全部转换为单数名词。是否有此目的的工具?最好使用Java或Python。
例如,有一个名为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')
Sources:
将会得到“Apple”。默认情况下,SimpleNLG会将其识别为名词短语并转换为单数形式。Lexicon lexicon = Lexicon.getDefaultLexicon();
NLGFactory nlgFactory = new NLGFactory(lexicon);
NPPhraseSpec subject = nlgFactory.createNounPhrase("apples"); subject.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);