2

BM25を使用してwhooshで検索を実行するためにいくつかのPythonコードを実装しましたが、すべて問題なく動作しましたが、スコアリングメカニズムをCosineに変更しようとすると、次のエラーが発生します。

ファイル"TFIDF.py"、18行目、検索者としてix.searcher(weighting = whoosh.scoring.Cosine())を使用したtfidf:AttributeError:'module'オブジェクトには属性'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 に答える