如何为输入搜索引擎添加容忍度
How can I add tolerance to an input search engine
我有这段代码可以在大文本文件中搜索文本:
y = input("Apellido/s:").upper()
for line in fread:
if y in line:
print(line)
如果没有找到,我如何实现搜索类似 text/autocorrect 的方法。不像 google 那样广泛,但只搜索可能有 1 个字母或单词重音的文本。想不到算法自己搞定
我现在必须添加一个 if 但我要求的是逻辑
您可以使用 find_near_matches from fuzzysearch
from fuzzysearch import find_near_matches
y = input("Apellido/s:").upper()
for line in fread:
if find_near_matches(y, line, max_l_dist=2):
print(line)
find_near_matches
return 如果找到匹配列表,如果没有找到匹配列表 returns 一个空数组,计算结果为 false。
max_l_dist
选项表示 the total number of substitutions, insertions and deletions (a.k.a. the Levenshtein distance)
我有这段代码可以在大文本文件中搜索文本:
y = input("Apellido/s:").upper()
for line in fread:
if y in line:
print(line)
如果没有找到,我如何实现搜索类似 text/autocorrect 的方法。不像 google 那样广泛,但只搜索可能有 1 个字母或单词重音的文本。想不到算法自己搞定
我现在必须添加一个 if 但我要求的是逻辑
您可以使用 find_near_matches from fuzzysearch
from fuzzysearch import find_near_matches
y = input("Apellido/s:").upper()
for line in fread:
if find_near_matches(y, line, max_l_dist=2):
print(line)
find_near_matches
return 如果找到匹配列表,如果没有找到匹配列表 returns 一个空数组,计算结果为 false。
max_l_dist
选项表示 the total number of substitutions, insertions and deletions (a.k.a. the Levenshtein distance)