Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal Query Config #272

Merged
merged 5 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
import kotlin.collections.ArrayDeque;
import org.vitrivr.cineast.api.messages.interfaces.MessageType;
import org.vitrivr.cineast.core.config.QueryConfig;
import org.vitrivr.cineast.core.db.dao.MetadataAccessSpecification;

/**
Expand All @@ -19,16 +16,6 @@ public class TemporalQuery extends Query {
*/
private final List<StagedSimilarityQuery> queries;

/**
* List of time distances as floats that can be part of this {@link TemporalQuery}.
*/
private final List<Float> timeDistances;

/**
* The max length of the temporal sequences as float that can be part of this {@link TemporalQuery}.
*/
private final Float maxLength;

/**
* Provide an empty list to fetch no metadata at all. If the field is not filled (i.e. null), all metadata is provided for backwards-compatibility
*/
Expand All @@ -37,15 +24,11 @@ public class TemporalQuery extends Query {
@JsonCreator
public TemporalQuery(
@JsonProperty(value = "queries", required = true) List<StagedSimilarityQuery> queries,
@JsonProperty(value = "config", required = false) QueryConfig config,
@JsonProperty(value = "timeDistances", required = false) List<Float> timeDistances,
@JsonProperty(value = "maxLength", required = false) Float maxLength,
@JsonProperty(value = "config", required = false) TemporalQueryConfig config,
@JsonProperty(value = "metadataAccessSpec", required = false) List<MetadataAccessSpecification> metadataAccessSpec
) {
super(config);
this.queries = queries;
this.timeDistances = timeDistances == null ? new ArrayList<>() : timeDistances;
this.maxLength = maxLength == null ? Float.MAX_VALUE : maxLength;
this.metadataAccessSpec = metadataAccessSpec;
}

Expand All @@ -64,7 +47,7 @@ public List<StagedSimilarityQuery> getQueries() {
* @return List<Float>
*/
public List<Float> getTimeDistances() {
return timeDistances;
return getTemporalQueryConfig().timeDistances;
}

/**
Expand All @@ -73,7 +56,11 @@ public List<Float> getTimeDistances() {
* @return Float
*/
public Float getMaxLength() {
return maxLength;
return getTemporalQueryConfig().maxLength;
}

public TemporalQueryConfig getTemporalQueryConfig() {
return (TemporalQueryConfig) this.config;
}

public List<MetadataAccessSpecification> getMetadataAccessSpec() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.vitrivr.cineast.api.messages.query;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
import org.vitrivr.cineast.core.config.QueryConfig;

public class TemporalQueryConfig extends QueryConfig {

/**
* List of time distances as floats that can be part of this {@link TemporalQuery}.
*/
public final List<Float> timeDistances;

/**
* The max length of the temporal sequences as float that can be part of this {@link TemporalQuery}.
*/
public final Float maxLength;

/**
* If set explicitly to false, there will be no temporal aggregation for the temporal queries. This is mainly done for testing or evaluation purposes.
*/
public final boolean computeTemporalObjects;
silvanheller marked this conversation as resolved.
Show resolved Hide resolved


public TemporalQueryConfig(@JsonProperty(value = "queryId", required = false) String queryId,
@JsonProperty(value = "hints", required = false) List<Hints> hints,
@JsonProperty(value = "timeDistances", required = false) List<Float> timeDistances,
@JsonProperty(value = "maxLength", required = false) Float maxLength,
@JsonProperty(value = "computeTemporalObjects", required = false) Boolean computeTemporalObjects
) {
super(queryId, hints);
this.timeDistances = timeDistances == null ? new ArrayList<>() : timeDistances;
this.maxLength = maxLength == null ? Float.MAX_VALUE : maxLength;
this.computeTemporalObjects = computeTemporalObjects == null || computeTemporalObjects;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ public void execute(Session session, QueryConfig qconf, TemporalQuery message, S
ssqThread.join();
}

/* You can skip the computation of temporal objects in the config if you wish simply to execute all queries independently (e.g. for evaluation)*/
if (!message.getTemporalQueryConfig().computeTemporalObjects) {
LOGGER.debug("Not computing temporal objects due to query config");
finish(metadataRetrievalThreads, cleanupThreads);
return;
}

LOGGER.debug("Starting fusion for temporal context");
long start = System.currentTimeMillis();
/* Retrieve the MediaSegmentDescriptors needed for the temporal scoring retrieval */
Expand Down Expand Up @@ -256,6 +263,10 @@ public void execute(Session session, QueryConfig qconf, TemporalQuery message, S
futures.forEach(CompletableFuture::join);
}

finish(metadataRetrievalThreads, cleanupThreads);
}

private void finish(List<Thread> metadataRetrievalThreads, List<Thread> cleanupThreads) throws InterruptedException {
for (Thread cleanupThread : cleanupThreads) {
cleanupThread.join();
}
Expand Down