Merge pull request #778 from jmaple12/patch-2

Update text_segmentation_method.py
This commit is contained in:
RVC-Boss 2024-03-17 14:40:11 +08:00 committed by GitHub
commit 5106fbc62a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,7 +82,8 @@ def cut1(inp):
inp = inp.strip("\n")
inps = split(inp)
split_idx = list(range(0, len(inps), 4))
split_idx[-1] = None
# split_idx[-1] = None
split_idx.append(None)
if len(split_idx) > 1:
opts = []
for idx in range(len(split_idx) - 1):
@ -135,7 +136,8 @@ def cut5(inp):
# if not re.search(r'[^\w\s]', inp[-1]):
# inp += '。'
inp = inp.strip("\n")
punds = r'[,.;?!、,。?!;:…]'
# punds = r'[,.;?!、,。?!;:…]'
punds = r'[,.;?!、,。?!;::…]'
items = re.split(f'({punds})', inp)
mergeitems = ["".join(group) for group in zip(items[::2], items[1::2])]
# 在句子不存在符号或句尾无符号的时候保证文本完整
@ -149,4 +151,4 @@ def cut5(inp):
if __name__ == '__main__':
method = get_method("cut5")
print(method("你好,我是小明。你好,我是小红。你好,我是小刚。你好,我是小张。"))