提问人:BlackHawk 提问时间:10/28/2023 更新时间:10/28/2023 访问量:54
如果句子被剪切,则从字符串中删除最后一句 [closed]
Removing last sentence from a string if sentence is cut [closed]
问:
我正在使用 Python OpenAI API 从 GPT-4 生成响应。问题是有时响应中的最后一句话被剪掉了。如果这句话被删掉了,我想删除最后一句话。例如,should result in 和 should result in Further,不应剪切。This is a full sentence. A second sentence. This sentence is cu
This is a full sentence. A second sentence.
This is another example. Here the last punctuation is missing
This is another example.
Here we are again. How are you doing?
如何实现这一目标?这可以使用 nltk 或正则表达式来实现吗?
答:
0赞
Ajay Pun Magar
10/28/2023
#1
text='This is a full sentence. A second sentence. hello'
text=text.strip()+' '
text=text.replace('. ','. <new_line>')
sentences=text.split('<new_line>')
if '. ' not in sentences[-1]:
sentences.pop()
out=''.join(sentences)
评论
.!?
.!?