-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict.py
54 lines (35 loc) · 976 Bytes
/
dict.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
try:
import dic_tree
except Exception as e:
print('You should compile the module first')
exit()
import json
def intitfromfile(filename):
words = []
with open(filename, 'r') as f:
words = json.load(f)
for word in words:
dic_tree.insert_word(word['word'],json.dumps(word))
def searchWord(word_en):
item = dic_tree.search_word(word_en)
result = {}
if(len(item)):
result = json.loads(item[1])
print(result)
return result
def modifyWord(item):
s = json.dumps(item)
word_en = item['word']
return dic_tree.modify_word(word_en, s)
def insertWord(item):
dic_tree.insert_word(item['word'], json.dumps(item))
return
def suggestWord(word_en):
item = dic_tree.suggest_word(word_en)
result = []
for i in item:
if(i):
result.append(i[0])
j = {'result': result}
return json.dumps(result)
intitfromfile("./static/items_comp.json")