use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.
the class Lightfield 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) {
/* Perform search for each extracted feature and adjust scores. */
HashMap<String, DistanceElement> map = new HashMap<>();
for (DistanceElement result : partialResults) {
map.merge(result.getId(), result, (v1, v2) -> {
if (v1.getDistance() < v2.getDistance()) {
return v1;
} else {
return v2;
}
});
}
/* Add results to list and return list of results. */
final CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.correspondence);
return ScoreElement.filterMaximumScores(map.entrySet().stream().map((e) -> e.getValue().toScore(correspondence)));
}
use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.
the class StagedFeatureModule method getSimilar.
/**
* This method executes a similarity query based on an existing segment. The query is executed in three stages (hence the name of the class):
*
* <ol>
* <li>Lookup: Retrieving the features associated with the provided segment ID.</li>
* <li>Similarity search: Performing the similarity query in the underlying storage engine.</li>
* <li>Post-processing: Aggregating the query results into the final Score elements.</li>
* </ol>
* <p>
* Even though it is possible to re-implement this method, it is not recommended. Instead, try to override
* the methods that represent the different stages.
*
* @param segmentId ID of the segment that is used as example.
* @param qc QueryConfiguration
* @return List of results
*/
@Override
public List<ScoreElement> getSimilar(String segmentId, ReadableQueryConfig qc) {
/* Load default query-config. */
QueryConfig qcc = this.defaultQueryConfig(qc);
/* Lookup features. */
List<float[]> features = this.selector.getFeatureVectors(GENERIC_ID_COLUMN_QUALIFIER, new StringTypeProvider(segmentId), FEATURE_COLUMN_QUALIFIER);
if (features.isEmpty()) {
LOGGER.warn("No features could be fetched for the provided segmentId '{}'. Aborting query execution...", segmentId);
return new ArrayList<>(0);
}
/* Generate a list of QueryConfigs for the feature. */
List<ReadableQueryConfig> configs = this.generateQueryConfigsForFeatures(qcc, features);
/* Start query lookup phase. */
List<SegmentDistanceElement> partialResults = this.lookup(features, configs);
/* Start query-results post-processing phase. */
return this.postprocessQuery(partialResults, qcc);
}
use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.
the class StagedFeatureModule method getSimilar.
/**
* This method executes a regular similarity query based on a provided SegmentContainer. The query is executed in three stages (hence the name of the class):
*
* <ol>
* <li>Pre-processing: Extracting features from the SegmentContainer.</li>
* <li>Similarity search: Performing the similarity query in the underlying storage engine.</li>
* <li>Post-processing: Aggregating the query results into the final Score elements.</li>
* </ol>
* <p>
* Even though it is possible to re-implement this method, it is not recommended. Instead, try to override
* the methods that represent the different stages.
*
* @param sc SegmentContainer to base the query on.
* @param qc QueryConfiguration
* @return List of results
*/
@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {
/* Load default query-config. */
QueryConfig qcc = this.defaultQueryConfig(qc);
/* Extract features. */
List<float[]> features = this.preprocessQuery(sc, qcc);
if (features == null || features.isEmpty()) {
LOGGER.warn("No features could be generated from the provided query. Aborting query execution...");
return new ArrayList<>(0);
}
/* Generates a list of QueryConfigs for the feature. */
List<ReadableQueryConfig> configs = this.generateQueryConfigsForFeatures(qcc, features);
/* Start query lookup phase. */
List<SegmentDistanceElement> partialResults = this.lookup(features, configs);
return this.postprocessQuery(partialResults, qcc);
}
Aggregations