T
- the type of objects that the ranking function works withpublic class RankedSortedDistFunctionCollection<T extends AbstractObject> extends RankedSortedCollection
RankedSortedCollection
that uses a different distance
function to rank the objects.
Note that this collection can be used either during the query evaluation or as after the computation is done (i.e. as a post-ranking of the collection).
For the first mode of operation (query evaluation - set by rankInAdd = false
),
the new distance is computed only when a query-object distance is computed via
add(messif.operations.AnswerType, messif.objects.AbstractObject, float, float[])
.
The already computed data added via add
or addAll
methods are not touched, so that the lists
can be merged without recomputing the data.
For the second mode of operation (post-ranking - set by rankInAdd = true
), the
objects have their ranking recomputed when added to this collection by any add
method. To create a separate re-ranked list, create a new instance of this collection
with rankInAdd = true
and add all
objects from the original collection.
DEFAULT_INITIAL_CAPACITY, UNLIMITED_CAPACITY
Constructor and Description |
---|
RankedSortedDistFunctionCollection(DistanceFunction<? super T> rankingDistanceFunction,
T rankingObject,
float originalDistanceWeight)
Constructs an empty collection.
|
RankedSortedDistFunctionCollection(DistanceFunction<? super T> rankingDistanceFunction,
T rankingObject,
float originalDistanceWeight,
boolean rankInAdd)
Constructs an empty collection.
|
RankedSortedDistFunctionCollection(DistanceFunction<? super T> rankingDistanceFunction,
T rankingObject,
float originalDistanceWeight,
boolean rankInAdd,
int initialCapacity,
int maximalCapacity)
Constructs an empty collection with the specified initial and maximal capacity.
|
Modifier and Type | Method and Description |
---|---|
RankedAbstractObject |
add(AnswerType answerType,
AbstractObject object,
float distance,
float[] objectDistances)
Add a distance-ranked object to this collection.
|
boolean |
add(RankedAbstractObject obj)
Adds the specified element to this list.
|
protected boolean |
add(RankedAbstractObject obj,
boolean rankInAdd)
Adds the specified element to this list.
|
static RankedSortedDistFunctionCollection<LocalAbstractObject> |
create(LocalAbstractObject rankingObject,
float originalDistanceWeight,
boolean rankInAdd,
int initialCapacity,
int maximalCapacity)
Creates an empty collection with the specified initial and maximal capacity.
|
protected float |
getNewDistance(float origDistance,
T object)
Given the original distance and the object, this method returns the
new distance according to which the object should be ranked.
|
float |
getOriginalDistanceWeight()
Returns the weight of the original distance that is summed with the new distance to get the ranking.
|
DistanceFunction<? super T> |
getRankingDistanceFunction()
Returns the distance function used for the ranking.
|
T |
getRankingObject()
Returns the ranking object used as the first argument for the
getRankingDistanceFunction() . |
boolean |
isRankingInAdd()
Returns true if the
add method computes the rank or false,
if the ranked objects are added without additional computations. |
add, clear, isEqual, isIgnoringDuplicates, rankObject, remove, remove, removeFirst, removeLast, setIgnoringDuplicates, setMaximalCapacity, toArray, toArray
getLastDistance, getThresholdDistance, iteratorDistanceRestricted, iteratorDistanceRestricted
addAll, addAllSortedArray, clone, clone, compare, contains, containsAll, element, get, getComparator, getMaximalCapacity, isEmpty, isFull, iterator, iterator, offer, peek, poll, popLast, remove, removeAll, removeAll, removeFirstN, retainAll, size, toString
binarySearch, first, fullSearch, indexOf, last, mergeSort
public RankedSortedDistFunctionCollection(DistanceFunction<? super T> rankingDistanceFunction, T rankingObject, float originalDistanceWeight, boolean rankInAdd, int initialCapacity, int maximalCapacity) throws java.lang.IllegalArgumentException, java.lang.NullPointerException
rankInAddAll
should be set to false. If the collection is used as post-ranking,
the rankInAddAll
probably needs to be set to true, however
the correct type of objects must be present in the operation (i.e. the AnswerType
should be set to something above AnswerType.CLEARED_OBJECTS
.rankingDistanceFunction
- the distance function used for the ranking,
if null, the natural distance function of the ranking object will be usedrankingObject
- the object used for rankingoriginalDistanceWeight
- the weight of the original distance (if zero, the original distance is ignored)rankInAdd
- flag whether the add
method computes the rank (true) or adds the ranked objects as-is (false)initialCapacity
- the initial capacity of the collectionmaximalCapacity
- the maximal capacity of the collectionjava.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalid or the ranking distance function is not compatible with the ranking objectjava.lang.NullPointerException
- if both the ranking distance function and the ranking object are nullpublic RankedSortedDistFunctionCollection(DistanceFunction<? super T> rankingDistanceFunction, T rankingObject, float originalDistanceWeight, boolean rankInAdd)
rankingDistanceFunction
- the distance function used for the rankingrankingObject
- the object used for rankingoriginalDistanceWeight
- the weight of the original distance (if zero, the original distance is ignored)rankInAdd
- flag whether the add
method computes the rank (true) or adds the ranked objects as-is (false)public RankedSortedDistFunctionCollection(DistanceFunction<? super T> rankingDistanceFunction, T rankingObject, float originalDistanceWeight)
rankingDistanceFunction
- the distance function used for the rankingrankingObject
- the object used for rankingoriginalDistanceWeight
- the weight of the original distance (if zero, the original distance is ignored)public static RankedSortedDistFunctionCollection<LocalAbstractObject> create(LocalAbstractObject rankingObject, float originalDistanceWeight, boolean rankInAdd, int initialCapacity, int maximalCapacity) throws java.lang.IllegalArgumentException, java.lang.NullPointerException
rankingObject
is used to compute
the rank.rankingObject
- the object used for rankingoriginalDistanceWeight
- the weight of the original distance (if zero, the original distance is ignored)rankInAdd
- flag whether the add
method computes the rank (true) or adds the ranked objects as-is (false)initialCapacity
- the initial capacity of the collectionmaximalCapacity
- the maximal capacity of the collectionjava.lang.IllegalArgumentException
- if the specified initial or maximal capacity is invalidjava.lang.NullPointerException
- if the ranking object is nullpublic RankedAbstractObject add(AnswerType answerType, AbstractObject object, float distance, float[] objectDistances) throws java.lang.IllegalArgumentException
RankedAbstractMetaObject
if the given objectDistances
array is not null.add
in class RankedSortedCollection
answerType
- the type of the objects added to this collectionobject
- the object to adddistance
- the distance of objectobjectDistances
- the array of distances to the respective sub-objects (can be null)java.lang.IllegalArgumentException
- if the answer type of this operation requires cloning but the passed object cannot be cloned or the distance function requires a different classpublic final boolean add(RankedAbstractObject obj)
SortedCollection
add
in interface java.util.Collection<RankedAbstractObject>
add
in interface java.util.Queue<RankedAbstractObject>
add
in class RankedSortedCollection
obj
- element to be appended to this listprotected boolean add(RankedAbstractObject obj, boolean rankInAdd)
obj
- element to be appended to this listrankInAdd
- flag whether the rank of the added object is recomputed (true) or
the object is added as-is (false)public DistanceFunction<? super T> getRankingDistanceFunction()
public T getRankingObject()
getRankingDistanceFunction()
.getRankingDistanceFunction()
public float getOriginalDistanceWeight()
public boolean isRankingInAdd()
add
method computes the rank or false,
if the ranked objects are added without additional computations.add
method computes the rank or notprotected final float getNewDistance(float origDistance, T object)
origDistance
- original query-object distanceobject
- data object corresponding to this distance