获取 python 个 fuzzywuzzy 匹配项的索引
Get index of python fuzzywuzzy match
我正在使用 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, in addition to the twin purposes mentioned above, this book is written for at least two groups: 1.', 59) is not in list
有没有更好的方法在原始列表中找到匹配项的索引? fuzzywuzzy
有什么办法可以给我吗? readme 中似乎没有任何内容。
如何获取 fuzzywuzzy
返回的匹配项的原始列表中的索引?
我觉得有点傻。 fuzzywuzzy
returns 包含分数的元组,而不仅仅是匹配项。解决方案:
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'
我正在使用 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, in addition to the twin purposes mentioned above, this book is written for at least two groups: 1.', 59) is not in list
有没有更好的方法在原始列表中找到匹配项的索引? fuzzywuzzy
有什么办法可以给我吗? readme 中似乎没有任何内容。
如何获取 fuzzywuzzy
返回的匹配项的原始列表中的索引?
我觉得有点傻。 fuzzywuzzy
returns 包含分数的元组,而不仅仅是匹配项。解决方案:
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'