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 aTermCollectionVisitor
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 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[]
count
For each offset, its count.long[]
frequency
For each offset, its frequency.int[]
indexNumber
For each offset, the corresponding index as a position inTermCollectionVisitor.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
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 void
clear()
Zeroes all counters, but not frequencies.CounterSetupVisitor
prepare()
Prepares the internal state of this visitor using data from the associatedTermCollectionVisitor
.String
toString()
void
update(IndexIterator indexIterator)
Updates thecount
using the provided index iterator.Boolean
visit(IndexIterator indexIterator)
Visits anIndexIterator
leaf.
-
-
-
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:
prepare
in interfaceDocumentIteratorVisitor<Boolean>
- Overrides:
prepare
in classAbstractDocumentIteratorVisitor
- Returns:
- this visitor.
-
visit
public Boolean visit(IndexIterator indexIterator) throws IOException
Description copied from interface:DocumentIteratorVisitor
Visits anIndexIterator
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 thecount
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 intocount
to storeIndexIterator.count()
.- Parameters:
indexIterator
- an index iterator.- Throws:
IOException
-
clear
public void clear()
Zeroes all counters, but not frequencies.
-
-