我正试图从python中使用Wordnet的名词中获取动词。 这是代码:
nouns = ["slip", "frustration"]
def nominalization(noun_word):
set_of_related_verbs = set()
for lemma in wn.lemmas(wn.morphy(noun_word, wn.NOUN), pos="n"):
for related_form in lemma.derivationally_related_forms():
set_of_related_verbs.add(related_form)
return set_of_related_verbs
for word in nouns:
set_of_words = nominalization(word)
if len(set_of_words) >= 1:
print word + "+++"
print set_of_words
我只需要动词,但我也得到了其他动词,例如: 滑+++ set([Lemma('slip。 a .01.slippy'),Lemma('err.v.01.slip')])
我该如何更改?
如果我使用该行:
for synset in wn.synsets(related_form.name(), pos=wn.VERB):
我只得到动词,但有些动词可能与我的名词无关,例如: 收购+++ set([Synset(' get .v.01'),Synset('假设 .v.03'),Synset('成长 .v.08'),Synset('acquire.v.04'),Synset('acquire.v.05'),Synset(' develop .v.03'),Synset('的学 .v.01' )])
答案 0 :(得分:1)
您可以导出可以从中提取动词的词条和相关单词形式:
import nltk as nltk
from nltk.corpus import wordnet as wn
lem = wn.lemmas('frustration')
print lem
结果:
[Lemma('frustration.n.01.frustration'), Lemma('frustration.n.02.frustration'), Lemma('frustration.n.03.frustration')]
你可以从中获得这样的动词:
related_forms = [lem[i].derivationally_related_forms() for i in range(len(lem))]
print related_forms
结果:
[[Lemma('thwart.v.01.frustrate')], [Lemma('thwart.v.01.frustrate')], [Lemma('thwart.v.01.frustrate'), Lemma('torment.v.02.frustrate')]]