我正在try 使用set提取包含选定关键字的句子.交点().
到目前为止,我只得到了'van'这个词的句子.我无法得到'blue tinge'或'off the road'这个词的句子,因为下面的代码只能处理单个关键字.
为什么会发生这种情况,我能做些什么来解决这个问题?非常感谢.
from textblob import TextBlob
import nltk
nltk.download('punkt')
search_words = set(["off the road", "blue tinge" ,"van"])
blob = TextBlob("That is the off the road vehicle I had in mind for my adventure.
Which one? The one with the blue tinge. Oh, I'd use the money for a van.")
matches = []
for sentence in blob.sentences:
blobwords = set(sentence.words)
if search_words.intersection(blobwords):
matches.append(str(sentence))
print(matches)
Output: ["Oh, I'd use the money for a van."]