Created
June 19, 2018 18:27
-
-
Save sente/29ca8adcbc4706f66c38a22d43d0b511 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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