문제

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:

File "TFIDF.py", line 18, in tfidf with ix.searcher(weighting=whoosh.scoring.Cosine()) as searcher: AttributeError: 'module' object has no attribute '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. 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top