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());
}
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());
}
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);
}
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;
}
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);
}
}
Aggregations