How to get the wordnet sense frequency of a synset in NLTK?

不问归期 提交于 2019-11-30 10:02:04

I managed to do it this way.

from nltk.corpus import wordnet as wn

word = "dog"
synsets = wn.synsets(word)

sense2freq = {}
for s in synsets:
  freq = 0  
  for lemma in s.lemmas:
    freq+=lemma.count()
  sense2freq[s.offset+"-"+s.pos] = freq

for s in sense2freq:
  print s, sense2freq[s]

If you only need to know what the most frequent word is, you can do wn.synsets(word)[0] since WordNet generally ranks them from most frequent to least frequent.

(source: Daniel Jurafsky's Speech and Language Processing 2nd edition)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!