【问题标题】:pyLucene - How to use BM25 similarity instead of tf-idfpyLucene - 如何使用 BM25 相似性而不是 tf-idf
【发布时间】:2017-10-05 12:36:36
【问题描述】:

据我了解,pyLucene 现在也提供 BM25 相似性。我正在使用 pyLucene - 4.10.1,但找不到任何关于如何使用 BM25 而不是 tf-idf 的示例。请指导。

【问题讨论】:

    标签: lucene tf-idf pylucene


    【解决方案1】:

    尝试使用 IndexSearcher 的 setSimilarity 设置检索模型。

    import lucene
    
    from java.nio.file import Paths
    from org.apache.lucene.store import SimpleFSDirectory
    from org.apache.lucene.index import DirectoryReader
    from org.apache.lucene.search import IndexSearcher
    from org.apache.lucene.search.similarities import BM25Similarity
    
    
    lucene.initVM(vmargs=['-Djava.awt.headless=true'])
    directory = SimpleFSDirectory(Paths.get(INDEX_DIR))
    searcher = IndexSearcher(DirectoryReader.open(directory))
    
    searcher.setSimilarity(BM25Similarity())
    

    【讨论】:

      猜你喜欢
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 2017-07-27
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多