1
如何使用whoosh庫進行拼寫檢查。我在文檔中添加了一些代碼。但它不糾正單詞。請找到我的代碼。如何使用whoosh python庫進行拼寫檢查
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)
我沒有收到 「你的意思是:」 與修正的字符串。
請讓我知道提前
感謝,
然後顯然'corrected.query == q'。 –
我的程序需要做什麼修改。我從文檔中獲取代碼。輸入是應該接受拼寫檢查的qstring –