Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将复数名词转换为单数NLP_Java_Python_Nlp - Fatal编程技术网

Java 将复数名词转换为单数NLP

Java 将复数名词转换为单数NLP,java,python,nlp,Java,Python,Nlp,我有一个复数名词的列表。例如,苹果、桔子等。我想把它们全部转换成单数名词。是否有用于此目的的工具?首选Java或Python。有示例库 例如: import inflect p = inflect.engine() words = ["apples", "sheep", "oranges", "cats", "people", "dice", "pence"] for word in words: print("The singular of ", word, " is ", p.s

我有一个复数名词的列表。例如,苹果、桔子等。我想把它们全部转换成单数名词。是否有用于此目的的工具?首选Java或Python。

有示例库

例如:

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')
资料来源:


您可以使用Java库SimpleLG() 或者使用其Python包装器PyNLG()(pip安装PyNLG)

它有一个广泛的词汇集合,可以识别许多对象的数字形式。您可以设置其功能并打印出其单数形式。它对于简单的任务非常有效

Lexicon Lexicon=Lexicon.getDefaultLexicon()

NLGFactory NLGFactory=新NLGFactory(词典)

NPPhraseSpec subject=nlgFactory.createNounPhrase(“苹果”); subject.setFeature(Feature.NUMBER,NumberAgreement.SINGULAR)


将给“苹果”。默认情况下,SimpleLg会将它可以识别的所有名词短语转换为单数。

我已经尝试过这个模块,它一般都可以工作,但并不完美。例如,如果您传递'as'或'does','means',它将输出'a'和'doe','means',这可能不是我们想要的。