-
Notifications
You must be signed in to change notification settings - Fork 0
/
vocab.py
112 lines (89 loc) · 2.36 KB
/
vocab.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from PyDictionary import PyDictionary
from vocabulary import Vocabulary as vb
import json
def translate(text):
try:
translation=''
result=json.loads(vb.translate(text, "en","hi"))
for res in result:
translation += res['text'] + ','
return translation[:-1] + '\n'
except:
return "N/A"
def synonyms(word):
try:
synonyms=''
result=json.loads(vb.synonym(word))
for res in result:
synonyms += res['text'] + ','
return synonyms[:-1] + '\n'
except:
return "N/A"
def antonyms(word):
try:
result=vb.antonym(word)
return ','.join(x for x in result['text']) + '\n'
except:
return "N/A"
def usage_example(word):
try:
examples=''
result=json.loads(vb.usage_example(word))
for res in result:
examples += res['text'] + '\n\n'
if(len<300):
return examples
else:
return examples[:300]
except:
return "N/A"
def meaning(word):
try:
parts=''
result=json.loads(vb.part_of_speech(word))
for res in result:
parts += res['text']+ ':' + res[u'example:'] + '\n\n'
return parts
except:
return "N/A"
def pronounce(word):
try:
result=vb.pronunciation(word)
return result[0]['raw'].encode('utf8') + '\n'
except:
return "N/A"
def create_result(word):
result={}
result['meaning'] = meaning(word)
result['pronunciation'] = pronounce(word)
result['usage'] = usage_example(word)
result['synonyms'] = synonyms(word)
result['antonyms'] = antonyms(word)
result['translation'] = translate(word)
return result
'''
def get_synonyms(word):
try:
dictionary=PyDictionary()
return ",".join(x for x in dictionary.synonym(word))
except:
return "No synonyms available"
def get_antonyms(word):
try:
dictionary=PyDictionary()
return ",".join(x for x in dictionary.antonym(word))
except:
return "No antonyms available"
def get_meaning(word):
try:
meaning=''
dictionary=PyDictionary()
result=dictionary.meaning(word)
forms=result.keys()
for form in forms:
meaning += 'As a ' +
form + ': ' + result[form][0] + '\n'
return meaning
except:
return "Word not found in dictionary."
'''