我使用Python fuzzywuzzy在一个句子列表中查找匹配:
def getMatches(needle):
return process.extract(needle, bookSentences, scorer=fuzz.token_sort_ratio, limit=3)我正试着打印出火柴和它周围的句子:
for match in matches:
matchIndex = bookSentences.index(match)
sentenceIndices = range(matchIndex-2,matchIndex+2)
for index in sentenceIndices:
print bookSentences[index],
print '\n\n'不幸的是,脚本未能在原始列表中找到匹配:
ValueError:(U‘’Thus,除了上面提到的两个目的之外,这本书至少是为两组写的: 1.',59)不在名单上
是否有更好的方法在原始列表中找到匹配的索引?fuzzywuzzy能不能给我点什么?自述文件里似乎没有关于它的任何东西。
如何在fuzzywuzzy返回的匹配的原始列表中获取索引
发布于 2015-12-02 17:40:19
我觉得有点傻。fuzzywuzzy返回一个包含分数的元组,而不仅仅是比赛。解决办法:
for match in matches:
matchIndex = bookSentences.index(match[0])
sentenceIndices = range(matchIndex-2,matchIndex+2)
for index in sentenceIndices:
print bookSentences[index],
print '\n\n'https://stackoverflow.com/questions/34049254
复制相似问题