# Crosscompute
word = 'shy'
target_folder = '.'
from os.path import join
try:
import nltk
except ImportError:
import sys
!{sys.executable} -m pip install nltk
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet
synsets = wordnet.synsets(word)
synsets
from itertools import chain
lemmas = list(chain(*[s.lemmas() for s in synsets]))
lemmas
set([l.name() for l in lemmas])
[l.name() for lemma in lemmas for l in lemma.antonyms()]
syns = set([lemma.name() for lemma in lemmas])
syns = list(syns - set([word]))
syns
ants = [l.name() for lemma in lemmas for l in lemma.antonyms()]
ants
syns_path = join(target_folder, 'synonyms.txt')
ants_path = join(target_folder, 'antonyms.txt')
with open(syns_path, 'w') as f:
f.writelines([x + '\n' for x in syns])
print('synonyms_text_path = %s' % syns_path)
if ants:
with open(ants_path, 'w') as f:
f.writelines([x + '\n' for x in ants])
print('antonyms_text_path = %s' % ants_path)