gpt4 book ai didi

python - 在触发词之后剪切句子

转载 作者:行者123 更新时间:2023-11-30 22:42:13 25 4
gpt4 key购买 nike

我有以下带有方法的类:

class Trigger():

def getRidOfTrashPerSentence(self, line, stopwords):
countWord = 0
words = line.split()
for word in words:
if countWord == 0:
if word in stopwords:
sep = word
lineNew = line.split(sep, 1)[0]
countWord = countWord + 1
return(lineNew)

stopwords = ['regards', 'Regards']

def getRidOfTrash(self, aTranscript):
result = [self.getRidOfTrashPerSentence(line, self.stopwords) for line in aTranscript]
return(result)

我想用它实现的是在某些触发词(如['regards', 'Regards'])之后删除句子中的“垃圾”

所以当我插入这样的 block 时:

aTranScript = [ "That's fine, regards Henk", "Allright great"]

我正在寻找这样的输出:

aTranScript = [ "That's fine, regards", "Allright great"]

但是当我这样做时:

newFile = Trigger()
newContent = newFile.getRidOfTrash(aTranScript)

我只得到“没关系”

关于如何获得两个字符串的任何想法

最佳答案

这是一个简单的解决方案:

yourString = 'Hello thats fine, regards Henk'
yourString.split(', regards')[0]

此代码将返回:“你好,很好”

如果需要,您可以在末尾添加“问候”:

yourString.split(', 问候')[0]+', 问候'

关于python - 在触发词之后剪切句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42221457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com