Created
November 2, 2018 15:16
-
-
Save erev0s/47ac855b2fea6cab4c246c6560ec632c to your computer and use it in GitHub Desktop.
small thing to change into synonyms the words of a text
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 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