Skip to content

Instantly share code, notes, and snippets.

@sente
Created June 19, 2018 18:27
Show Gist options
  • Save sente/29ca8adcbc4706f66c38a22d43d0b511 to your computer and use it in GitHub Desktop.
Save sente/29ca8adcbc4706f66c38a22d43d0b511 to your computer and use it in GitHub Desktop.
import sys
import pprint
import json
from nltk.corpus import wordnet as wn
def get_synsets(words):
return dict([[w,wn.synsets(w.split()[0])] for w in words])
def showit(word):
res = get_synsets([word])
dd = {}
for k,v in res.items():
dd[k] = {}
for thing in v:
dd[k][str(thing.name())] = map(str,thing.lemma_names())
return dd
if __name__ == '__main__':
res = []
for word in sys.argv[1:]:
res.append(showit(word))
print json.dumps(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment