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
任意のアイデア???
ありがとうございました!