Get a noun from the Wordnet verb

I am trying to get a noun from a verb with Wordnet in python. I want to receive:
from the verb "created" noun "creator",

'funded' => 'funder' Verb X => Noun Y 

Y refers to a person

I could do it the other way: Noun Y => Verb X

 import nltk as nltk from nltk.corpus import wordnet as wn lem = wn.lemmas('creation') print lem related_forms = lem[0].derivationally_related_forms() print related_forms 

Here is the result indicated

 [Lemma('creation.n.01.creation'), Lemma('creation.n.02.creation'), Lemma('creation.n.03.creation'), Lemma('initiation.n.02.creation'), Lemma('creation.n.05.Creation'), Lemma('universe.n.01.creation')] [Lemma('create.v.02.create'), Lemma('produce.v.02.create'), Lemma('create.v.03.create')] 

But I'm trying to do the opposite. Here is a link that looks the way I want, but the code does not work and does not respond to my request:
Convert words between a verb / noun / adjective form

+6
source share
1 answer

You can try something like this:

 def nounify(verb_word): set_of_related_nouns = set() for lemma in wn.lemmas(wn.morphy(verb_word, wn.VERB), pos="v"): for related_form in lemma.derivationally_related_forms(): for synset in wn.synsets(related_form.name(), pos=wn.NOUN): if wn.synset('person.n.01') in synset.closure(lambda s:s.hypernyms()): set_of_related_nouns.add(synset) return set_of_related_nouns 

This method searches for all derivatives related nouns in the verb and checks to see if they have a “person” as a hypernim.

This input

 print nounify("created") print nounify("teach") print nounify("spoke") 

will return this conclusion

 set([Synset('creator.n.02'), Synset('creature.n.02'), Synset('creature.n.03')]) set([Synset('teacher.n.01')]) set([Synset('speaker.n.03'), Synset('speaker.n.01')]) 

Unfortunately, your example of a "fund" is not considered, since "funder" is not listed as a derivationally related form for a "fund" in WordNet.

+3
source

Source: https://habr.com/ru/post/986681/


All Articles