This commit is contained in:
haoneng.lhn 2023-04-17 19:01:10 +08:00
parent 0e05ca31a9
commit 5aec896e02
2 changed files with 3 additions and 3 deletions

View File

@ -19,6 +19,7 @@ def forward_segment(text, seg_dict):
def seg_tokenize(txt, seg_dict):
out_txt = ""
for word in txt:
word = word.lower()
if word in seg_dict:
out_txt += seg_dict[word] + " "
else:
@ -41,8 +42,7 @@ def tokenize(data,
if seg_dict is not None:
assert isinstance(seg_dict, dict)
txt = forward_segment("".join(text).lower(), seg_dict)
text = seg_tokenize(txt, seg_dict)
text = seg_tokenize(text, seg_dict)
length = len(text)
for i in range(length):

View File

@ -48,6 +48,7 @@ def forward_segment(text, dic):
def seg_tokenize(txt, seg_dict):
out_txt = ""
for word in txt:
word = word.lower()
if word in seg_dict:
out_txt += seg_dict[word] + " "
else:
@ -359,7 +360,6 @@ class CommonPreprocessor(AbsPreprocessor):
if self.split_with_space:
tokens = text.strip().split(" ")
if self.seg_dict is not None:
tokens = forward_segment("".join(tokens), self.seg_dict)
tokens = seg_tokenize(tokens, self.seg_dict)
else:
tokens = self.tokenizer.text2tokens(text)