2017-06-29 15 views
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) 

私は "もしかして:" になっていないです修正文字列で。

私は事前に

感謝を教えてください、

+0

明らかに 'corrected.query == q'です。 –

+0

私のプログラムで何が変更される必要がありますか?私は文書からコードを取り出した。入力はqstringで、スペルチェックを受けなければなりません –

答えて

3

スクリプトは、インデックス付きの単語から修正を取得します。訂正したい句には、索引に似た言葉がありません。

あなたのフレーズ:

"campanyためwroking FRMのindea"

インデックスフレーズ:

は、 "これは、我々が追加した最初の文書であります!"

「もう1つはさらに面白いです!あなたが得る"secend one is ewen" :これはよく補正されて

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

あなたのようなフレーズを与える場合

関連する問題