• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BM25Similarity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Lucene

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
public Lucene(Path path) throws IOException {
	/* Setup Lucene */
       Directory dir = FSDirectory.open(path);
       // here we are using a standard analyzer, there are a lot of analyzers available to our use.
       Analyzer analyzer = new StandardAnalyzer();
       IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
       //this mode by default overwrites the previous index, not a very good option in real usage
       iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
       iwc.setSimilarity(new BM25Similarity());
       index = new IndexWriter(dir, iwc);
}
 
开发者ID:SeanTater,项目名称:uncc2014watsonsim,代码行数:12,代码来源:Lucene.java


示例17: SpokendocBaseline

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
/**
 *  
 * @param propatiesPath 設定ファイル.propertiesのパス
 * @throws IOException
 */
public SpokendocBaseline(String propatiesPath) throws IOException {
	Properties conf = new Properties();
	FileInputStream fis = new FileInputStream(new File(propatiesPath));
	conf.load(fis);
	this.analyzer = new WhitespaceAnalyzer(Version.LUCENE_46);
	this.task = conf.getProperty("task");
	this.freqfilePath = conf.getProperty("freqfile");
	this.tokenizerPath = conf.getProperty("tokenizer");
	this.resultPath = conf.getProperty("result");
	this.normalization = new Boolean(conf.getProperty("normalization"));
	//メモリにインデックス保存する。テスト用
	//this.directory = new RAMDirectory();
	//MMapDirectory: 読み込みはメモリ、書き出しはファイルシステムらしい
	String indexPath = conf.getProperty("index");
	this.indexDirectory = MMapDirectory.open(new File(indexPath));

	String selectedSimilarity = conf.getProperty("similarity");
	if (selectedSimilarity.equals("LMDirichlet")) {
		float mu = Float.valueOf(conf.getProperty("mu"));
	    this.similarity = new LMDirichletSimilarity(mu);
	}
	else if (selectedSimilarity.equals("BM25")) {
		float k1 = Float.valueOf(conf.getProperty("k1"));
		float b = Float.valueOf(conf.getProperty("b"));
	    this.similarity = new BM25Similarity(k1, b);
	}
	else {
	    this.similarity = new DefaultSimilarity();	
	}
	fis.close();
}
 
开发者ID:Kesin11,项目名称:Spokendoc-Baseline,代码行数:37,代码来源:SpokendocBaseline.java


示例18: getSimilarity

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
private PerFieldSimilarityWrapper getSimilarity(final QueryWithFilters queryWithFilters) {
	return new PerFieldSimilarityWrapper() {
		@Override
		public Similarity get(String name) {

			AnalyzerSettings analyzerSettings = indexConfig.getAnalyzerSettingsForIndexField(name);
			AnalyzerSettings.Similarity similarity = AnalyzerSettings.Similarity.BM25;
			if (analyzerSettings != null) {
				similarity = analyzerSettings.getSimilarity();
			}

			AnalyzerSettings.Similarity fieldSimilarityOverride = queryWithFilters.getFieldSimilarityOverride(name);
			if (fieldSimilarityOverride != null) {
				similarity = fieldSimilarityOverride;
			}

			if (AnalyzerSettings.Similarity.TFIDF.equals(similarity)) {
				return new ClassicSimilarity();
			}
			else if (AnalyzerSettings.Similarity.BM25.equals(similarity)) {
				return new BM25Similarity();
			}
			else if (AnalyzerSettings.Similarity.CONSTANT.equals(similarity)) {
				return new ConstantSimilarity();
			}
			else if (AnalyzerSettings.Similarity.TF.equals(similarity)) {
				return new TFSimilarity();
			}
			else {
				throw new RuntimeException("Unknown similarity type <" + similarity + ">");
			}
		}
	};
}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:35,代码来源:LumongoSegment.java


示例19: getSimilarity

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
private static Similarity getSimilarity(JsonObject similarity) {
    switch (similarity.getString("type")) {
    case "BM25Similarity":
        JsonNumber k1 = similarity.getJsonNumber("k1");
        JsonNumber b = similarity.getJsonNumber("b");
        if (k1 != null && b != null)
            return new BM25Similarity((float) k1.doubleValue(), (float) b.doubleValue());
        return new BM25Similarity();
    case "TermFrequencySimilarity":
        return new TermFrequencySimilarity();
    }
    return null;
}
 
开发者ID:seecr,项目名称:meresco-lucene,代码行数:14,代码来源:LuceneSettings.java


示例20: testBM25Similarity

import org.apache.lucene.search.similarities.BM25Similarity; //导入依赖的package包/类
@Test
public void testBM25Similarity() throws Exception {
    LuceneSettings settings = new LuceneSettings();
    String json = "{\"similarity\": {\"type\": \"BM25Similarity\"}}";

    settings.updateSettings(new StringReader(json));
    assertEquals(BM25Similarity.class, settings.similarity.getClass());
    assertEquals(0.75f, ((BM25Similarity) settings.similarity).getB(), 0);
    assertEquals(1.2f, ((BM25Similarity) settings.similarity).getK1(), 0);
}
 
开发者ID:seecr,项目名称:meresco-lucene,代码行数:11,代码来源:LuceneSettingsTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MutableCallSite类代码示例发布时间:2022-05-21
下一篇:
Java UiScrollable类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap