|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.unimi.di.mg4j.query.IntervalSelector
public class IntervalSelector
A strategy for selecting reasonable intervals to be shown to the user.
MG4J returns for each query and each document a list of minimal intervals satisfying the query. Due to overlaps and long intervals, this list is not always the best way to show the result of a query to the user. Instances of this class select intervals using two parameters (maximum number of intervals and maximum interval length) and the following algorithm: intervals enqueued in a queue ordered by length; then, they are extracted from the queue and added greedily to the result set as long as they do not overlap any other interval already in the result set, they are not longer than the maximum length, and the result set contains less intervals than the maximum allowed.
If all intervals are longer than the maximum allowed length, then from the shorter interval we extract two new intervals long as half of the maximum allowed length and sharing the left and right extreme, respectively, with the original interval.
Warning: implementations of this class are not required
to be thread-safe, but they provide flyweight copies
(actually, just copies, as no internal state is shared, but we implement the interface for consistency
with the rest of the components used by a QueryEngine
).
The copy()
method is strengthened so to return an object implementing this interface.
Constructor Summary | |
---|---|
IntervalSelector()
Creates a new selector that selects all intervals. |
|
IntervalSelector(int maxIntervals,
int intervalMaxLength)
Creates a new selector. |
Method Summary | |
---|---|
IntervalSelector |
copy()
|
Reference2ObjectMap<Index,SelectedInterval[]> |
select(DocumentIterator documentIterator,
Reference2ObjectMap<Index,SelectedInterval[]> index2Interval)
Selects intervals from a document iterator. |
SelectedInterval[] |
select(IntervalIterator intervalIterator)
Selects intervals from an interval iterator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IntervalSelector()
public IntervalSelector(int maxIntervals, int intervalMaxLength)
maxIntervals
- the maximum number of intervals returned by the selector.intervalMaxLength
- the maximum length of an interval returned by the selector.Method Detail |
---|
public IntervalSelector copy()
copy
in interface FlyweightPrototype<IntervalSelector>
public SelectedInterval[] select(IntervalIterator intervalIterator) throws IOException
intervalIterator
- an iterator returning intervals.
SelectedInterval.TRUE_ARRAY
and SelectedInterval.FALSE_ARRAY
are returned for IntervalIterators.TRUE
and IntervalIterators.FALSE
, respectively.
IOException
public Reference2ObjectMap<Index,SelectedInterval[]> select(DocumentIterator documentIterator, Reference2ObjectMap<Index,SelectedInterval[]> index2Interval) throws IOException
Intervals will be gathered using the interval iterators returned by the document iterator for the current document.
documentIterator
- a document iterator positioned over a document, with
callable DocumentIterator.intervalIterator(Index)
methods for all indices.index2Interval
- a map that will be cleared and fill with associations from
indices to arrays of selected intervals; the special empty arrays SelectedInterval.TRUE_ARRAY
and SelectedInterval.FALSE_ARRAY
are returned for IntervalIterators.TRUE
and IntervalIterators.FALSE
, respectively.
index2Interval
.
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |