如何使用Whoosh库执行拼写检查?我添加了一些文档中的代码。但是它不能纠正单词。请找到我的代码。

def main():
    print " Hi"

    schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
    ix = create_in("/home/praveen/Downloads/who", schema)
    writer = ix.writer()
    writer.add_document(title=u"First document", path=u"/a", content=u"This is the first document we've added!")
    writer.add_document(title=u"Second document", path=u"/b",content=u"The second one is even more interesting!")
    writer.commit()

    qstring = "frm indea wroking for campany"
    qp = qparser.QueryParser("content", ix.schema)
    q = qp.parse(qstring)
    # Try correcting the query
    with ix.searcher() as s:
            corrected = s.correct_query(q,qstring)
            print(corrected)
            print(corrected.query)
            if corrected.query != q:
                print("Did you mean:", corrected.string)

if __name__ == "__main__":
    main();


我的输出是:

 Hi
Correction(And([Term('content', u'frm'), Term('content', u'indea'), Term('content', u'wroking'), Term('content', u'campany')]), 'frm indea wroking for campany')
(content:frm AND content:indea AND content:wroking AND content:campany)


我没有得到带有正确字符串的“您是不是要:”。

最佳答案

该脚本仅从索引的单词中得到更正。您要纠正的短语在索引中没有相似的单词。

你的话:


  “ frm indea忙着露营”


索引词组:


  “这是我们添加的第一个文档!”
  
  “第二个更有趣!”


如果您给出类似的短语:"secend one is ewen"
你会得到:

('Did you mean:', u'second one is even')


它已得到纠正。

关于python - 如何使用Whoosh Python库进行拼写检查?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44822705/

10-10 17:03