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

java.lang.Object
  extended by it.unimi.di.mg4j.search.visitor.AbstractDocumentIteratorVisitor
      extended by it.unimi.di.mg4j.search.visitor.CounterSetupVisitor
All Implemented Interfaces:
DocumentIteratorVisitor<Boolean>

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().
 String[] offset2Term
          For each offset, the corresponding term.
 int[] offset2TermId
          For each offset, its term id.
 String[] termId2Term
          For each term id, 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 an IndexIterator leaf.
 
Methods inherited from class it.unimi.di.mg4j.search.visitor.AbstractDocumentIteratorVisitor
newArray, visit, visit, visit, 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().


offset2Term

public String[] offset2Term
For each offset, the corresponding term.


count

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


frequency

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


offset2TermId

public int[] offset2TermId
For each offset, its term id.


termId2Term

public String[] termId2Term
For each term id, the corresponding term.

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<Boolean>
Overrides:
prepare in class AbstractDocumentIteratorVisitor
Returns:
this visitor.

visit

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

Parameters:
indexIterator - the leaf to be visited.
Returns:
an appropriate return value if the visit should continue, or null.
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