Class CounterSetupVisitor
- java.lang.Object
-
- it.unimi.di.big.mg4j.search.visitor.AbstractDocumentIteratorVisitor
-
- it.unimi.di.big.mg4j.search.visitor.CounterSetupVisitor
-
- All Implemented Interfaces:
DocumentIteratorVisitor<Boolean>
public class CounterSetupVisitor extends AbstractDocumentIteratorVisitor
A visitor using the information collected by aTermCollectionVisitorto 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
TermCollectionVisitorprovided at construction time. Additionally, the index number (a position into the array returned byTermCollectionVisitor.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
Fields Modifier and Type Field Description int[]countFor each offset, its count.long[]frequencyFor each offset, its frequency.int[]indexNumberFor each offset, the corresponding index as a position inTermCollectionVisitor.indices().String[]offset2TermFor each offset, the corresponding term.int[]offset2TermIdFor each offset, its term id.String[]termId2TermFor each term id, the corresponding term.
-
Constructor Summary
Constructors Constructor Description CounterSetupVisitor(TermCollectionVisitor termCollectionVisitor)Creates a new counter-setup visitor based on a given term-collection visitor.
-
Method Summary
Modifier and Type Method Description voidclear()Zeroes all counters, but not frequencies.CounterSetupVisitorprepare()Prepares the internal state of this visitor using data from the associatedTermCollectionVisitor.StringtoString()voidupdate(IndexIterator indexIterator)Updates thecountusing the provided index iterator.Booleanvisit(IndexIterator indexIterator)Visits anIndexIteratorleaf.
-
-
-
Field Detail
-
indexNumber
public int[] indexNumber
For each offset, the corresponding index as a position inTermCollectionVisitor.indices().
-
offset2Term
public String[] offset2Term
For each offset, the corresponding term.
-
count
public int[] count
For each offset, its count.
-
frequency
public long[] 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 associatedTermCollectionVisitor.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:
preparein interfaceDocumentIteratorVisitor<Boolean>- Overrides:
preparein classAbstractDocumentIteratorVisitor- Returns:
- this visitor.
-
visit
public Boolean visit(IndexIterator indexIterator) throws IOException
Description copied from interface:DocumentIteratorVisitorVisits anIndexIteratorleaf.- 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 thecountusing the provided index iterator.This method is usually called back by a
CounterCollectionVisitorbuilt upon this counter-setup visitor. It simply retrieves the index iterator id and use it as an index intocountto storeIndexIterator.count().- Parameters:
indexIterator- an index iterator.- Throws:
IOException
-
clear
public void clear()
Zeroes all counters, but not frequencies.
-
-