Python 使用 NLTK 和 WordNet;如何将简单时态动词转换为其现在、过去或过去分词形式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3753021/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:34:02  来源:igfitidea点击:

Using NLTK and WordNet; how do I convert simple tense verb into its present, past or past participle form?

pythonnlpnltkwordnet

提问by Software Enthusiastic

Using NLTK and WordNet, how do I convert simple tense verb into its present, past or past participle form?

使用 NLTK 和WordNet,如何将简单时态动词转换为其现在、过去或过去分词形式?

For example:

例如:

I want to write a function which would give me verb in expected form as follows.

我想写一个函数,它会以预期的形式给我动词,如下所示。

v = 'go'
present = present_tense(v)
print present # prints "going"

past = past_tense(v)
print past # prints "went"

采纳答案by msbmsb

I think what you're looking for is the NodeBox::Linguisticslibrary. It does exactly that:

我认为您正在寻找的是NodeBox::Linguistics库。它正是这样做的:

print en.verb.present("gave")
>>> give

回答by Hoda

JWI (the WordNet library by MIT) also has a stemmer (WordNetStemmer) which converts different morphological forms of a word like ("written", "writes", "wrote") to their base form. It seems it works only for nouns (like plurals) and verbs though.

JWI(麻省理工学院的 WordNet 库)还有一个词干分析器 (WordNetStemmer),它可以将单词的不同形态形式(如“written”、“writes”、“wrote”)转换为它们的基本形式。不过,它似乎只适用于名词(如复数)和动词。

Word Stemming in Java with WordNet and JWNLalso shows how to do this kind of stemming using JWNL, another Java-based Wordnet library:

使用 WordNet 和 JWNL 在 Java 中进行词干提取还展示了如何使用 JWNL(另一个基于 Java 的 Wordnet 库)进行这种词干提取:

回答by Gunjan

With the help of NLTK this can also be done. It can give the base form of the verb. But not the exact tense, but it still can be useful. Try the following code.

在 NLTK 的帮助下,这也可以完成。它可以给出动词的基本形式。但不是确切的时态,但它仍然有用。试试下面的代码。

from nltk.stem.wordnet import WordNetLemmatizer
words = ['gave','went','going','dating']
for word in words:
    print word+"-->"+WordNetLemmatizer().lemmatize(word,'v')

The output is:

输出是:

gave-->give
went-->go
going-->go
dating-->date

Have a look at Stack Overflow question NLTK WordNet Lemmatizer: Shouldn't it lemmatize all inflections of a word?.

看看堆栈溢出问题NLTK WordNet Lemmatizer:它不应该对一个词的所有变化进行词形还原吗?.

回答by Anatoly Alekseev

For Python3:

对于 Python3:

git clone https://github.com/clips/pattern
cd pattern
git fetch
git checkout development
pip install mysqlclient
python setup.py install

then

然后

from pattern.en import conjugate, lemma, lexeme,PRESENT,SG
print (lemma('gave'))
print (lexeme('gave'))
print (conjugate(verb='give',tense=PRESENT,number=SG)) # he / she / it

yields

产量

give ['give', 'gives', 'giving', 'gave', 'given'] gives

give ['give', 'gives', 'giving', 'gave', 'given'] gives

thnks to @Agargara for pointing & authors of Pattern for their beautiful work, go support them ;-)

感谢@Agargara 指出和 Pattern 的作者,感谢他们的美丽作品,去支持他们吧 ;-)