【发布时间】:2015-12-02 17:32:27
【问题描述】:
我正在使用 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'因此,除了上面提到的双重目的之外,这本书至少是为两个群体写的:1.', 59) 不在列表中
有没有更好的方法在原始列表中找到匹配的索引? fuzzywuzzy 可以给我吗? readme 中似乎没有任何关于它的内容。
如何获取fuzzywuzzy返回的匹配的原始列表中的索引?
【问题讨论】:
标签: python fuzzy-search fuzzywuzzy