Skip to content

Instantly share code, notes, and snippets.

@erev0s
Created November 2, 2018 15:16
Show Gist options
  • Save erev0s/47ac855b2fea6cab4c246c6560ec632c to your computer and use it in GitHub Desktop.
Save erev0s/47ac855b2fea6cab4c246c6560ec632c to your computer and use it in GitHub Desktop.
small thing to change into synonyms the words of a text
import thesaurus as th
wordlist = []
with open('test.txt') as f:
wordlist = ([word for line in f for word in line.split()])
changedw = []
for word in wordlist:
tmpword = th.Word(word).synonyms(relevance=3)
if not tmpword:
changedw.append(word)
else:
changedw.append(tmpword[0])
print(' '.join(changedw))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment