gpt4 book ai didi

python - 获取 python fuzzywuzzy 匹配的索引

转载 作者:太空宇宙 更新时间:2023-11-04 05:40:37 24 4
gpt4 key购买 nike

我正在使用 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 返回一个包含分数的元组,而不仅仅是匹配项。解决方案:

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 - 获取 python fuzzywuzzy 匹配的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34049254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com