确定句子的结尾。如何“猜测”何时在一个较大的文本字符串中添加句点

问题描述 投票:1回答:1

我整天在转录领域中处理大量文本字符串。没有标点符号或句号。

我想知道是否使用Python或VB ..或任何其他语言,我可以使用program \ script来确定何时添加句点或句子结尾吗?

javascript python string vb.net punctuation
1个回答
0
投票

我想这很大程度上取决于您认为句子的内容以及句子的定义,而不是句号。我注意到的一个这样的标准是在删除期限后的大写字母。

# Python
sen = list("i went to the coffee shop yesterday Today i will go to the school.")

for i in range(len(sen)):
    if sen[i].isupper():
        sen[i] = ". " + sen[i]

# I whipped up that code pretty quickly, so it does generate some small artifacts (" . " instead of ". "), but I'm sure you can fix it.

您还可以尝试检查最后一个字符,并查看它是否为句点(因为句子中的最后一个字符应为句点)。

if sen[-1] != ".":
    sen += "." # If sen is still a string

即使使用这两种小算法,您也可能会遇到一些额外的问题,例如“ I”(“我去买冰淇淋”这个词)始终是大写的,即使不是句子的开头,但是可以很容易地用上一个if循环中的另一个for语句来解决。

© www.soinside.com 2019 - 2024. All rights reserved.