From f2bb24b07e5622b35e8311b8f4695df9bc12b9d1 Mon Sep 17 00:00:00 2001 From: Silvan Heller Date: Thu, 3 Mar 2022 16:41:42 +0100 Subject: [PATCH 1/4] adding temporal-query specific config which allows disabling temporal scoring for evaluation- and testing-purposes --- .../api/messages/query/TemporalQuery.java | 27 ++++----------- .../messages/query/TemporalQueryConfig.java | 34 +++++++++++++++++++ .../queries/TemporalQueryMessageHandler.java | 11 ++++++ 3 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java index 53f81ebf5..9794dbfe6 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java @@ -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; /** @@ -19,30 +16,16 @@ public class TemporalQuery extends Query { */ private final List queries; - /** - * List of time distances as floats that can be part of this {@link TemporalQuery}. - */ - private final List timeDistances; - - /** - * The max length of the temporal sequences as float that can be part of this {@link TemporalQuery}. - */ - private final Float maxLength; - private final List metadataAccessSpec; @JsonCreator public TemporalQuery( @JsonProperty(value = "queries", required = true) List queries, - @JsonProperty(value = "config", required = false) QueryConfig config, - @JsonProperty(value = "timeDistances", required = false) List timeDistances, - @JsonProperty(value = "maxLength", required = false) Float maxLength, + @JsonProperty(value = "config", required = false) TemporalQueryConfig config, @JsonProperty(value = "metadataAccessSpec", required = false) List metadataAccessSpec ) { super(config); this.queries = queries; - this.timeDistances = timeDistances == null ? new ArrayList<>() : timeDistances; - this.maxLength = maxLength == null ? Float.MAX_VALUE : maxLength; this.metadataAccessSpec = metadataAccessSpec; } @@ -61,7 +44,7 @@ public List getQueries() { * @return List */ public List getTimeDistances() { - return timeDistances; + return getTemporalQueryConfig().timeDistances; } /** @@ -70,7 +53,11 @@ public List getTimeDistances() { * @return Float */ public Float getMaxLength() { - return maxLength; + return getTemporalQueryConfig().maxLength; + } + + public TemporalQueryConfig getTemporalQueryConfig() { + return (TemporalQueryConfig) this.config; } public List getMetadataAccessSpec() { diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java new file mode 100644 index 000000000..d3d2e57e3 --- /dev/null +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java @@ -0,0 +1,34 @@ +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 timeDistances; + + /** + * The max length of the temporal sequences as float that can be part of this {@link TemporalQuery}. + */ + public final Float maxLength; + + public final boolean computeTemporalObjects; + + + public TemporalQueryConfig(@JsonProperty(value = "queryId", required = false) String queryId, + @JsonProperty(value = "hints", required = false) List hints, + @JsonProperty(value = "timeDistances", required = false) List 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 ? true : computeTemporalObjects; + } +} diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/websocket/handlers/queries/TemporalQueryMessageHandler.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/websocket/handlers/queries/TemporalQueryMessageHandler.java index 4afed8c98..862f0cf7f 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/websocket/handlers/queries/TemporalQueryMessageHandler.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/websocket/handlers/queries/TemporalQueryMessageHandler.java @@ -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 */ @@ -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 metadataRetrievalThreads, List cleanupThreads) throws InterruptedException { for (Thread cleanupThread : cleanupThreads) { cleanupThread.join(); } From f14a922feed2cd17238aa8b0e9eee7bdc44c8eb0 Mon Sep 17 00:00:00 2001 From: Florian Spiess Date: Thu, 3 Mar 2022 16:58:14 +0100 Subject: [PATCH 2/4] Simplified expression. --- .../vitrivr/cineast/api/messages/query/TemporalQueryConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java index d3d2e57e3..eb2b6c19c 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java @@ -29,6 +29,6 @@ public TemporalQueryConfig(@JsonProperty(value = "queryId", required = false) St super(queryId, hints); this.timeDistances = timeDistances == null ? new ArrayList<>() : timeDistances; this.maxLength = maxLength == null ? Float.MAX_VALUE : maxLength; - this.computeTemporalObjects = computeTemporalObjects == null ? true : computeTemporalObjects; + this.computeTemporalObjects = computeTemporalObjects == null || computeTemporalObjects; } } From f2c3384d4da99129b738598cbbf271c4e192b5dd Mon Sep 17 00:00:00 2001 From: Silvan Heller Date: Thu, 3 Mar 2022 17:18:27 +0100 Subject: [PATCH 3/4] adding documentation --- .../cineast/api/messages/query/TemporalQueryConfig.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java index eb2b6c19c..1f338cabb 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQueryConfig.java @@ -17,6 +17,9 @@ public class TemporalQueryConfig extends QueryConfig { */ 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; From a65fc0012f1a12a9e01d8cf3912db23f918ec4cb Mon Sep 17 00:00:00 2001 From: silvanheller Date: Fri, 4 Mar 2022 09:06:51 +0100 Subject: [PATCH 4/4] merge --- .../org/vitrivr/cineast/api/messages/query/TemporalQuery.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java index b3c04f432..19b188433 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/messages/query/TemporalQuery.java @@ -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; /**