it.unimi.di.mg4j.search.score
Class DecreasingDocumentRankScorer

java.lang.Object
  extended by it.unimi.di.mg4j.search.score.AbstractScorer
      extended by it.unimi.di.mg4j.search.score.DecreasingDocumentRankScorer
All Implemented Interfaces:
DelegatingScorer, Scorer, FlyweightPrototype<Scorer>

public class DecreasingDocumentRankScorer
extends AbstractScorer
implements DelegatingScorer

Compute scores that do not depend on intervals, but that just assign a fixed score to each document starting from 1; scores are read from a file whose name is passed to the constructor.

This scorer assumes that scores are nonnegative and that documents are ordered in decreasing score order: that is, that if i < j then the score of i is greater than or equal to the score of j. This allows to normalise the score (the document with the highest score has exactly score 1) without additional costs. This scorer will throw an IllegalStateException if this assumption is violated.


Field Summary
 
Fields inherited from class it.unimi.di.mg4j.search.score.AbstractScorer
documentIterator, indexIterator
 
Constructor Summary
DecreasingDocumentRankScorer(double[] score)
          Builds a document scorer with given scores.
DecreasingDocumentRankScorer(String filename)
          Builds a document scorer by first reading the ranks from a file.
 
Method Summary
 DecreasingDocumentRankScorer copy()
           
 double score()
          Returns a score for the current document of the last document iterator given to Scorer.wrap(DocumentIterator).
 double score(Index index)
          Returns a score for the current document of the last document iterator given to Scorer.wrap(DocumentIterator), but considering only a given index (optional operation).
 String toString()
           
 boolean usesIntervals()
          Whether this scorer uses intervals.
 void wrap(DocumentIterator documentIterator)
          Wraps the given document iterator.
 
Methods inherited from class it.unimi.di.mg4j.search.score.AbstractScorer
getWeights, nextDocument, setWeights
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface it.unimi.di.mg4j.search.score.Scorer
getWeights, nextDocument, setWeights
 

Constructor Detail

DecreasingDocumentRankScorer

public DecreasingDocumentRankScorer(String filename)
                             throws IOException
Builds a document scorer by first reading the ranks from a file. Ranks are saved as doubles (the first double is the rank of document 0 and so on).

Parameters:
filename - the name of the rank file.
Throws:
IOException

DecreasingDocumentRankScorer

public DecreasingDocumentRankScorer(double[] score)
Builds a document scorer with given scores.

Parameters:
score - the scores (they are not copied, so the caller is supposed not to change their values).
Method Detail

copy

public DecreasingDocumentRankScorer copy()
Specified by:
copy in interface DelegatingScorer
Specified by:
copy in interface Scorer
Specified by:
copy in interface FlyweightPrototype<Scorer>

score

public double score()
Description copied from interface: Scorer
Returns a score for the current document of the last document iterator given to Scorer.wrap(DocumentIterator).

Specified by:
score in interface Scorer
Returns:
the score.

score

public double score(Index index)
Description copied from interface: Scorer
Returns a score for the current document of the last document iterator given to Scorer.wrap(DocumentIterator), but considering only a given index (optional operation).

Specified by:
score in interface Scorer
Parameters:
index - the only index to be considered.
Returns:
the score.

wrap

public void wrap(DocumentIterator documentIterator)
          throws IOException
Description copied from class: AbstractScorer
Wraps the given document iterator.

This method records internally the provided iterator.

Specified by:
wrap in interface Scorer
Overrides:
wrap in class AbstractScorer
Parameters:
documentIterator - the document iterator that will be used in subsequent calls to Scorer.score() and Scorer.score(Index).
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

usesIntervals

public boolean usesIntervals()
Description copied from interface: Scorer
Whether this scorer uses intervals.

This method is essential when aggregating scorers, because if several scores need intervals, a CachingDocumentIterator will be necessary.

Specified by:
usesIntervals in interface Scorer
Returns:
true if this scorer uses intervals.