我正在从事一个文本搜索项目,并使用文本 blob 从文本中搜索句子。TextBlob 有效地提取所有带有关键字的句子。但是,为了进行有效的研究,我还想在之前和之后提取一个句子,我无法弄清楚。
下面是我正在使用的代码:
def extraxt_sents(Text,word):
search_words = set(word.split(','))
sents = ''.join([s.lower() for s in Text])
blob = TextBlob(sents)
matches = [str(s) for s in blob.sentences if search_words & set(s.words)]
print search_words
print(matches)