Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions funasr/utils/postprocess_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ def sentence_postprocess(words: List[Any], time_stamp: List[List] = None):
ts_lists.append([begin, end])
begin = end
else:
if alpha_blank is True:
word_lists.pop()
word_lists.append(ch)
alpha_blank = False
if time_stamp is not None:
ts_lists.append([time_stamp[i][0], time_stamp[i][1]])

if time_stamp is not None:
word_lists, ts_lists = abbr_dispose(word_lists, ts_lists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ def sentence_postprocess(words: List[Any], time_stamp: List[List] = None):
ts_lists.append([begin, end])
begin = end
else:
raise ValueError("invalid character: {}".format(ch))
if alpha_blank is True:
word_lists.pop()
word_lists.append(ch)
alpha_blank = False
if time_stamp is not None:
ts_lists.append([time_stamp[i][0], time_stamp[i][1]])

if time_stamp is not None:
word_lists, ts_lists = abbr_dispose(word_lists, ts_lists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ def sentence_postprocess(words: List[Any], time_stamp: List[List] = None):
ts_lists.append([begin, end])
begin = end
else:
raise ValueError("invalid character: {}".format(ch))
if alpha_blank is True:
word_lists.pop()
word_lists.append(ch)
alpha_blank = False
if time_stamp is not None:
ts_lists.append([time_stamp[i][0], time_stamp[i][1]])

if time_stamp is not None:
word_lists, ts_lists = abbr_dispose(word_lists, ts_lists)
Expand Down
32 changes: 32 additions & 0 deletions tests/test_sentence_postprocess_timestamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ def test_spelled_out_letters_are_one_word_without_timestamps(self):
("看CCTV新闻", ["看", "CCTV", "新", "闻"]),
)

def test_symbol_tokens_keep_their_own_timestamp(self):
self.assert_timestamps(
["价", "格", "是", "3", ".", "5", "元", "好"],
["价", "格", "是", "3", ".", "5", "元", "好"],
[[i * 100, (i + 1) * 100] for i in range(8)],
)
self.assert_timestamps(
["ok", ".", "好"],
["ok", ".", "好"],
[[0, 100], [100, 200], [200, 300]],
)
self.assert_timestamps(
["x", "y", ".", "好"],
["XY", ".", "好"],
[[0, 200], [200, 300], [300, 400]],
)

def test_spelled_out_letters_after_a_symbol_token_keep_their_timestamp(self):
self.assert_timestamps(
[".", "x", "y"],
[".", "XY"],
[[0, 100], [100, 300]],
)

def test_symbol_tokens_are_accepted_without_timestamps(self):
for path in POSTPROCESS_UTILS:
with self.subTest(path=path):
self.assertEqual(
_load_sentence_postprocess(path)(["价", "格", "3", ".", "5", "元"]),
("价格3.5元", ["价", "格", "3", ".", "5", "元"]),
)


if __name__ == "__main__":
unittest.main()
Loading