org.apache.lucene.search.similarities.LMDirichletSimilarity Java Examples

The following examples show how to use org.apache.lucene.search.similarities.LMDirichletSimilarity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KNearestNeighborClassifierTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicUsage() throws Exception {
  LeafReader leafReader = null;
  try {
    MockAnalyzer analyzer = new MockAnalyzer(random());
    leafReader = getSampleIndex(analyzer);
    checkCorrectClassification(new KNearestNeighborClassifier(leafReader, null, analyzer, null, 1, 0, 0, categoryFieldName, textFieldName), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT);
    checkCorrectClassification(new KNearestNeighborClassifier(leafReader, new LMDirichletSimilarity(), analyzer, null, 1, 0, 0, categoryFieldName, textFieldName), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT);
    ClassificationResult<BytesRef> resultDS =  checkCorrectClassification(new KNearestNeighborClassifier(leafReader, new BM25Similarity(), analyzer, null, 3, 2, 1, categoryFieldName, textFieldName), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT);
    ClassificationResult<BytesRef> resultLMS =  checkCorrectClassification(new KNearestNeighborClassifier(leafReader, new LMDirichletSimilarity(), analyzer, null, 3, 2, 1, categoryFieldName, textFieldName), TECHNOLOGY_INPUT, TECHNOLOGY_RESULT);
    assertTrue(resultDS.getScore() != resultLMS.getScore());
  } finally {
    if (leafReader != null) {
      leafReader.close();
    }
  }
}
 
Example #2
Source File: LMDirichletSimilarityFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Similarity getSimilarity() {
  LMDirichletSimilarity sim = (mu != null) ? new LMDirichletSimilarity(mu)
                                           : new LMDirichletSimilarity();
  sim.setDiscountOverlaps(discountOverlaps);
  return sim;
}
 
Example #3
Source File: TestLMDirichletSimilarityFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** dirichlet with parameters */
public void testParameters() throws Exception {
  Similarity sim = getSimilarity("text_params");
  assertEquals(LMDirichletSimilarity.class, sim.getClass());
  LMDirichletSimilarity lm = (LMDirichletSimilarity) sim;
  assertEquals(1000f, lm.getMu(), 0.01f);
}
 
Example #4
Source File: LtrQueryTests.java    From elasticsearch-learning-to-rank with Apache License 2.0 5 votes vote down vote up
@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 BasicModelG(), 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);
}
 
Example #5
Source File: LMDirichletSimilarityProvider.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Inject
public LMDirichletSimilarityProvider(@Assisted String name, @Assisted Settings settings) {
    super(name);
    float mu = settings.getAsFloat("mu", 2000f);
    this.similarity = new LMDirichletSimilarity(mu);
}
 
Example #6
Source File: TestLMDirichletSimilarityFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** dirichlet with default parameters */
public void test() throws Exception {
  assertEquals(LMDirichletSimilarity.class, getSimilarity("text").getClass());
}