| | |
| | | |
| | | |
| | | def isChinese(ch: str): |
| | | if '\u4e00' <= ch <= '\u9fff' or '\u0030' <= ch <= '\u0039': |
| | | if '\u4e00' <= ch <= '\u9fff' or '\u0030' <= ch <= '\u0039' or ch == '@': |
| | | return True |
| | | return False |
| | | |
| | |
| | | cur = i.replace(' ', '') |
| | | cur = cur.replace('</s>', '') |
| | | cur = cur.replace('<s>', '') |
| | | cur = cur.replace('<unk>', '') |
| | | cur = cur.replace('<OOV>', '') |
| | | word_lists.append(cur) |
| | | |
| | | if len(word_lists) == 0: |
| | |
| | | cur = i.replace(' ', '') |
| | | cur = cur.replace('</s>', '') |
| | | cur = cur.replace('<s>', '') |
| | | cur = cur.replace('<unk>', '') |
| | | cur = cur.replace('<OOV>', '') |
| | | word_lists.append(cur) |
| | | |
| | | if len(word_lists) == 0: |
| | |
| | | else: |
| | | word = i.decode('utf-8') |
| | | |
| | | if word in ['<s>', '</s>', '<unk>']: |
| | | if word in ['<s>', '</s>', '<unk>', '<OOV>']: |
| | | continue |
| | | else: |
| | | middle_lists.append(word) |
| | |
| | | ts_lists.append([begin, end]) |
| | | begin = end |
| | | else: |
| | | raise ValueError('invalid character: {}'.format(ch)) |
| | | word_lists.append(ch) |
| | | |
| | | if time_stamp is not None: |
| | | word_lists, ts_lists = abbr_dispose(word_lists, ts_lists) |
| | |
| | | return sentence, ts_lists, real_word_lists |
| | | else: |
| | | word_lists = abbr_dispose(word_lists) |
| | | real_word_lists = [] |
| | | for ch in word_lists: |
| | | if ch != ' ': |
| | | real_word_lists.append(ch) |
| | | sentence = ''.join(word_lists).strip() |
| | | return sentence |
| | | return sentence, real_word_lists |