JavaCup
JavaCup

Reputation: 15

Searching through an entire series of synsets (from NLTK) in Python NLP

Original question:

The polysemy of a word is the number of senses it has. Using WordNet, we can determine that the noun dog has seven senses with len(wn.synsets('dog', 'n')). Compute the average polysemy of nouns, verbs, adjectives, and adverbs according to WordNet.

From what I gathered from the question, I was to use a built in polysemy method in NLTK with WordNet to find out the number of senses something has.

More importantly, I am trying to use all of the available synsets available and loop them through, and placing all of the values returned into a set. After this, I would have intended to add the total number of all the synsets in the set(filled with integers) that was newly created to receive a sum. After I obtain this sum, I would have divided the total number of entries to receive the average.

My biggest question is... how would I go about looping through all of the synsets available as well as the nouns, verbs, adjectives, and adverbs?

However the type it returns is a "generator", how would I go about using loops to iterate through a "generator" type?

.>>>allsynsets = wn.all_synsets('n')

.>>> allsynsets

<.generator object all_synsets at 0x04359F30>

.>>> type(allsynsets)

<.type 'generator'>

I hope I've provided enough information to allow anyone to find an answer to this problem. I do not have source code, aside from imports and tests to understand the generator type for this problem.

Thank you for your time.

Upvotes: 0

Views: 1618

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113988

either of these methods should work

list = [x for x in wx.all_synsets('n')]

or

for x in wx.all_synsets('n'):
    print x

[edit] this talks more about generators (among many other sources on the web) http://www.dalkescientific.com/writings/NBN/generators.html

Upvotes: 2

Related Questions