Skip to content

Instantly share code, notes, and snippets.

@XericZephyr
Created October 8, 2015 19:20
Show Gist options
  • Save XericZephyr/462043957ee2a23ace73 to your computer and use it in GitHub Desktop.
Save XericZephyr/462043957ee2a23ace73 to your computer and use it in GitHub Desktop.
WordNet Python
from nltk.corpus import wordnet as wn
# get synset from offset string, e.g. 'n09208496' for asterism
a = wn._synset_from_pos_and_offset('n', 9208496) # got Synset('asterism.n.02')
# then got hypernym_paths
print a.hypernym_paths()
# got
"""
[[Synset('entity.n.01'),
Synset('physical_entity.n.01'),
Synset('object.n.01'),
Synset('whole.n.02'),
Synset('natural_object.n.01'),
Synset('asterism.n.02')]]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment