Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get noun from verb Wordnet

I'm trying to get the noun from a verb with Wordnet in python. I want to be able to get :
from the verb 'created' the noun 'creator',

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

Y is referring to a person

I've been able to do it the other side : 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 output given

[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 like what I want to do, but the code is not working and doesn't answer my request:
Convert words between verb/noun/adjective forms

like image 622
dooms Avatar asked May 06 '15 16:05

dooms


1 Answers

You could 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 looks up all derivationally related nouns to a verb, and checks if they have "person" as a hypernym.

This input

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

will return this output

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, however, your "fund" example isn't covered, as "funder" isn't listed as a derivationally related form to "fund" in WordNet.

like image 52
yvespeirsman Avatar answered Oct 12 '22 11:10

yvespeirsman