首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cosine评分在whoosh,python

Cosine评分在whoosh,python
EN

Stack Overflow用户
提问于 2013-03-26 20:29:16
回答 1查看 2.2K关注 0票数 2

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

文件"TFIDF.py",第18行,在tfidf中使用TFIDF.py作为搜索器: AttributeError:‘模块’对象没有属性‘余弦’

如果我进口余弦

代码语言:javascript
复制
from whoosh.scoring import Cosine

我明白了:

代码语言:javascript
复制
File "TFIDF.py", line 4, in <module>
    from whoosh.scoring import Cosine
ImportError: cannot import name Cosine

我的代码如下:

代码语言:javascript
复制
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

有什么想法吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-26 20:57:03

关于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)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15646767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档