Spaces:
Sleeping
Sleeping
Merge branch 'eason/main' of https://github.com/project-kxkg/project-t into eason/main
Browse files- dict_util.py +8 -10
dict_util.py
CHANGED
@@ -7,11 +7,12 @@ import pickle
|
|
7 |
# 1_2_3, 1 is action, 2 is supply object, 3 is accept object
|
8 |
def update_dict_csv(term_dict, f):
|
9 |
for rows in csv.reader(f):
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
else:
|
14 |
-
term_dict[
|
15 |
pass
|
16 |
|
17 |
def export_dict_csv(term_dict, f):
|
@@ -21,17 +22,14 @@ def export_dict_csv(term_dict, f):
|
|
21 |
|
22 |
def save_dict_pickle(term_dict, f):
|
23 |
pickle.dump(term_dict, f, pickle.HIGHEST_PROTOCOL)
|
|
|
24 |
|
25 |
def update_csv_pickle(pickle_f, csv_f):
|
26 |
term_dict = pickle.load(pickle_f)
|
27 |
-
|
28 |
-
if rows[0] in term_dict:
|
29 |
-
if rows[1] not in term_dict[rows[0]]:
|
30 |
-
term_dict[rows[0]] = term_dict[rows[0]]+[rows[1]]
|
31 |
-
else:
|
32 |
-
term_dict[rows[0]]=[rows[1]]
|
33 |
#save to pickle file, highest protocal to get better performance
|
34 |
pickle.dump(term_dict, pickle_f, pickle.HIGHEST_PROTOCOL)
|
|
|
35 |
|
36 |
|
37 |
#demo
|
|
|
7 |
# 1_2_3, 1 is action, 2 is supply object, 3 is accept object
|
8 |
def update_dict_csv(term_dict, f):
|
9 |
for rows in csv.reader(f):
|
10 |
+
word = rows[0].lower()
|
11 |
+
if word in term_dict:
|
12 |
+
if rows[1] not in term_dict[word]:
|
13 |
+
term_dict[word] = term_dict[word]+[rows[1]]
|
14 |
else:
|
15 |
+
term_dict[word]=[rows[1]]
|
16 |
pass
|
17 |
|
18 |
def export_dict_csv(term_dict, f):
|
|
|
22 |
|
23 |
def save_dict_pickle(term_dict, f):
|
24 |
pickle.dump(term_dict, f, pickle.HIGHEST_PROTOCOL)
|
25 |
+
pass
|
26 |
|
27 |
def update_csv_pickle(pickle_f, csv_f):
|
28 |
term_dict = pickle.load(pickle_f)
|
29 |
+
update_dict_csv(term_dict, csv_f)
|
|
|
|
|
|
|
|
|
|
|
30 |
#save to pickle file, highest protocal to get better performance
|
31 |
pickle.dump(term_dict, pickle_f, pickle.HIGHEST_PROTOCOL)
|
32 |
+
pass
|
33 |
|
34 |
|
35 |
#demo
|