TheAnsIs42 commited on
Commit
b829268
1 Parent(s): 28db600

add variable word translation function

Browse files

Former-commit-id: 3d42dd4a0be3324068517811f9b7193e8054893e

Files changed (1) hide show
  1. dict_util.py +6 -1
dict_util.py CHANGED
@@ -1,5 +1,6 @@
1
  import csv
2
  import pickle
 
3
 
4
  ### NOTICE: csv only accept two colomn input. but accept multi-time input.
5
 
@@ -12,7 +13,7 @@ def update_dict_csv(term_dict:dict, f):
12
  if rows[1] not in term_dict[word]:
13
  term_dict[word] = term_dict[word]+[rows[1]]
14
  else:
15
- print("{},{}已存在".format(word, rows[1]))
16
  else:
17
  term_dict[word]=[rows[1]]
18
  term_dict = sort_dict(term_dict)
@@ -38,6 +39,10 @@ def sort_dict(term_dict:dict):
38
  term_dict = dict(sorted(term_dict.items(), key=lambda x:len(x[0]), reverse=True))
39
  return term_dict
40
 
 
 
 
 
41
  #demo
42
  term_dict_sc2 = {}
43
  with open("./finetune_data/dict_enzh.csv", 'r', encoding='utf-8') as f:
 
1
  import csv
2
  import pickle
3
+ from random import randint
4
 
5
  ### NOTICE: csv only accept two colomn input. but accept multi-time input.
6
 
 
13
  if rows[1] not in term_dict[word]:
14
  term_dict[word] = term_dict[word]+[rows[1]]
15
  else:
16
+ print("{},{} 已存在".format(word, rows[1]))
17
  else:
18
  term_dict[word]=[rows[1]]
19
  term_dict = sort_dict(term_dict)
 
39
  term_dict = dict(sorted(term_dict.items(), key=lambda x:len(x[0]), reverse=True))
40
  return term_dict
41
 
42
+ def get_word(term_dict:dict, key:str) -> str:
43
+ word = term_dict[key][randint(0,len(term_dict[key])-1)]
44
+ return word
45
+
46
  #demo
47
  term_dict_sc2 = {}
48
  with open("./finetune_data/dict_enzh.csv", 'r', encoding='utf-8') as f: