2

我已经实现了一些 python 代码来使用 BM25 在 whoosh 上运行搜索并且一切正常,但是现在我正在尝试将评分机制更改为余弦,我收到了这个错误:

文件“TFIDF.py”,第 18 行,在 tfidf 中使用 ix.searcher(weighting=whoosh.scoring.Cosine()) 作为搜索器:AttributeError: 'module' object has no attribute 'Cosine'

如果我导入余弦

from whoosh.scoring import Cosine

我明白了:

File "TFIDF.py", line 4, in <module>
    from whoosh.scoring import Cosine
ImportError: cannot import name Cosine

我的代码如下:

import whoosh
from whoosh.scoring import Cosine
from whoosh.fields import *
from whoosh.scoring import *
from whoosh.qparser import *
from whoosh.query import *
from whoosh.index import open_dir

#Index path
lab3dir= "../lab3/Aula3_1/"
ix = open_dir(lab3dir + "indexdir") #Index generated in previous lab


def cosine(queryTerms):
    list=[]
    dict={} # dict com ID do doc e Similiaridade 
    with ix.searcher(weighting=whoosh.scoring.Cosine()) as searcher:
        query = QueryParser("content", ix.schema, group=OrGroup).parse(u(queryTerms))
        results = searcher.search(query, limit=100)
        for i,r in enumerate(results):
            list.append(r["id"])
            print r, results.score(i)
            dict[r["id"]]= results.score(i)
    return dict

有什么想法???

谢谢!

4

1 回答 1

0

http://pythonhosted.org/Whoosh/searching.html#the-searcher-object上的文档,我认为您正在查看的内容与您发现的不正确。查看文档(http://pythonhosted.org/Whoosh/api/scoring.html#module-whoosh.scoring)或源代码(https://bitbucket.org/mchaput/whoosh/src/362fc2999c8cabc51370f433de7402fafd536ec6/src/ whoosh/scoring.py?at=default ) 用于实际可用的选项。

于 2013-03-26T20:57:03.407 回答