-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_dict.py
57 lines (47 loc) · 1.36 KB
/
create_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
49
50
51
52
53
54
55
56
import database
import nltk.data
import questionnode
nodes = {i: database.__dict__[i] for i in database.__dict__ if
isinstance(database.__dict__[i], questionnode.GameNode)}
everyword_list = []
for node in nodes:
try:
for i in nodes[node].query:
try:
corpus = nltk.word_tokenize(i)
tagged = nltk.pos_tag(corpus)
everyword_list.append(tagged)
except UnicodeDecodeError:
pass
except AttributeError:
pass
try:
for i in nodes[node].options:
try:
corpus = nltk.word_tokenize(i)
tagged = nltk.pos_tag(corpus)
everyword_list.append(tagged)
except UnicodeDecodeError:
pass
except AttributeError:
pass
# try:
# for i in nodes[node].options:
# try:
# corpus = nltk.word_tokenize(i)
# tagged = nltk.pos_tag(corpus)
# everyword_list.append(tagged)
# except UnicodeDecodeError:
# pass
# except AttributeError:
# pass
# print everyword_list
f = open("parts.txt", "r+")
everyword_dict = {}
for sentence in everyword_list:
for i in sentence:
everyword_dict[i[0]] = i[1]
# f.write()
print everyword_dict
f.write(str(everyword_dict))
f.close()