Skip to content

Instantly share code, notes, and snippets.

@adsieg
Created May 7, 2019 13:06
Show Gist options
  • Save adsieg/d3e04773bf2092fe28c831a892402dc1 to your computer and use it in GitHub Desktop.
Save adsieg/d3e04773bf2092fe28c831a892402dc1 to your computer and use it in GitHub Desktop.
knowledge_based_measure
from nltk.corpus import wordnet as wn
from nltk.corpus import wordnet_ic
dog=wn.synsets('dog', pos=wn.NOUN)[0] #get the first noun synonym of the word "dog"
cat=wn.synsets('cat', pos=wn.NOUN)[0]
rose=wn.synsets('rose', pos=wn.NOUN)[0]
flower=wn.synsets('flower', pos=wn.NOUN)[0]
brown_ic = wordnet_ic.ic('ic-brown.dat') #load the brown corpus to compute the IC
rose.res_similarity(flower, brown_ic)
rose.res_similarity(dog, brown_ic)
cat.res_similarity(dog, brown_ic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment