MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / check_fuzzy

Function check_fuzzy

CheckErrorWord.py:24–36  ·  view source on GitHub ↗
(trie, word, path='', tol=1)

Source from the content-addressed store, hash-verified

22# 搜索过程中,用path记录搜索路径,该路径及为一个词典中存在的词,作为纠错的参考
23# 最终结果即为诸多搜索停止位置的结点路径的并集
24def check_fuzzy(trie, word, path='', tol=1): #tol为容错数
25 if word == '':
26 return [path] if END in trie else []
27 else:
28 p0 = []
29 if word[0] in trie:
30 p0 = check_fuzzy(trie[word[0]], word[1:], path+word[0], tol)
31 p1 = []
32 if tol > 0:
33 for k in trie:
34 if k != word[0]:
35 p1.extend(check_fuzzy(trie[k], word[1:], path+k, tol-1))
36 return p0 + p1
37
38
39# 测试代码

Callers 1

CheckErrorWord.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected