use of org.vitrivr.cineast.core.data.distance.SegmentDistanceElement in project cineast by vitrivr.
the class MFCCShingle method postprocessQuery.
/**
* This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of ScoreElements is returned by the feature module during retrieval.
*
* @param partialResults List of partial results returned by the lookup stage.
* @param qc A ReadableQueryConfig object that contains query-related configuration parameters.
* @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
*/
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
/* Prepare helper data-structures. */
final List<ScoreElement> results = new ArrayList<>();
final TObjectIntHashMap<String> scoreMap = new TObjectIntHashMap<>();
/* Set QueryConfig and extract correspondence function. */
qc = this.setQueryConfig(qc);
final CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.correspondence);
for (DistanceElement hit : partialResults) {
if (hit.getDistance() < this.distanceThreshold) {
scoreMap.adjustOrPutValue(hit.getId(), 1, scoreMap.get(hit.getId()) / 2);
}
}
/* Prepare final result-set. */
scoreMap.forEachEntry((key, value) -> results.add(new SegmentScoreElement(key, 1.0 - 1.0 / value)));
ScoreElement.filterMaximumScores(results.stream());
return results;
}
use of org.vitrivr.cineast.core.data.distance.SegmentDistanceElement in project cineast by vitrivr.
the class CLIPText method getSimilar.
private List<ScoreElement> getSimilar(PrimitiveTypeProvider queryProvider, ReadableQueryConfig qc) {
ReadableQueryConfig qcc = QueryConfig.clone(qc).setDistance(DISTANCE);
List<SegmentDistanceElement> distances = this.selector.getNearestNeighboursGeneric(qc.getResultsPerModule(), queryProvider, FEATURE_COLUMN_QUALIFIER, SegmentDistanceElement.class, qcc);
CorrespondenceFunction function = qcc.getCorrespondenceFunction().orElse(CORRESPONDENCE);
return DistanceElement.toScore(distances, function);
}
use of org.vitrivr.cineast.core.data.distance.SegmentDistanceElement in project cineast by vitrivr.
the class AbstractFeatureModule method getSimilar.
/**
* Helper function to retrieve elements close to a generic primitive type
*/
protected List<ScoreElement> getSimilar(PrimitiveTypeProvider queryProvider, ReadableQueryConfig qc) {
ReadableQueryConfig qcc = setQueryConfig(qc);
List<SegmentDistanceElement> distances = this.selector.getNearestNeighboursGeneric(qc.getResultsPerModule(), queryProvider, FEATURE_COLUMN_QUALIFIER, SegmentDistanceElement.class, qcc);
CorrespondenceFunction function = qcc.getCorrespondenceFunction().orElse(correspondence);
return DistanceElement.toScore(distances, function);
}
use of org.vitrivr.cineast.core.data.distance.SegmentDistanceElement in project cineast by vitrivr.
the class MetadataFeatureModule method getSimilar.
protected List<ScoreElement> getSimilar(float[] feature, ReadableQueryConfig rqc) {
QueryConfig qc = QueryConfig.clone(rqc).setDistanceIfEmpty(this.defaultDistance());
List<SegmentDistanceElement> sDistances = new ArrayList<>();
List<ObjectDistanceElement> oDistances = new ArrayList<>();
CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.defaultCorrespondence());
if (this.segmentRetrievalScope) {
sDistances = this.dbSelector.getNearestNeighboursGeneric(rqc.getResultsPerModule(), feature, FEATURE_COLUMN_NAME, SegmentDistanceElement.class, qc);
return DistanceElement.toScore(sDistances, correspondence);
} else {
oDistances = this.dbSelector.getNearestNeighboursGeneric(rqc.getResultsPerModule(), feature, FEATURE_COLUMN_NAME, ObjectDistanceElement.class, qc);
return DistanceElement.toScore(oDistances, correspondence);
}
}
use of org.vitrivr.cineast.core.data.distance.SegmentDistanceElement in project cineast by vitrivr.
the class MotionHistogramCalculator method getSimilar.
protected List<ScoreElement> getSimilar(float[] vector, ReadableQueryConfig qc) {
ReadableQueryConfig qcc = setQueryConfig(qc);
List<SegmentDistanceElement> distances = this.selector.getNearestNeighboursGeneric(qcc.getResultsPerModule(), vector, this.fieldName, SegmentDistanceElement.class, qcc);
return DistanceElement.toScore(distances, qcc.getCorrespondenceFunction().get());
}
Aggregations