aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/MapTypeContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/MapTypeContext.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/MapTypeContext.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/MapTypeContext.java b/config-model/src/main/java/com/yahoo/searchdefinition/MapTypeContext.java
new file mode 100644
index 00000000000..e0dc7a2f33c
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapTypeContext.java
@@ -0,0 +1,39 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition;
+
+import com.yahoo.tensor.TensorType;
+import com.yahoo.tensor.evaluation.TypeContext;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A context which only contains type information.
+ * This returns empty tensor types (double) for unknown features which are not
+ * query, attribute or constant features, as we do not have information about which such
+ * features exist (but we know those that exist are doubles).
+ *
+ * @author bratseth
+ */
+public class MapTypeContext implements TypeContext {
+
+ private final Map<String, TensorType> featureTypes = new HashMap<>();
+
+ public void setType(String name, TensorType type) {
+ featureTypes.put(FeatureNames.canonicalize(name), type);
+ }
+
+ @Override
+ public TensorType getType(String name) {
+ if (FeatureNames.isConstantFeature(name) ||
+ FeatureNames.isAttributeFeature(name) ||
+ FeatureNames.isQueryFeature(name))
+ return featureTypes.get(FeatureNames.canonicalize(name));
+ else
+ return TensorType.empty; // we do not have type information for these. Correct would be either empty or null
+ }
+
+ public Map<String, TensorType> bindings() { return Collections.unmodifiableMap(featureTypes); }
+
+}