[英]Cosine scoring in whoosh, python
我已經實現了一些python代碼,以使用BM25在whoosh上運行搜索,但一切正常,但是現在我試圖將評分機制更改為Cosine,卻遇到了以下錯誤:
tfidf中的文件“ TFIDF.py”,第18行,以ix.searcher(weighting = whoosh.scoring.Cosine())作為搜索者: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
任何想法?
謝謝!
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 )以獲取實際可用的選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.