|
@@ -44,15 +44,22 @@ def forward_segment(text, dic):
|
|
|
i += len(longest_word)
|
|
i += len(longest_word)
|
|
|
return word_list
|
|
return word_list
|
|
|
|
|
|
|
|
-
|
|
|
|
|
def seg_tokenize(txt, seg_dict):
|
|
def seg_tokenize(txt, seg_dict):
|
|
|
|
|
+ pattern = re.compile(r'^[\u4E00-\u9FA50-9]+$')
|
|
|
out_txt = ""
|
|
out_txt = ""
|
|
|
for word in txt:
|
|
for word in txt:
|
|
|
word = word.lower()
|
|
word = word.lower()
|
|
|
if word in seg_dict:
|
|
if word in seg_dict:
|
|
|
out_txt += seg_dict[word] + " "
|
|
out_txt += seg_dict[word] + " "
|
|
|
else:
|
|
else:
|
|
|
- out_txt += "<unk>" + " "
|
|
|
|
|
|
|
+ if pattern.match(word):
|
|
|
|
|
+ for char in word:
|
|
|
|
|
+ if char in seg_dict:
|
|
|
|
|
+ out_txt += seg_dict[char] + " "
|
|
|
|
|
+ else:
|
|
|
|
|
+ out_txt += "<unk>" + " "
|
|
|
|
|
+ else:
|
|
|
|
|
+ out_txt += "<unk>" + " "
|
|
|
return out_txt.strip().split()
|
|
return out_txt.strip().split()
|
|
|
|
|
|
|
|
def seg_tokenize_wo_pattern(txt, seg_dict):
|
|
def seg_tokenize_wo_pattern(txt, seg_dict):
|