Search in sources :

Example 1 with ConstrainedQueryConfig

use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.

the class FindSegmentSimilarStagedPostHandler method performPost.

@Override
public SimilarityQueryResultBatch performPost(StagedSimilarityQuery query, Context ctx) {
    ConstrainedQueryConfig config = ConstrainedQueryConfig.getApplyingConfig(query.getConfig());
    var results = QueryUtil.findSegmentsSimilarStaged(continuousRetrievalLogic, query.getStages(), config);
    return new SimilarityQueryResultBatch(results, config.getQueryId().toString());
}
Also used : ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) SimilarityQueryResultBatch(org.vitrivr.cineast.api.messages.result.SimilarityQueryResultBatch)

Example 2 with ConstrainedQueryConfig

use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.

the class CliUtils method retrieveAndLog.

public static void retrieveAndLog(List<Retriever> retrievers, ContinuousRetrievalLogic retrieval, int limit, boolean printDetail, AbstractQueryTermContainer qc) {
    System.out.println("Only printing the first " + limit + " results, change with --limit parameter");
    DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
    retrievers.forEach(retriever -> {
        AtomicBoolean entityExists = new AtomicBoolean(true);
        retriever.getTableNames().forEach(table -> {
            if (!selector.existsEntity(table)) {
                System.out.println("Entity " + table + " does not exist");
                entityExists.set(false);
            }
        });
        if (!entityExists.get()) {
            System.out.println("Not retrieving for " + retriever.getClass().getSimpleName() + " because entity does not exist");
            return;
        }
        System.out.println("Retrieving for " + retriever.getClass().getSimpleName());
        long start = System.currentTimeMillis();
        List<SegmentScoreElement> results = retrieval.retrieveByRetriever(qc, retriever, new ConstrainedQueryConfig().setMaxResults(limit));
        long stop = System.currentTimeMillis();
        System.out.println("Results for " + retriever.getClass().getSimpleName() + ":, retrieved in " + (stop - start) + "ms");
        for (SegmentScoreElement e : results) {
            System.out.print(e.getSegmentId());
            System.out.print(": ");
            System.out.println(e.getScore());
            if (printDetail) {
                CliUtils.printInfoForSegment(e.getSegmentId(), selector, null, true);
            }
        }
        System.out.println();
    });
    retrieval.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) SegmentScoreElement(org.vitrivr.cineast.core.data.score.SegmentScoreElement) DBSelector(org.vitrivr.cineast.core.db.DBSelector)

Example 3 with ConstrainedQueryConfig

use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.

the class AbstractQueryMessageHandler method handle.

/**
 * Handles a {@link Query} message
 *
 * @param session WebSocketSession for which the message arrived.
 * @param message Message of type a that needs to be handled.
 */
public final void handle(Session session, T message) {
    if (message == null) {
        LOGGER.warn("Received null message. Ignoring.");
        return;
    }
    try {
        final QueryConfig qconf = new ConstrainedQueryConfig(message.getQueryConfig());
        final String uuid = qconf.getQueryId().toString();
        final int max = Math.min(qconf.getMaxResults().orElse(Config.sharedConfig().getRetriever().getMaxResults()), Config.sharedConfig().getRetriever().getMaxResults());
        qconf.setMaxResults(max);
        final int resultsPerModule = Math.min(qconf.getRawResultsPerModule() == -1 ? Config.sharedConfig().getRetriever().getMaxResultsPerModule() : qconf.getResultsPerModule(), Config.sharedConfig().getRetriever().getMaxResultsPerModule());
        qconf.setResultsPerModule(resultsPerModule);
        String qid = uuid.substring(0, 3);
        Thread.currentThread().setName("query-msg-handler-" + uuid.substring(0, 3));
        try {
            /* Begin of Query: Send QueryStart Message to Client.
         *  We could wait for future-completion here, but there will likely never be a case where a simple write would fall behind the first message we send to the client.
         * Additionally, QR_START is informational - the client already knows that they sent a request.
         */
            this.write(session, new QueryStart(uuid));
            /* Execute actual query. */
            LOGGER.trace("Executing query with id {} from message {}", qid, message);
            final Set<String> segmentIdsForWhichMetadataIsFetched = new HashSet<>();
            final Set<String> objectIdsForWhichMetadataIsFetched = new HashSet<>();
            this.execute(session, qconf, message, segmentIdsForWhichMetadataIsFetched, objectIdsForWhichMetadataIsFetched);
        } catch (Exception e) {
            /* Error: Send QueryError Message to Client. */
            LOGGER.error("An exception occurred during execution of similarity query message {}.", LogHelper.getStackTrace(e));
            this.write(session, new QueryError(uuid, e.getMessage()));
            return;
        }
        /* End of Query: Send QueryEnd Message to Client. */
        this.write(session, new QueryEnd(uuid));
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) QueryEnd(org.vitrivr.cineast.api.messages.result.QueryEnd) QueryStart(org.vitrivr.cineast.api.messages.result.QueryStart) QueryError(org.vitrivr.cineast.api.messages.result.QueryError) HashSet(java.util.HashSet)

Example 4 with ConstrainedQueryConfig

use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.

the class FindSegmentSimilarPostHandler method performPost.

@Override
public SimilarityQueryResultBatch performPost(SimilarityQuery query, Context ctx) {
    ConstrainedQueryConfig config = ConstrainedQueryConfig.getApplyingConfig(query.getQueryConfig());
    var returnMap = QueryUtil.findSegmentsSimilar(continuousRetrievalLogic, query.getTerms(), config);
    return new SimilarityQueryResultBatch(returnMap, config.getQueryId().toString());
}
Also used : ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) SimilarityQueryResultBatch(org.vitrivr.cineast.api.messages.result.SimilarityQueryResultBatch)

Example 5 with ConstrainedQueryConfig

use of org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig in project cineast by vitrivr.

the class FindSegmentSimilarTemporalPostHandler method performPost.

@Override
public TemporalQueryResult performPost(TemporalQuery query, Context ctx) {
    ConstrainedQueryConfig config = ConstrainedQueryConfig.getApplyingConfig(query.getQueryConfig());
    var temporalResults = QueryUtil.findSegmentsSimilarTemporal(continuousRetrievalLogic, query, config);
    return new TemporalQueryResult(config.getQueryId().toString(), temporalResults);
}
Also used : ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) TemporalQueryResult(org.vitrivr.cineast.api.messages.result.TemporalQueryResult)

Aggregations

ConstrainedQueryConfig (org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig)6 SimilarityQueryResultBatch (org.vitrivr.cineast.api.messages.result.SimilarityQueryResultBatch)2 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)2 SegmentScoreElement (org.vitrivr.cineast.core.data.score.SegmentScoreElement)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 QueryEnd (org.vitrivr.cineast.api.messages.result.QueryEnd)1 QueryError (org.vitrivr.cineast.api.messages.result.QueryError)1 QueryStart (org.vitrivr.cineast.api.messages.result.QueryStart)1 TemporalQueryResult (org.vitrivr.cineast.api.messages.result.TemporalQueryResult)1 DBSelector (org.vitrivr.cineast.core.db.DBSelector)1 RetrievalResultCSVExporter (org.vitrivr.cineast.standalone.listener.RetrievalResultCSVExporter)1 ContinuousRetrievalLogic (org.vitrivr.cineast.standalone.util.ContinuousRetrievalLogic)1