BM25Scorer { public double score(int count, int length) { double numerator = count * (k + 1); double denominator = count + (k * (1 - b + (b * length / avgDocLength))); return idf * numerator / denominator; } BM25Scorer(NodeParameters parameters); double score(int count, int length); double score(int count, int length, double externalIDF); double getIDF(); void setIDF(double newIDF); long getDocumentCount(); void setDocumentCount(int dc);  }
@Test public void testScorer() throws Exception { NodeParameters p = new NodeParameters(); p.set("collectionLength", 5000); p.set("documentCount", 100); p.set("nodeDocumentCount", 0); BM25Scorer scorer = new BM25Scorer(p); assertEquals(0.75, scorer.b, 0.001); assertEquals(1.2, scorer.k, 0.001); assertEquals(50.0, scorer.avgDocLength, 0.001); assertEquals(5.29832, scorer.idf, 0.0001); assertEquals(8.20866, scorer.score(5, 100), 0.0001); p.set("nodeDocumentCount", 5); scorer = new BM25Scorer(p); assertEquals(0.75, scorer.b, 0.001); assertEquals(1.2, scorer.k, 0.001); assertEquals(50.0, scorer.avgDocLength, 0.001); assertEquals(2.90042, scorer.idf, 0.0001); assertEquals(5.53660, scorer.score(12, 85), 0.0001); p.set("b", 0.3); p.set("k", 2.0); p.set("nodeDocumentCount", 20); scorer = new BM25Scorer(p); assertEquals(0.3, scorer.b, 0.001); assertEquals(2.0, scorer.k, 0.001); assertEquals(50.0, scorer.avgDocLength, 0.001); assertEquals(1.58474, scorer.idf, 0.0001); assertEquals(3.79327, scorer.score(15, 200), 0.0001); }