当前位置: 首页>>代码示例>>Java>>正文


Java BM25Similarity类代码示例

本文整理汇总了Java中org.apache.lucene.search.similarities.BM25Similarity的典型用法代码示例。如果您正苦于以下问题:Java BM25Similarity类的具体用法?Java BM25Similarity怎么用?Java BM25Similarity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BM25Similarity类属于org.apache.lucene.search.similarities包,在下文中一共展示了BM25Similarity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CollectiveTestApproach

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
public CollectiveTestApproach(boolean fuzzy, boolean standardSeacher,
		boolean withDescription) {
	File indexDir = new File(entIndexDirectory);
	File indexDir1 = new File(docIndexDirectory);
	this.fuzzy = fuzzy;
	this.withDescription = withDescription;
	try {
		Directory dir = FSDirectory.open(indexDir);
		Directory dir1 = FSDirectory.open(indexDir1);
		entISearcher = new IndexSearcher(DirectoryReader.open(dir));
		entIReader = DirectoryReader.open(dir);
		docISearcher = new IndexSearcher(DirectoryReader.open(dir1));
		docIReader = DirectoryReader.open(dir1);
		if (!standardSeacher) {
			entISearcher.setSimilarity(new BM25Similarity());
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:21,代码来源:CollectiveTestApproach.java

示例2: BM25SimilarityProvider

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
public BM25SimilarityProvider(String name, Settings settings, Settings indexSettings) {
    super(name);
    float k1 = settings.getAsFloat("k1", 1.2f);
    float b = settings.getAsFloat("b", 0.75f);
    final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger(getClass()));
    boolean discountOverlaps =
        settings.getAsBooleanLenientForPreEs6Indices(Version.indexCreated(indexSettings), "discount_overlaps", true, deprecationLogger);

    this.similarity = new BM25Similarity(k1, b);
    this.similarity.setDiscountOverlaps(discountOverlaps);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:BM25SimilarityProvider.java

示例3: BM25SimilarityProvider

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
@Inject
public BM25SimilarityProvider(@Assisted String name, @Assisted Settings settings) {
    super(name);
    float k1 = settings.getAsFloat("k1", 1.2f);
    float b = settings.getAsFloat("b", 0.75f);
    boolean discountOverlaps = settings.getAsBoolean("discount_overlaps", true);

    this.similarity = new BM25Similarity(k1, b);
    this.similarity.setDiscountOverlaps(discountOverlaps);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:BM25SimilarityProvider.java

示例4: openReader

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
private void openReader() throws IOException {
    this.hitsReader   = DirectoryReader.open(FSDirectory.open(this.hitsDirectory));
    this.hitsSearcher = new IndexSearcher(this.hitsReader);
    this.hitsSearcher.setSimilarity(new BM25Similarity(0.0f, 0.0f)); // simple idf scoring 
    //searcher.setSimilarity(new BM25Similarity(1.2f, 0.75f)); // k1, b
    //searcher.setSimilarity(new LMDirichletSimilarity(200f)); // mu
    //searcher.setSimilarity(new LMJelinekMercerSimilarity(0.5f)); // lambda
}
 
开发者ID:searsia,项目名称:searsiaserver,代码行数:9,代码来源:SearchResultIndex.java

示例5: setupIndex

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
@Before
public void setupIndex() throws IOException {
    dirUnderTest = newDirectory();
    List<Similarity> sims = Arrays.asList(
            new ClassicSimilarity(),
            new SweetSpotSimilarity(), // extends Classic
            new BM25Similarity(),
            new LMDirichletSimilarity(),
            new BooleanSimilarity(),
            new LMJelinekMercerSimilarity(0.2F),
            new AxiomaticF3LOG(0.5F, 10),
            new DFISimilarity(new IndependenceChiSquared()),
            new DFRSimilarity(new BasicModelBE(), new AfterEffectB(), new NormalizationH1()),
            new IBSimilarity(new DistributionLL(), new LambdaDF(), new NormalizationH3())
        );
    similarity = sims.get(random().nextInt(sims.size()));

    indexWriterUnderTest = new RandomIndexWriter(random(), dirUnderTest, newIndexWriterConfig().setSimilarity(similarity));
    for (int i = 0; i < docs.length; i++) {
        Document doc = new Document();
        doc.add(newStringField("id", "" + i, Field.Store.YES));
        doc.add(newField("field", docs[i], Store.YES));
        indexWriterUnderTest.addDocument(doc);
    }
    indexWriterUnderTest.commit();
    indexWriterUnderTest.forceMerge(1);
    indexWriterUnderTest.flush();


    indexReaderUnderTest = indexWriterUnderTest.getReader();
    searcherUnderTest = newSearcher(indexReaderUnderTest);
    searcherUnderTest.setSimilarity(similarity);
}
 
开发者ID:o19s,项目名称:elasticsearch-learning-to-rank,代码行数:34,代码来源:LtrQueryTests.java

示例6: LuceneReRank

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
public LuceneReRank(String indexLocation) throws IOException {
    dir = FSDirectory.open(new File(indexLocation));
    IndexWriterConfig iwc = new IndexWriterConfig(ANALYZER.getVersion(), ANALYZER);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
    writer = new IndexWriter(dir, iwc);
    float K1 = (float) 1.0;
    float B = (float) 0.75;
    //NOTE: Leo mentioned that lucene's bm25 calculation could be not accurate
    similarity = new BM25Similarity(K1, B);
    fieldToLoad.add(RE_RANK_OFFSET);
}
 
开发者ID:oaqa,项目名称:LiveQA,代码行数:12,代码来源:LuceneReRank.java

示例7: testParameters

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/** bm25 with parameters */
public void testParameters() throws Exception {
  Similarity sim = getSimilarity("text_params");
  assertEquals(BM25Similarity.class, sim.getClass());
  BM25Similarity bm25 = (BM25Similarity) sim;
  assertEquals(1.2f, bm25.getK1(), 0.01f);
  assertEquals(0.76f, bm25.getB(), 0.01f);
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:TestBM25SimilarityFactory.java

示例8: getScoringAlgorithmObject

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
@JsonIgnore
public Similarity getScoringAlgorithmObject() {
    if(this.scoringAlgorithm == null || this.scoringAlgorithm.isEmpty() || this.scoringAlgorithm.equals(DEFAULT_SCORING_ALGORITHM) || this.scoringAlgorithm.equalsIgnoreCase("tfidf") || this.scoringAlgorithm.equalsIgnoreCase("vectorspace")) {
        // vector-space model
        return new DefaultSimilarity();
    } else if(this.scoringAlgorithm.equalsIgnoreCase("bm25")) {
        // bm25 probability model
        return new BM25Similarity();
    }
    
    return new DefaultSimilarity();
}
 
开发者ID:iychoi,项目名称:biospectra,代码行数:13,代码来源:Configuration.java

示例9: createFeature5

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
 * Feature 5: cos(BM25) * sim(t_d, q)
 * 
 * @param keyword
 * @return
 */
private Query createFeature5(EntityObject dataObject) {
	String keyword = dataObject.getText();
	BM25Similarity bm25 = new BM25Similarity();
	LearnToRankFuzzyQuery fq = new LearnToRankFuzzyQuery(new Term("title",
			keyword), bm25);
	return fq;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:14,代码来源:LearnToRankFeatureSetupEntityBased.java

示例10: createFeature6

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
 * Feature 6: cos(Bm25) * sim(a_d, q)
 * 
 * @param dataObject
 * @return
 */
private Query createFeature6(EntityObject dataObject) {
	String keyword = dataObject.getText();
	BM25Similarity bm25 = new BM25Similarity();
	LearnToRankFuzzyQuery fq = new LearnToRankFuzzyQuery(new Term(
			"description", keyword), bm25);
	return fq;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:14,代码来源:LearnToRankFeatureSetupEntityBased.java

示例11: createFeature7

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
	 * Feature 7: cos(BM25) * sim(t_d, q_c)
	 * 
	 * @param dataObject
	 * @return
	 */
	private Query createFeature7(EntityObject dataObject) {
		String sentence = dataObject.getContext();
		String[] split = sentence.split(" ");
		LTRBooleanQuery bq = new LTRBooleanQuery();
		BM25Similarity bm25 = new BM25Similarity();
		for (int i = 0; i < split.length; i++) {
//			LearnToRankFuzzyQuery fq = new LearnToRankFuzzyQuery(new Term(
//					"title", split[i]), bm25);
			 LearnToRankTermQuery fq = new LearnToRankTermQuery(new Term(
			 "title", split[i]), bm25);
			bq.add(fq, Occur.SHOULD);
		}
		return bq;
	}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:21,代码来源:LearnToRankFeatureSetupEntityBased.java

示例12: createFeature8

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
	 * Feature 8: cos(BM25) * sim(a_d, q_c)
	 * 
	 * @param dataObject
	 * @return
	 */
	private Query createFeature8(EntityObject dataObject) {
		String sentence = dataObject.getContext();
		String[] split = sentence.split(" ");
		LTRBooleanQuery bq = new LTRBooleanQuery();
		BM25Similarity bm25 = new BM25Similarity();
		for (int i = 0; i < split.length; i++) {
//			LearnToRankFuzzyQuery fq = new LearnToRankFuzzyQuery(new Term(
//					"description", usePorterStemmer(split[i])), bm25);
			 LearnToRankTermQuery fq = new LearnToRankTermQuery(new Term(
			 "description", split[i]), bm25);
			bq.add(fq, Occur.SHOULD);
		}
		return bq;
	}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:21,代码来源:LearnToRankFeatureSetupEntityBased.java

示例13: createFeature6

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
 * Feature 6: cos(Bm25) * sim(a_d, q)
 * 
 * @param dataObject
 * @return
 */
private Query createFeature6(EntityObject dataObject) {
	String keyword = dataObject.getText();
	BM25Similarity bm25 = new BM25Similarity();
	LearnToRankFuzzyQuery fq = new LearnToRankFuzzyQuery(new Term(
			"abstract", keyword), bm25);
	return fq;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:14,代码来源:LearnToRankFeatureSetupDocumentCentric.java

示例14: createFeature7

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
 * Feature 7: cos(BM25) * sim(t_d, q_c)
 * 
 * @param dataObject
 * @return
 */
private Query createFeature7(EntityObject dataObject) {
	String sentence = dataObject.getContext();
	String[] split = sentence.split(" ");
	LTRBooleanQuery bq = new LTRBooleanQuery();
	BM25Similarity bm25 = new BM25Similarity();
	for (int i = 0; i < split.length; i++) {
		LearnToRankFuzzyQuery fq = new LearnToRankFuzzyQuery(new Term(
				"title", split[i]), bm25);
		bq.add(fq, Occur.SHOULD);
	}
	return bq;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:19,代码来源:LearnToRankFeatureSetupDocumentCentric.java

示例15: createFeature8

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
 * Feature 8: cos(BM25) * sim(a_d, q_c)
 * 
 * @param dataObject
 * @return
 */
private Query createFeature8(EntityObject dataObject) {
	String sentence = dataObject.getContext();
	String[] split = sentence.split(" ");
	LTRBooleanQuery bq = new LTRBooleanQuery();
	BM25Similarity bm25 = new BM25Similarity();
	for (int i = 0; i < split.length; i++) {
		LearnToRankFuzzyQuery fq = new LearnToRankFuzzyQuery(new Term(
				"abstract", split[i]), bm25);
		bq.add(fq, Occur.SHOULD);
	}
	return bq;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:19,代码来源:LearnToRankFeatureSetupDocumentCentric.java


注:本文中的org.apache.lucene.search.similarities.BM25Similarity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。