-
Notifications
You must be signed in to change notification settings - Fork 0
/
thesaurus.py
61 lines (50 loc) · 1.72 KB
/
thesaurus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
from difflib import SequenceMatcher, get_close_matches
data = json.load(open("data.json"))
data_synonyms = json.load(open("eng_synonyms.json"))
def translate_synonyms(word):
word = word.lower()
if word in data_synonyms:
return data_synonyms[word]
else:
return "Word doesn't exist. Reconsider spell check."
def translate(word):
global right_word
word = word.lower()
if word in data:
return data[word]
elif len(get_close_matches(word, data.keys())) > 0:
close_match = input("Did you mean %s ? Enter (Y/yes) for affirmative. " % get_close_matches(word, data.keys()))
close_match = close_match.lower()
if close_match == "yes" or close_match == "y":
word = input("Okay! enter the correct word: ")
right_word = word
return data[word]
else:
return "Word doesn't exist. Reconsider spell check."
else:
return "Word doesn't exist. Reconsider spell check."
def output(out):
if type(out) == list:
for element in out:
print(element)
else:
print(out)
def input_u():
word_user = input("Enter word: ")
result = translate(word_user)
output(result)
synonyms = input("Satisfied? Or wanna go deeper?: (y/n): ")
if synonyms == "yes" or synonyms == "y":
result = translate_synonyms(right_word)
output(result)
elif synonyms == "no" or synonyms == "n":
loop = input("Wanna try again?(Y/n): ")
if loop == "yes" or loop == "y":
word_user = input("Enter word: ")
result = translate(word_user)
output(result)
else:
print("Thank you! try again sometime.")
return
input_u()