Search in sources :

Example 1 with SweetSpotSimilarity

use of org.apache.lucene.misc.SweetSpotSimilarity in project lucene-solr by apache.

the class TestSweetSpotSimilarityFactory method testDefaults.

/** default parameters */
public void testDefaults() throws Exception {
    SweetSpotSimilarity sim = getSimilarity("text", SweetSpotSimilarity.class);
    // SSS tf w/defaults should behave just like DS
    ClassicSimilarity d = new ClassicSimilarity();
    for (int i = 0; i <= 1000; i++) {
        assertEquals("tf: i=" + i, d.tf(i), sim.tf(i), 0.0F);
    }
    // default norm sanity check
    assertEquals("norm 1", 1.00F, computeNorm(sim, 1), 0.0F);
    assertEquals("norm 4", 0.50F, computeNorm(sim, 4), 0.0F);
    assertEquals("norm 16", 0.25F, computeNorm(sim, 16), 0.0F);
}
Also used : SweetSpotSimilarity(org.apache.lucene.misc.SweetSpotSimilarity) ClassicSimilarity(org.apache.lucene.search.similarities.ClassicSimilarity)

Example 2 with SweetSpotSimilarity

use of org.apache.lucene.misc.SweetSpotSimilarity in project lucene-solr by apache.

the class TestSweetSpotSimilarityFactory method testHyperbolicParameters.

/** hyperbolic with parameters */
public void testHyperbolicParameters() throws Exception {
    SweetSpotSimilarity sim = getSimilarity("text_hyperbolic", SweetSpotSimilarity.class);
    for (int i = 1; i <= 1000; i++) {
        assertTrue("MIN tf: i=" + i + " : s=" + sim.tf(i), 3.3F <= sim.tf(i));
        assertTrue("MAX tf: i=" + i + " : s=" + sim.tf(i), sim.tf(i) <= 7.7F);
    }
    assertEquals("MID tf", 3.3F + (7.7F - 3.3F) / 2.0F, sim.tf(5), 0.00001F);
    // norms: plateau from 1-5, shallow slope
    assertEquals("norm 1", 1.00F, computeNorm(sim, 1), 0.0F);
    assertEquals("norm 2", 1.00F, computeNorm(sim, 2), 0.0F);
    assertEquals("norm 3", 1.00F, computeNorm(sim, 3), 0.0F);
    assertEquals("norm 4", 1.00F, computeNorm(sim, 4), 0.0F);
    assertEquals("norm 5", 1.00F, computeNorm(sim, 5), 0.0F);
    assertTrue("norm 6 too high: " + computeNorm(sim, 6), computeNorm(sim, 6) < 1.0F);
    assertTrue("norm 7 higher then norm 6", computeNorm(sim, 7) < computeNorm(sim, 6));
    assertTrue("norm 20 not high enough: " + computeNorm(sim, 20), 0.25F < computeNorm(sim, 20));
}
Also used : SweetSpotSimilarity(org.apache.lucene.misc.SweetSpotSimilarity)

Example 3 with SweetSpotSimilarity

use of org.apache.lucene.misc.SweetSpotSimilarity in project lucene-solr by apache.

the class TestSweetSpotSimilarityFactory method testBaselineParameters.

/** baseline with parameters */
public void testBaselineParameters() throws Exception {
    SweetSpotSimilarity sim = getSimilarity("text_baseline", SweetSpotSimilarity.class);
    ClassicSimilarity d = new ClassicSimilarity();
    // constant up to 6
    for (int i = 1; i <= 6; i++) {
        assertEquals("tf i=" + i, 1.5F, sim.tf(i), 0.0F);
    }
    // less then default sim above 6
    for (int i = 6; i <= 1000; i++) {
        assertTrue("tf: i=" + i + " : s=" + sim.tf(i) + " < d=" + d.tf(i), sim.tf(i) < d.tf(i));
    }
    // norms: plateau from 3-5
    assertEquals("norm 1 == 7", computeNorm(sim, 1), computeNorm(sim, 7), 0.0F);
    assertEquals("norm 2 == 6", computeNorm(sim, 1), computeNorm(sim, 7), 0.0F);
    assertEquals("norm 3", 1.00F, computeNorm(sim, 3), 0.0F);
    assertEquals("norm 4", 1.00F, computeNorm(sim, 4), 0.0F);
    assertEquals("norm 5", 1.00F, computeNorm(sim, 5), 0.0F);
    assertTrue("norm 6 too high: " + computeNorm(sim, 6), computeNorm(sim, 6) < 1.0F);
    assertTrue("norm 7 higher then norm 6", computeNorm(sim, 7) < computeNorm(sim, 6));
    assertEquals("norm 20", 0.25F, computeNorm(sim, 20), 0.0F);
}
Also used : SweetSpotSimilarity(org.apache.lucene.misc.SweetSpotSimilarity) ClassicSimilarity(org.apache.lucene.search.similarities.ClassicSimilarity)

Aggregations

SweetSpotSimilarity (org.apache.lucene.misc.SweetSpotSimilarity)3 ClassicSimilarity (org.apache.lucene.search.similarities.ClassicSimilarity)2