Skip to content

Commit

Permalink
Temporal Query Config (#272)
Browse files Browse the repository at this point in the history
* adding temporal-query specific config which allows disabling temporal scoring for evaluation- and testing-purposes

Co-authored-by: Florian Spiess <[email protected]>
Former-commit-id: c1bd1ef
  • Loading branch information
silvanheller and Spiess authored Mar 4, 2022
1 parent 7597ee7 commit 9a042d2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
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;


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

0 comments on commit 9a042d2

Please sign in to comment.