Reputation: 303
Here is a function I'm writing to check for the existence of hyper and hyponyms from a list of nouns.
def check_hyper_hypo(wordlist):
returnlist=[]
for word in wordlist: #by definition a base word has a word above and below heirachy
x = wn.synsets(word)
for syn in x:
if not(((len(syn.hypernyms()))==0)or((len(syn.hyponyms()))==0)):
returnlist.append(word)
break
return returnlist
How do i check the length of hyper/hyponyms only for the synsets which are nouns? E.g.
for syn in x:
if ".n." in syn:
#rest of code
Upvotes: 1
Views: 2941
Reputation: 17
another approach using wordnet and list comprehension
print ([len(wn.morphy(tag,wn.NOUN)) for tag in tags])
Upvotes: -1
Reputation: 473
You could also try
wordnet.synsets(word, pos='n')
It will only return nouns, if you want verbs you should use pos='v'
Upvotes: 5