-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdicts.py
86 lines (76 loc) · 2.06 KB
/
dicts.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from PyDictionary import PyDictionary
from googletrans import Translator
def translate_to_tamil(text):
try:
translator = Translator()
result = translator.translate(text, dest="ta")
return result.text
except:
return "Word Not Available"
def meaning_list(texts):
text = texts.lower()
try:
dicts = PyDictionary()
mean = dicts.meaning(text)
try:
mean_noun = mean["Noun"]
except:
mean_noun = ["It may be a name or not a noun"]
try:
mean_verb = mean["Verb"]
except:
mean_verb = ["It is not Verb"]
try:
mean_adj = mean["Adjective"]
except:
mean_adj = ["It is not Adjective"]
try:
mean_adv = mean["Adverb"]
except:
mean_adv = ["It is not Adverb"]
except:
mean_noun = ["Not Available"]
mean_verb = ["Not Available"]
mean_adj = ["Not Available"]
mean_adv = ["Not Available"]
return mean_noun, mean_verb, mean_adj, mean_adv
def meaning(text):
tup = meaning_list(text)
string_of_mean_noun = ""
string_of_mean_verb = ""
string_of_mean_adj = ""
string_of_mean_adv = ""
for word in tup[0]:
string_of_mean_noun = string_of_mean_noun + word + "\n"
for word in tup[1]:
string_of_mean_verb = string_of_mean_verb + word + "\n"
for word in tup[2]:
string_of_mean_adj = string_of_mean_adj + word + "\n"
for word in tup[3]:
string_of_mean_adv = string_of_mean_adv + word + "\n"
final = """
{}
Meaning as Noun:
---------------
{}
Meaning as Verb:
---------------
{}
Meaning as Adjective:
--------------------
{}
Meaning as Adverb:
--------------------
{}
Tamil Meaning:
-------------
{}
""".format(
text.title(),
string_of_mean_noun,
string_of_mean_verb,
string_of_mean_adj,
string_of_mean_adv,
translate_to_tamil(text),
)
return final