summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-02-17 16:32:51 +0100
committerJon Bratseth <bratseth@oath.com>2018-02-17 16:32:51 +0100
commitd7e1e3b5b24b0f9f0e3dfcc6d1e37d442f1de4e8 (patch)
tree6520dc0340d605bba01bfbd7e3c9d3fd59bd4f5a /searchlib
parent80f0982ad44485879cc98aeb6e7bde3bd6b3bbb3 (diff)
Static type check reference parameters
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java5
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java3
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java5
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java7
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java15
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java11
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/rule/ArgumentsTestCase.java4
7 files changed, 23 insertions, 27 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
index 486affe9371..ee5952d9aea 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
@@ -2,6 +2,7 @@
package com.yahoo.searchlib.rankingexpression.evaluation;
import com.yahoo.searchlib.rankingexpression.RankingExpression;
+import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.tensor.TensorType;
import java.util.Arrays;
@@ -82,8 +83,8 @@ public class ArrayContext extends AbstractArrayContext implements Cloneable {
}
@Override
- public TensorType getType(Name name) {
- Integer index = nameToIndex().get(name.toString());
+ public TensorType getType(Reference reference) {
+ Integer index = nameToIndex().get(reference.toString());
if (index == null) return null;
return values[index].type();
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java
index 9779e01bf51..4102d4078e6 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.evaluation;
+import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.searchlib.rankingexpression.rule.Arguments;
import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
import com.yahoo.tensor.Tensor;
@@ -14,7 +15,7 @@ import java.util.stream.Collectors;
*
* @author bratseth
*/
-public abstract class Context implements EvaluationContext {
+public abstract class Context implements EvaluationContext<Reference> {
/**
* Returns the value of a simple variable name.
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java
index 01b8bffe995..0004036da4b 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java
@@ -2,6 +2,7 @@
package com.yahoo.searchlib.rankingexpression.evaluation;
import com.yahoo.searchlib.rankingexpression.RankingExpression;
+import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.tensor.TensorType;
/**
@@ -68,7 +69,9 @@ public class DoubleOnlyArrayContext extends AbstractArrayContext {
}
@Override
- public TensorType getType(Name name) { return TensorType.empty; }
+ public TensorType getType(Reference reference) {
+ return TensorType.empty; // Double only
+ }
/** Perform a slow lookup by name */
@Override
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java
index c7679ea9e55..4ef24d60bba 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.evaluation;
+import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.tensor.TensorType;
import java.util.Collections;
@@ -15,7 +16,7 @@ import java.util.Set;
*/
public class MapContext extends Context {
- private Map<String, Value> bindings = new HashMap<>();
+ private Map<String, Value> bindings = new HashMap<>(); // TODO: Change String to Reference
private boolean frozen = false;
@@ -42,8 +43,8 @@ public class MapContext extends Context {
/** Returns the type of the given value key, or null if it is not bound. */
@Override
- public TensorType getType(Name key) {
- Value value = bindings.get(key);
+ public TensorType getType(Reference key) {
+ Value value = bindings.get(key.toString());
if (value == null) return null;
return value.type();
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java
index 4ce7dd561e2..985878cfd66 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java
@@ -1,6 +1,7 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.evaluation;// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.evaluation.TypeContext;
@@ -13,20 +14,20 @@ import java.util.Map;
*
* @author bratseth
*/
-public class MapTypeContext implements TypeContext {
+public class MapTypeContext implements TypeContext<Reference> {
- private final Map<Name, TensorType> featureTypes = new HashMap<>();
+ private final Map<Reference, TensorType> featureTypes = new HashMap<>();
- public void setType(Name name, TensorType type) {
- featureTypes.put(name, type);
+ public void setType(Reference reference, TensorType type) {
+ featureTypes.put(reference, type);
}
@Override
- public TensorType getType(Name name) {
- return featureTypes.get(name);
+ public TensorType getType(Reference reference) {
+ return featureTypes.get(reference);
}
/** Returns an unmodifiable map of the bindings in this */
- public Map<Name, TensorType> bindings() { return Collections.unmodifiableMap(featureTypes); }
+ public Map<Reference, TensorType> bindings() { return Collections.unmodifiableMap(featureTypes); }
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java
deleted file mode 100644
index 3807fbe2207..00000000000
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.rankingexpression.rule;
-
-import com.yahoo.tensor.TensorType;
-import com.yahoo.tensor.evaluation.TypeContext;
-
-public interface EvaluationTypeContext extends TypeContext {
-
- TensorType getType(String name, Arguments arguments, String output);
-
-}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/rule/ArgumentsTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/rule/ArgumentsTestCase.java
index 867331e99ce..303135888d8 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/rule/ArgumentsTestCase.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/rule/ArgumentsTestCase.java
@@ -9,13 +9,13 @@ import java.util.Collections;
import static org.junit.Assert.*;
/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ * @author Simon Thoresen
*/
public class ArgumentsTestCase {
@Test
public void requireThatAccessorsWork() {
- Arguments args = new Arguments(null);
+ Arguments args = new Arguments();
assertTrue(args.expressions().isEmpty());
args = new Arguments(Collections.<ExpressionNode>emptyList());