Search in sources :

Example 26 with ReadableQueryConfig

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)));
}
Also used : StagedFeatureModule(org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) ReadableMesh(org.vitrivr.cineast.core.data.m3d.ReadableMesh) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) FloatVectorImpl(org.vitrivr.cineast.core.data.FloatVectorImpl) HashMap(java.util.HashMap) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) JOGLOffscreenRenderer(org.vitrivr.cineast.core.render.JOGLOffscreenRenderer) ArrayList(java.util.ArrayList) ImageUtil(com.twelvemonkeys.image.ImageUtil) List(java.util.List) SegmentContainer(org.vitrivr.cineast.core.data.segments.SegmentContainer) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) LogHelper(org.vitrivr.cineast.core.util.LogHelper) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) Renderer(org.vitrivr.cineast.core.render.Renderer) HashMap(java.util.HashMap) CorrespondenceFunction(org.vitrivr.cineast.core.data.CorrespondenceFunction) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement)

Example 27 with ReadableQueryConfig

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);
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) ArrayList(java.util.ArrayList) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 28 with ReadableQueryConfig

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);
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) ArrayList(java.util.ArrayList) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Aggregations

ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)28 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)17 ArrayList (java.util.ArrayList)16 SegmentDistanceElement (org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)11 CorrespondenceFunction (org.vitrivr.cineast.core.data.CorrespondenceFunction)8 List (java.util.List)7 ScoreElement (org.vitrivr.cineast.core.data.score.ScoreElement)7 HashMap (java.util.HashMap)6 DistanceElement (org.vitrivr.cineast.core.data.distance.DistanceElement)5 FloatVectorImpl (org.vitrivr.cineast.core.data.FloatVectorImpl)4 SegmentContainer (org.vitrivr.cineast.core.data.segments.SegmentContainer)4 StagedFeatureModule (org.vitrivr.cineast.core.features.abstracts.StagedFeatureModule)4 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Pair (org.vitrivr.cineast.core.data.Pair)3 HPCP (org.vitrivr.cineast.core.util.audio.HPCP)3 FFTUtil (org.vitrivr.cineast.core.util.dsp.fft.FFTUtil)3 STFT (org.vitrivr.cineast.core.util.dsp.fft.STFT)3 HanningWindow (org.vitrivr.cineast.core.util.dsp.fft.windows.HanningWindow)3 MathHelper (org.vitrivr.cineast.core.util.math.MathHelper)3