it.unimi.dsi.mg4j.search.visitor
Class CounterSetupVisitor

java.lang.Object
  extended by it.unimi.dsi.mg4j.search.visitor.AbstractDocumentIteratorVisitor
      extended by it.unimi.dsi.mg4j.search.visitor.CounterSetupVisitor
All Implemented Interfaces:
DocumentIteratorVisitor

public class CounterSetupVisitor
extends AbstractDocumentIteratorVisitor

A visitor using the information collected by a TermCollectionVisitor to set up term frequencies and counters.

Term frequencies and counts are stored in publicly accessible parallel arrays of integers indexed by offsets, as defined by a TermCollectionVisitor provided at construction time. Additionally, the index number (a position into the array returned by TermCollectionVisitor.indices()) and the term for each offset are available.

When instances of this class perform a visit, they prepare the arrays and fill those contaning frequencies and index numbers. It is up to an instance of CounterCollectionVisitor (which requires an instance of this class in its constructor) to fill the counts with data related to the current document.

For a more complete picture, see CounterCollectionVisitor.


Field Summary
 int[] count
          For each offset, its count.
 int[] frequency
          For each offset, its frequency.
 int[] indexNumber
          For each offset, the corresponding index as a position in TermCollectionVisitor.indices().
 CharSequence[] term
          For each offset, the corresponding term.
 
Constructor Summary
CounterSetupVisitor(TermCollectionVisitor termCollectionVisitor)
          Creates a new counter-setup visitor based on a given term-collection visitor.
 
Method Summary
 void clear()
          Zeroes all counters, but not frequencies.
 CounterSetupVisitor prepare()
          Prepares the internal state of this visitor using data from the associated TermCollectionVisitor.
 String toString()
           
 void update(IndexIterator indexIterator)
          Updates the count using the provided index iterator.
 boolean visit(IndexIterator indexIterator)
          Visits a leaf.
 
Methods inherited from class it.unimi.dsi.mg4j.search.visitor.AbstractDocumentIteratorVisitor
visitPost, visitPre
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

indexNumber

public int[] indexNumber
For each offset, the corresponding index as a position in TermCollectionVisitor.indices().


term

public CharSequence[] term
For each offset, the corresponding term.


count

public int[] count
For each offset, its count.


frequency

public int[] frequency
For each offset, its frequency.

Constructor Detail

CounterSetupVisitor

public CounterSetupVisitor(TermCollectionVisitor termCollectionVisitor)
Creates a new counter-setup visitor based on a given term-collection visitor.

Parameters:
termCollectionVisitor - a term-collection visitor.
Method Detail

prepare

public CounterSetupVisitor prepare()
Prepares the internal state of this visitor using data from the associated TermCollectionVisitor.

Note that because of this dependency, it is essential that you first prepare and visit with the associated TermCollectionVisitor, and then prepare and visit with this visitor.

Specified by:
prepare in interface DocumentIteratorVisitor
Overrides:
prepare in class AbstractDocumentIteratorVisitor
Returns:
this visitor.

visit

public boolean visit(IndexIterator indexIterator)
              throws IOException
Description copied from interface: DocumentIteratorVisitor
Visits a leaf.

Parameters:
indexIterator - the leaf to be visited.
Returns:
true if the visit should continue.
Throws:
IOException

update

public void update(IndexIterator indexIterator)
            throws IOException
Updates the count using the provided index iterator.

This method is usually called back by a CounterCollectionVisitor built upon this counter-setup visitor. It simply retrieves the index iterator id and use it as an index into count to store IndexIterator.count().

Parameters:
indexIterator - an index iterator.
Throws:
IOException

clear

public void clear()
Zeroes all counters, but not frequencies.


toString

public String toString()
Overrides:
toString in class Object