[英]Cosine scoring in whoosh, python
I've implemented some python code to run search on whoosh using BM25 and all went out ok, but now that I'm trying to change scoring mechanism to Cosine, I'm getting this error: 我已经实现了一些python代码,以使用BM25在whoosh上运行搜索,但一切正常,但是现在我试图将评分机制更改为Cosine,却遇到了以下错误:
File "TFIDF.py", line 18, in tfidf with ix.searcher(weighting=whoosh.scoring.Cosine()) as searcher: AttributeError: 'module' object has no attribute 'Cosine' tfidf中的文件“ TFIDF.py”,第18行,以ix.searcher(weighting = whoosh.scoring.Cosine())作为搜索者:AttributeError:'module'对象没有属性'Cosine'
If I import Cosine 如果我导入余弦
from whoosh.scoring import Cosine
I get this: 我得到这个:
File "TFIDF.py", line 4, in <module>
from whoosh.scoring import Cosine
ImportError: cannot import name Cosine
My code is below: 我的代码如下:
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
Any ideias??? 任何想法?
Thank you! 谢谢!
The documentation on http://pythonhosted.org/Whoosh/searching.html#the-searcher-object , which I assume is what you're looking at is incorrect as you have found. http://pythonhosted.org/Whoosh/searching.html#the-searcher-object上的文档(我认为这是您正在查看的内容)不正确。 Look at the documentation ( http://pythonhosted.org/Whoosh/api/scoring.html#module-whoosh.scoring ) or the source code ( https://bitbucket.org/mchaput/whoosh/src/362fc2999c8cabc51370f433de7402fafd536ec6/src/whoosh/scoring.py?at=default ) for the options actually available. 查看文档( 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.