我在MongoDB建立了一个庞大的银行数据库。我可以很容易地获取这些信息并用它创建索引。例如,密苏里州伊格尔银行和密苏里信托银行的名称可以匹配。下面的代码使用简单的fuzzy-such,但无法在上面实现匹配:
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(name=TEXT(stored=True))
ix = create_in("indexdir", schema)
writer = ix.writer()
test_items = [u"Eagle Bank and Trust Company of Missouri"]
writer.add_document(name=item)
writer.commit()
from whoosh.qparser import QueryParser
from whoosh.query import FuzzyTerm
with ix.searcher() as s:
qp = QueryParser("name", schema=ix.schema, termclass=FuzzyTerm)
q = qp.parse(u"Eagle Bank & Trust Co of Missouri")
results = s.search(q)
print results
给我:
^{pr2}$用呼呼声能达到我想要的效果吗?如果没有,我还有什么其他基于python的解决方案呢?在
您可以在Whoosh中使用模糊搜索将}进行匹配,但由于}之间的差异很大,所以不应该 进行匹配。}相似,}相似,你可以想象搜索结果有多糟糕,有多大。在
Co
与{Co
和{Co
与Company
相似,因为Be
与{ny
与{但是,如果您想将}与{}匹配,可以使用
Compan
或compani
或{FuzzyTerm
的个性化类,默认maxdist
等于2或更多:然后:
^{pr2}$您可以通过将},但是我说的这会导致错误的搜索结果。我建议将}。在
maxdist
设置为5
来匹配Co
和{maxdist
从1
保留到{如果您正在寻找匹配词的语言变体,最好使用^{} 。在
注意:旧版的Whoosh有}。在
minsimilarity
而不是{也许这其中的一些东西可能会有所帮助(字符串匹配由seatgeek的开源人员提供):
https://github.com/seatgeek/fuzzywuzzy
为了将来的参考,肯定有更好的方法来做这件事,但这是我的机会。在
相关问题 更多 >
编程相关推荐