Search in sources :

Example 11 with ReadableQueryConfig

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

Example 12 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class SubDivMotionHistogram method getSimilar.

@Override
protected List<ScoreElement> getSimilar(float[] vector, ReadableQueryConfig qc) {
    ReadableQueryConfig rqc = setQueryConfig(qc);
    List<SegmentDistanceElement> distances = this.selector.getNearestNeighboursGeneric(qc.getResultsPerModule(), vector, "hist", SegmentDistanceElement.class, qc);
    return DistanceElement.toScore(distances, rqc.getCorrespondenceFunction().get());
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) SegmentDistanceElement(org.vitrivr.cineast.core.data.distance.SegmentDistanceElement)

Example 13 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class VisualTextCoEmbedding method getSimilar.

@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {
    String text = sc.getText();
    // Ensure the correct distance function is used
    QueryConfig queryConfig = QueryConfig.clone(qc);
    queryConfig.setDistance(DISTANCE);
    float[] embeddingArray = embedText(text);
    return getSimilar(embeddingArray, queryConfig);
}
Also used : QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) TString(org.tensorflow.types.TString)

Example 14 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class QueryUtil method retrieveCategory.

public static List<StringDoublePair> retrieveCategory(ContinuousRetrievalLogic continuousRetrievalLogic, List<Pair<AbstractQueryTermContainer, ReadableQueryConfig>> queryContainers, String category) {
    TObjectDoubleHashMap<String> scoreBySegmentId = new TObjectDoubleHashMap<>();
    for (Pair<AbstractQueryTermContainer, ReadableQueryConfig> pair : queryContainers) {
        if (pair == null) {
            continue;
        }
        AbstractQueryTermContainer qc = pair.first;
        ReadableQueryConfig qconf = pair.second;
        float weight = MathHelper.limit(qc.getWeight(), -1f, 1f);
        retrieveAndWeight(continuousRetrievalLogic, category, scoreBySegmentId, qc, qconf, weight);
    }
    final List<StringDoublePair> list = new ArrayList<>(scoreBySegmentId.size());
    scoreBySegmentId.forEachEntry((segmentId, score) -> {
        if (score > 0) {
            list.add(new StringDoublePair(segmentId, score));
        }
        return true;
    });
    list.sort(StringDoublePair.COMPARATOR);
    // FIXME: Using an arbitrary query config to limit results is prone to errors
    final int MAX_RESULTS = queryContainers.get(0).second.getMaxResults().orElse(Config.sharedConfig().getRetriever().getMaxResults());
    List<StringDoublePair> resultList = list;
    if (list.size() > MAX_RESULTS) {
        resultList = resultList.subList(0, MAX_RESULTS);
    }
    return resultList;
}
Also used : ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) StringDoublePair(org.vitrivr.cineast.core.data.StringDoublePair) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) AbstractQueryTermContainer(org.vitrivr.cineast.core.data.query.containers.AbstractQueryTermContainer) ArrayList(java.util.ArrayList)

Example 15 with ReadableQueryConfig

use of org.vitrivr.cineast.core.config.ReadableQueryConfig in project cineast by vitrivr.

the class CottontailSelector method getRowsAND.

@Override
public List<Map<String, PrimitiveTypeProvider>> getRowsAND(List<Triple<String, RelationalOperator, List<PrimitiveTypeProvider>>> conditions, String identifier, List<String> projection, ReadableQueryConfig qc) {
    /* Prepare plain query. */
    final Query query = new Query(this.fqn);
    if (projection.isEmpty()) {
        query.select("*", null);
    } else {
        for (String p : projection) {
            query.select(p, null);
        }
    }
    /* Process predicates. */
    final List<Predicate> atomics = conditions.stream().map(c -> {
        final String op = toOperator(c.getMiddle());
        return new Literal(c.getLeft(), op, c.getRight().stream().map(PrimitiveTypeProvider::toObject).toArray());
    }).collect(Collectors.toList());
    /*  */
    final Optional<Predicate> predicates = atomics.stream().reduce(And::new);
    if (qc != null && !qc.getRelevantSegmentIds().isEmpty()) {
        final Set<String> relevant = qc.getRelevantSegmentIds();
        final Literal segmentIds = new Literal(GENERIC_ID_COLUMN_QUALIFIER, "IN", relevant.toArray());
        if (predicates.isPresent()) {
            query.where(new And(segmentIds, predicates.get()));
        } else {
            query.where(segmentIds);
        }
    } else {
        predicates.ifPresent(query::where);
    }
    try {
        return processResults(this.cottontail.client.query(query));
    } catch (StatusRuntimeException e) {
        LOGGER.warn("Error occurred during query execution in getRowsAND(): {}", e.getMessage());
        return new ArrayList<>(0);
    }
}
Also used : Arrays(java.util.Arrays) Tuple(org.vitrivr.cottontail.client.iterators.Tuple) DB_DISTANCE_VALUE_QUALIFIER(org.vitrivr.cineast.core.util.CineastConstants.DB_DISTANCE_VALUE_QUALIFIER) GENERIC_ID_COLUMN_QUALIFIER(org.vitrivr.cineast.core.util.CineastConstants.GENERIC_ID_COLUMN_QUALIFIER) DBSelector(org.vitrivr.cineast.core.db.DBSelector) HashMap(java.util.HashMap) KEY_COL_NAME(org.vitrivr.cineast.core.util.CineastConstants.KEY_COL_NAME) Query(org.vitrivr.cottontail.client.language.dql.Query) TupleIterator(org.vitrivr.cottontail.client.iterators.TupleIterator) ArrayList(java.util.ArrayList) Code(io.grpc.Status.Code) Or(org.vitrivr.cottontail.client.language.extensions.Or) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) Literal(org.vitrivr.cottontail.client.language.extensions.Literal) LinkedList(java.util.LinkedList) Predicate(org.vitrivr.cottontail.client.language.extensions.Predicate) DOMAIN_COL_NAME(org.vitrivr.cineast.core.util.CineastConstants.DOMAIN_COL_NAME) Triple(org.apache.commons.lang3.tuple.Triple) And(org.vitrivr.cottontail.client.language.extensions.And) Collection(java.util.Collection) Set(java.util.Set) RelationalOperator(org.vitrivr.cineast.core.db.RelationalOperator) MetadataAccessSpecification(org.vitrivr.cineast.core.db.dao.MetadataAccessSpecification) StopWatch(org.apache.commons.lang3.time.StopWatch) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) Collectors(java.util.stream.Collectors) StatusRuntimeException(io.grpc.StatusRuntimeException) TimeUnit(java.util.concurrent.TimeUnit) Distances(org.vitrivr.cottontail.client.language.basics.Distances) List(java.util.List) AboutEntity(org.vitrivr.cottontail.client.language.ddl.AboutEntity) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider) Optional(java.util.Optional) Distance(org.vitrivr.cineast.core.config.ReadableQueryConfig.Distance) DistanceElement(org.vitrivr.cineast.core.data.distance.DistanceElement) Direction(org.vitrivr.cottontail.client.language.basics.Direction) Query(org.vitrivr.cottontail.client.language.dql.Query) And(org.vitrivr.cottontail.client.language.extensions.And) Literal(org.vitrivr.cottontail.client.language.extensions.Literal) StatusRuntimeException(io.grpc.StatusRuntimeException) Predicate(org.vitrivr.cottontail.client.language.extensions.Predicate)

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