python - 如何使用 whoosh python 库进行拼写检查?

标签 python python-2.7 spell-checking whoosh

如何使用 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 wroking for campany"

索引短语:

"This is the first document we've added!"

"The second one is even more interesting!"

如果你给出这样的短语:“secend one is ewen” 你将得到:

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

已修正得很好。

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

相关文章:

python - 当时间序列中的一个值出现多次时替换它

python - 如何在 python 中终止 qthread

python - 定时器的暂停/恢复功能

parsing - OpenOffice 词典的格式是什么?

python - 如何使用 Python 访问(读取、写入)Google Sheets 电子表格?

python - django-admin.py makemessages 失败

python-2.7 - python - Flask test_client() 没有使用 pytest 的 request.authorization

python - 如何(正确)使用 PIP 安装和导入 pymavlink

search - Solr - 示例拼写检查器不工作

linux - 如何在 google colab 中启用拼写检查器(colab 在 linux 操作系统上运行)?