aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/expression/DivideFunctionNode.java2
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/expression/Int16ResultNode.java2
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/expression/Int32ResultNode.java2
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/expression/Int8ResultNode.java2
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/expression/NumElemFunctionNode.java2
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/mlr/ga/KeyboardChecker.java2
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/ranking/features/fieldmatch/SegmentStartPoint.java2
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java276
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/FeatureList.java278
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EmbracedNode.java114
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/TruthOperator.java2
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/treenet/TreeNetConverter.java68
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/treenet/rule/ComparisonCondition.java76
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Response.java88
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/treenet/rule/SetMembershipCondition.java114
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Tree.java218
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNet.java124
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNode.java66
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/BiasEstimatorTest.java2
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/HyperLogLogEstimatorTest.java2
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/NormalSketchTest.java2
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SketchMergerTest.java2
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SparseSketchTest.java2
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/gbdt/TreeNodeTestCase.java2
-rwxr-xr-xsearchlib/src/test/java/com/yahoo/searchlib/rankingexpression/FeatureListTestCase.java152
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/Benchmark.java286
-rwxr-xr-xsearchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java156
-rw-r--r--searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp2
-rw-r--r--searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp2
-rw-r--r--searchlib/src/tests/diskindex/fusion/fusion_test.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/changevector.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/datastore/datastore.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/engine/propertiesmap.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h2
-rw-r--r--searchlib/src/vespa/searchlib/test/statestring.h2
-rw-r--r--searchlib/src/vespa/searchlib/util/url.h2
38 files changed, 1033 insertions, 1033 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/expression/DivideFunctionNode.java b/searchlib/src/main/java/com/yahoo/searchlib/expression/DivideFunctionNode.java
index c7ff00a9e78..0a7b36cfd71 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/expression/DivideFunctionNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/expression/DivideFunctionNode.java
@@ -20,4 +20,4 @@ public class DivideFunctionNode extends NumericFunctionNode {
protected void onArgument(final ResultNode arg, ResultNode result) {
((NumericResultNode)result).divide(arg);
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/expression/Int16ResultNode.java b/searchlib/src/main/java/com/yahoo/searchlib/expression/Int16ResultNode.java
index 4a636bb8a3f..804b6a52c5b 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/expression/Int16ResultNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/expression/Int16ResultNode.java
@@ -146,4 +146,4 @@ public class Int16ResultNode extends NumericResultNode {
public void set(ResultNode rhs) {
value = (short)rhs.getInteger();
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/expression/Int32ResultNode.java b/searchlib/src/main/java/com/yahoo/searchlib/expression/Int32ResultNode.java
index 0316ee2d9c3..9a03df015b8 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/expression/Int32ResultNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/expression/Int32ResultNode.java
@@ -146,4 +146,4 @@ public class Int32ResultNode extends NumericResultNode {
public void set(ResultNode rhs) {
value = (int)rhs.getInteger();
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/expression/Int8ResultNode.java b/searchlib/src/main/java/com/yahoo/searchlib/expression/Int8ResultNode.java
index 0bbc3414c2e..d21473b9be8 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/expression/Int8ResultNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/expression/Int8ResultNode.java
@@ -146,4 +146,4 @@ public class Int8ResultNode extends NumericResultNode {
public void set(ResultNode rhs) {
value = (byte)rhs.getInteger();
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/expression/NumElemFunctionNode.java b/searchlib/src/main/java/com/yahoo/searchlib/expression/NumElemFunctionNode.java
index 102c598402a..c7897afd514 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/expression/NumElemFunctionNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/expression/NumElemFunctionNode.java
@@ -47,4 +47,4 @@ public class NumElemFunctionNode extends UnaryFunctionNode {
protected boolean equalsUnaryFunction(UnaryFunctionNode obj) {
return true;
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/mlr/ga/KeyboardChecker.java b/searchlib/src/main/java/com/yahoo/searchlib/mlr/ga/KeyboardChecker.java
index 091990ffdc5..6d47b2dfd7a 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/mlr/ga/KeyboardChecker.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/mlr/ga/KeyboardChecker.java
@@ -47,4 +47,4 @@ public class KeyboardChecker {
}
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/ranking/features/fieldmatch/SegmentStartPoint.java b/searchlib/src/main/java/com/yahoo/searchlib/ranking/features/fieldmatch/SegmentStartPoint.java
index c7331a0b5b6..15e458dea70 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/ranking/features/fieldmatch/SegmentStartPoint.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/ranking/features/fieldmatch/SegmentStartPoint.java
@@ -142,4 +142,4 @@ final class SegmentStartPoint {
" (" + (open ? "open" : "closed") + ")";
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java
index 86ac53a1e44..7e5033844a3 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java
@@ -1,139 +1,139 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.rankingexpression;
-
-import com.google.common.collect.ImmutableList;
-import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
-import com.yahoo.searchlib.rankingexpression.rule.SerializationContext;
-import com.yahoo.text.Utf8;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.*;
-
-/**
- * <p>A function defined by a ranking expression</p>
- *
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- * @author bratseth
- */
-public class ExpressionFunction {
-
- private final String name;
- private final ImmutableList<String> arguments;
- private final RankingExpression body;
-
- /**
- * <p>Constructs a new function</p>
- *
- * @param name the name of this function
- * @param arguments its argument names
- * @param body the ranking expression that defines this function
- */
- public ExpressionFunction(String name, List<String> arguments, RankingExpression body) {
- this.name = name;
- this.arguments = arguments==null ? ImmutableList.of() : ImmutableList.copyOf(arguments);
- this.body = body;
- }
-
- public String getName() { return name; }
-
- /** Returns an immutable list of the arguments of this */
- public List<String> arguments() { return arguments; }
-
- public RankingExpression getBody() { return body; }
-
- /**
- * <p>Create and return an instance of this function based on the given
- * arguments. If function calls are nested, this call might produce
- * additional scripts.</p>
- *
- * @param context the context used to expand this
- * @param arguments the arguments to instantiate on.
- * @param path the expansion path leading to this.
- * @return the script function instance created.
- */
- public Instance expand(SerializationContext context, List<ExpressionNode> arguments, Deque<String> path) {
- Map<String, String> argumentBindings = new HashMap<>();
- for (int i = 0; i < this.arguments.size() && i < arguments.size(); ++i) {
- argumentBindings.put(this.arguments.get(i), arguments.get(i).toString(context, path, null));
- }
- return new Instance(toSymbol(argumentBindings), body.getRoot().toString(context.createBinding(argumentBindings), path, null));
- }
-
- /**
- * Returns a symbolic string that represents this function with a given
- * list of arguments. The arguments are mangled by hashing the string
- * representation of the argument expressions, so we might need to revisit
- * this if we start seeing collisions.
- *
- * @param argumentBindings the bound arguments to include in the symbolic name.
- * @return the symbolic name for an instance of this function
- */
- private String toSymbol(Map<String, String> argumentBindings) {
- if (argumentBindings.isEmpty()) return name;
-
- StringBuilder ret = new StringBuilder();
- ret.append(name).append("@");
- for (Map.Entry<String,String> argumentBinding : argumentBindings.entrySet()) {
- ret.append(Long.toHexString(symbolCode(argumentBinding.getKey() + "=" + argumentBinding.getValue())));
- ret.append(".");
- }
- if (ret.toString().endsWith("."))
- ret.setLength(ret.length()-1);
- return ret.toString();
- }
-
-
- /**
- * <p>Returns a more unique hash code than what Java's own {@link
- * String#hashCode()} method would produce.</p>
- *
- * @param str The string to hash.
- * @return A 64 bit long hash code.
- */
- private static long symbolCode(String str) {
- try {
- MessageDigest md = java.security.MessageDigest.getInstance("SHA-1");
- byte[] buf = md.digest(Utf8.toBytes(str));
- if (buf.length >= 8) {
- long ret = 0;
- for (int i = 0; i < 8; ++i) {
- ret = (ret << 8) + (buf[i] & 0xff);
- }
- return ret;
- }
- } catch (NoSuchAlgorithmException e) {
- throw new Error("java must always support SHA-1 message digest format", e);
- }
- return str.hashCode();
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- /**
- * An instance of a serialization of this function, using a particular serialization context (by {@link
- * ExpressionFunction#expand})
- */
- public class Instance {
-
- private final String name;
- private final String expressionString;
-
- public Instance(String name, String expressionString) {
- this.name = name;
- this.expressionString = expressionString;
- }
-
- public String getName() {
- return name;
- }
-
- public String getExpressionString() {
- return expressionString;
- }
-
- }
-}
+package com.yahoo.searchlib.rankingexpression;
+
+import com.google.common.collect.ImmutableList;
+import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
+import com.yahoo.searchlib.rankingexpression.rule.SerializationContext;
+import com.yahoo.text.Utf8;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+
+/**
+ * <p>A function defined by a ranking expression</p>
+ *
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ * @author bratseth
+ */
+public class ExpressionFunction {
+
+ private final String name;
+ private final ImmutableList<String> arguments;
+ private final RankingExpression body;
+
+ /**
+ * <p>Constructs a new function</p>
+ *
+ * @param name the name of this function
+ * @param arguments its argument names
+ * @param body the ranking expression that defines this function
+ */
+ public ExpressionFunction(String name, List<String> arguments, RankingExpression body) {
+ this.name = name;
+ this.arguments = arguments==null ? ImmutableList.of() : ImmutableList.copyOf(arguments);
+ this.body = body;
+ }
+
+ public String getName() { return name; }
+
+ /** Returns an immutable list of the arguments of this */
+ public List<String> arguments() { return arguments; }
+
+ public RankingExpression getBody() { return body; }
+
+ /**
+ * <p>Create and return an instance of this function based on the given
+ * arguments. If function calls are nested, this call might produce
+ * additional scripts.</p>
+ *
+ * @param context the context used to expand this
+ * @param arguments the arguments to instantiate on.
+ * @param path the expansion path leading to this.
+ * @return the script function instance created.
+ */
+ public Instance expand(SerializationContext context, List<ExpressionNode> arguments, Deque<String> path) {
+ Map<String, String> argumentBindings = new HashMap<>();
+ for (int i = 0; i < this.arguments.size() && i < arguments.size(); ++i) {
+ argumentBindings.put(this.arguments.get(i), arguments.get(i).toString(context, path, null));
+ }
+ return new Instance(toSymbol(argumentBindings), body.getRoot().toString(context.createBinding(argumentBindings), path, null));
+ }
+
+ /**
+ * Returns a symbolic string that represents this function with a given
+ * list of arguments. The arguments are mangled by hashing the string
+ * representation of the argument expressions, so we might need to revisit
+ * this if we start seeing collisions.
+ *
+ * @param argumentBindings the bound arguments to include in the symbolic name.
+ * @return the symbolic name for an instance of this function
+ */
+ private String toSymbol(Map<String, String> argumentBindings) {
+ if (argumentBindings.isEmpty()) return name;
+
+ StringBuilder ret = new StringBuilder();
+ ret.append(name).append("@");
+ for (Map.Entry<String,String> argumentBinding : argumentBindings.entrySet()) {
+ ret.append(Long.toHexString(symbolCode(argumentBinding.getKey() + "=" + argumentBinding.getValue())));
+ ret.append(".");
+ }
+ if (ret.toString().endsWith("."))
+ ret.setLength(ret.length()-1);
+ return ret.toString();
+ }
+
+
+ /**
+ * <p>Returns a more unique hash code than what Java's own {@link
+ * String#hashCode()} method would produce.</p>
+ *
+ * @param str The string to hash.
+ * @return A 64 bit long hash code.
+ */
+ private static long symbolCode(String str) {
+ try {
+ MessageDigest md = java.security.MessageDigest.getInstance("SHA-1");
+ byte[] buf = md.digest(Utf8.toBytes(str));
+ if (buf.length >= 8) {
+ long ret = 0;
+ for (int i = 0; i < 8; ++i) {
+ ret = (ret << 8) + (buf[i] & 0xff);
+ }
+ return ret;
+ }
+ } catch (NoSuchAlgorithmException e) {
+ throw new Error("java must always support SHA-1 message digest format", e);
+ }
+ return str.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * An instance of a serialization of this function, using a particular serialization context (by {@link
+ * ExpressionFunction#expand})
+ */
+ public class Instance {
+
+ private final String name;
+ private final String expressionString;
+
+ public Instance(String name, String expressionString) {
+ this.name = name;
+ this.expressionString = expressionString;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getExpressionString() {
+ return expressionString;
+ }
+
+ }
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/FeatureList.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/FeatureList.java
index 527a908da73..c18a8c0e838 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/FeatureList.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/FeatureList.java
@@ -1,140 +1,140 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.rankingexpression;
-
-import com.google.common.annotations.Beta;
-import com.yahoo.searchlib.rankingexpression.parser.ParseException;
-import com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParser;
-import com.yahoo.searchlib.rankingexpression.parser.TokenMgrError;
-import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode;
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Encapsulates the production rule 'featureList()' int the RankingExpressionParser.
- *
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-@Beta
-public class FeatureList implements Iterable<ReferenceNode> {
-
- private final List<ReferenceNode> features = new ArrayList<>();
-
- /**
- * Creates a new feature list by consuming from a reader object.
- *
- * @param reader The reader that contains the string to parse.
- * @throws ParseException Thrown if the string could not be parsed.
- */
- public FeatureList(Reader reader) throws ParseException {
- features.addAll(parse(reader));
- }
-
- /**
- * Creates a new feature list by parsing a string.
- *
- * @param list The string to parse.
- * @throws ParseException Thrown if the string could not be parsed.
- */
- public FeatureList(String list) throws ParseException {
- features.addAll(parse(new StringReader(list)));
- }
-
- /**
- * Creates a new feature list by reading the content of a file.
- *
- * @param file The file whose content to parse.
- * @throws ParseException Thrown if the string could not be parsed.
- * @throws FileNotFoundException Thrown if the file specified could not be found.
- */
- public FeatureList(File file) throws ParseException, FileNotFoundException {
- features.addAll(parse(new FileReader(file)));
- }
-
- /**
- * Parses the content of a reader object as a list of feature nodes.
- *
- * @param reader A reader object that contains an feature list.
- * @return A list of those features named in the string.
- * @throws ParseException if the string could not be parsed.
- */
- private static List<ReferenceNode> parse(Reader reader) throws ParseException {
- List<ReferenceNode> lst;
- try {
- lst = new RankingExpressionParser(reader).featureList();
- }
- catch (TokenMgrError e) {
- ParseException t = new ParseException();
- throw (ParseException)t.initCause(e);
- }
- List<ReferenceNode> ret = new ArrayList<ReferenceNode>(lst.size());
- for (Object obj : lst) {
- if (!(obj instanceof ReferenceNode)) {
- throw new IllegalStateException("Feature list contains a " + obj.getClass().getName() + ".");
- }
- ret.add((ReferenceNode)obj);
- }
- return ret;
- }
-
- /**
- * Returns the number of features in this list.
- *
- * @return The size.
- */
- public int size() {
- return features.size();
- }
-
- /**
- * Returns the feature at the given index.
- *
- * @param i The index of the feature to return.
- * @return The featuer at the given index.
- */
- public ReferenceNode get(int i) {
- return features.get(i);
- }
-
- @Override
- public int hashCode() {
- int ret = 0;
- for (ReferenceNode node : features) {
- ret += node.hashCode() * 17;
- }
- return ret;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof FeatureList)) {
- return false;
- }
- FeatureList lst = (FeatureList)obj;
- if (features.size() != lst.features.size()) {
- return false;
- }
- for (int i = 0; i < features.size(); ++i) {
- if (!features.get(i).equals(lst.features.get(i))) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder ret = new StringBuilder();
- for (ReferenceNode node : this) {
- ret.append(node).append(" ");
- }
- return ret.toString();
- }
-
- @Override
- public Iterator<ReferenceNode> iterator() {
- return features.iterator();
- }
-}
+package com.yahoo.searchlib.rankingexpression;
+
+import com.google.common.annotations.Beta;
+import com.yahoo.searchlib.rankingexpression.parser.ParseException;
+import com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParser;
+import com.yahoo.searchlib.rankingexpression.parser.TokenMgrError;
+import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Encapsulates the production rule 'featureList()' int the RankingExpressionParser.
+ *
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+@Beta
+public class FeatureList implements Iterable<ReferenceNode> {
+
+ private final List<ReferenceNode> features = new ArrayList<>();
+
+ /**
+ * Creates a new feature list by consuming from a reader object.
+ *
+ * @param reader The reader that contains the string to parse.
+ * @throws ParseException Thrown if the string could not be parsed.
+ */
+ public FeatureList(Reader reader) throws ParseException {
+ features.addAll(parse(reader));
+ }
+
+ /**
+ * Creates a new feature list by parsing a string.
+ *
+ * @param list The string to parse.
+ * @throws ParseException Thrown if the string could not be parsed.
+ */
+ public FeatureList(String list) throws ParseException {
+ features.addAll(parse(new StringReader(list)));
+ }
+
+ /**
+ * Creates a new feature list by reading the content of a file.
+ *
+ * @param file The file whose content to parse.
+ * @throws ParseException Thrown if the string could not be parsed.
+ * @throws FileNotFoundException Thrown if the file specified could not be found.
+ */
+ public FeatureList(File file) throws ParseException, FileNotFoundException {
+ features.addAll(parse(new FileReader(file)));
+ }
+
+ /**
+ * Parses the content of a reader object as a list of feature nodes.
+ *
+ * @param reader A reader object that contains an feature list.
+ * @return A list of those features named in the string.
+ * @throws ParseException if the string could not be parsed.
+ */
+ private static List<ReferenceNode> parse(Reader reader) throws ParseException {
+ List<ReferenceNode> lst;
+ try {
+ lst = new RankingExpressionParser(reader).featureList();
+ }
+ catch (TokenMgrError e) {
+ ParseException t = new ParseException();
+ throw (ParseException)t.initCause(e);
+ }
+ List<ReferenceNode> ret = new ArrayList<ReferenceNode>(lst.size());
+ for (Object obj : lst) {
+ if (!(obj instanceof ReferenceNode)) {
+ throw new IllegalStateException("Feature list contains a " + obj.getClass().getName() + ".");
+ }
+ ret.add((ReferenceNode)obj);
+ }
+ return ret;
+ }
+
+ /**
+ * Returns the number of features in this list.
+ *
+ * @return The size.
+ */
+ public int size() {
+ return features.size();
+ }
+
+ /**
+ * Returns the feature at the given index.
+ *
+ * @param i The index of the feature to return.
+ * @return The featuer at the given index.
+ */
+ public ReferenceNode get(int i) {
+ return features.get(i);
+ }
+
+ @Override
+ public int hashCode() {
+ int ret = 0;
+ for (ReferenceNode node : features) {
+ ret += node.hashCode() * 17;
+ }
+ return ret;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof FeatureList)) {
+ return false;
+ }
+ FeatureList lst = (FeatureList)obj;
+ if (features.size() != lst.features.size()) {
+ return false;
+ }
+ for (int i = 0; i < features.size(); ++i) {
+ if (!features.get(i).equals(lst.features.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder ret = new StringBuilder();
+ for (ReferenceNode node : this) {
+ ret.append(node).append(" ");
+ }
+ return ret.toString();
+ }
+
+ @Override
+ public Iterator<ReferenceNode> iterator() {
+ return features.iterator();
+ }
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EmbracedNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EmbracedNode.java
index 49604f14ca2..fdb71bca2f5 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EmbracedNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EmbracedNode.java
@@ -1,57 +1,57 @@
-// Copyright 2016 Yahoo Inc. 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.searchlib.rankingexpression.evaluation.Context;
-import com.yahoo.searchlib.rankingexpression.evaluation.Value;
-
-import java.util.Collections;
-import java.util.Deque;
-import java.util.List;
-
-/**
- * This class represents another expression enclosed in braces.
- *
- * @author Simon Thoresen
- */
-public final class EmbracedNode extends CompositeNode {
-
- // The node to embrace.
- private final ExpressionNode value;
-
- /**
- * Creates a new expression node that embraces another.
- *
- * @param value The node to embrace.
- */
- public EmbracedNode(ExpressionNode value) {
- this.value=value;
- }
-
- /** Returns the node enclosed by this */
- public ExpressionNode getValue() { return value; }
-
- @Override
- public List<ExpressionNode> children() {
- return Collections.singletonList(value);
- }
-
- @Override
- public String toString(SerializationContext context, Deque<String> path, CompositeNode parent) {
- String expression = value.toString(context, path, this);
- if (value instanceof ReferenceNode) return expression;
- return "(" + expression + ")";
- }
-
- @Override
- public Value evaluate(Context context) {
- return value.evaluate(context);
- }
-
- @Override
- public CompositeNode setChildren(List<ExpressionNode> newChildren) {
- if (newChildren.size() != 1)
- throw new IllegalArgumentException("Expected 1 child but got " + newChildren.size());
- return new EmbracedNode(newChildren.get(0));
- }
-
-}
+// Copyright 2016 Yahoo Inc. 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.searchlib.rankingexpression.evaluation.Context;
+import com.yahoo.searchlib.rankingexpression.evaluation.Value;
+
+import java.util.Collections;
+import java.util.Deque;
+import java.util.List;
+
+/**
+ * This class represents another expression enclosed in braces.
+ *
+ * @author Simon Thoresen
+ */
+public final class EmbracedNode extends CompositeNode {
+
+ // The node to embrace.
+ private final ExpressionNode value;
+
+ /**
+ * Creates a new expression node that embraces another.
+ *
+ * @param value The node to embrace.
+ */
+ public EmbracedNode(ExpressionNode value) {
+ this.value=value;
+ }
+
+ /** Returns the node enclosed by this */
+ public ExpressionNode getValue() { return value; }
+
+ @Override
+ public List<ExpressionNode> children() {
+ return Collections.singletonList(value);
+ }
+
+ @Override
+ public String toString(SerializationContext context, Deque<String> path, CompositeNode parent) {
+ String expression = value.toString(context, path, this);
+ if (value instanceof ReferenceNode) return expression;
+ return "(" + expression + ")";
+ }
+
+ @Override
+ public Value evaluate(Context context) {
+ return value.evaluate(context);
+ }
+
+ @Override
+ public CompositeNode setChildren(List<ExpressionNode> newChildren) {
+ if (newChildren.size() != 1)
+ throw new IllegalArgumentException("Expected 1 child but got " + newChildren.size());
+ return new EmbracedNode(newChildren.get(0));
+ }
+
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/TruthOperator.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/TruthOperator.java
index 234825eaa3d..1b74326b168 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/TruthOperator.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/TruthOperator.java
@@ -47,4 +47,4 @@ public enum TruthOperator implements Serializable {
return x==y;
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/treenet/TreeNetConverter.java b/searchlib/src/main/java/com/yahoo/searchlib/treenet/TreeNetConverter.java
index c147c3a33b8..628cfc10a48 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/treenet/TreeNetConverter.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/treenet/TreeNetConverter.java
@@ -1,35 +1,35 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet;
-
-import com.yahoo.searchlib.treenet.parser.TreeNetParser;
-
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public class TreeNetConverter {
-
- /**
- * Implements an application main function so that the converter can be used as a command-line tool.
- *
- * @param args List of arguments.
- */
- public static void main(String[] args) {
- if (args.length != 1) {
- System.err.println("Usage: TreeNetConverter <filename>");
- System.exit(1);
- }
- try {
- TreeNetParser parser = new TreeNetParser(new FileReader(args[0]));
- System.out.println(parser.treeNet().toRankingExpression());
- } catch (FileNotFoundException e) {
- System.err.println("Could not find file '" + args[0] + "'.");
- System.exit(1);
- } catch (Exception e) {
- System.err.println("An error occured while parsing the content of file '" + args[0] + "': " + e);
- System.exit(1);
- }
- }
-}
+package com.yahoo.searchlib.treenet;
+
+import com.yahoo.searchlib.treenet.parser.TreeNetParser;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class TreeNetConverter {
+
+ /**
+ * Implements an application main function so that the converter can be used as a command-line tool.
+ *
+ * @param args List of arguments.
+ */
+ public static void main(String[] args) {
+ if (args.length != 1) {
+ System.err.println("Usage: TreeNetConverter <filename>");
+ System.exit(1);
+ }
+ try {
+ TreeNetParser parser = new TreeNetParser(new FileReader(args[0]));
+ System.out.println(parser.treeNet().toRankingExpression());
+ } catch (FileNotFoundException e) {
+ System.err.println("Could not find file '" + args[0] + "'.");
+ System.exit(1);
+ } catch (Exception e) {
+ System.err.println("An error occured while parsing the content of file '" + args[0] + "': " + e);
+ System.exit(1);
+ }
+ }
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/ComparisonCondition.java b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/ComparisonCondition.java
index 1855a8a5674..6c40406977b 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/ComparisonCondition.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/ComparisonCondition.java
@@ -1,39 +1,39 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet.rule;
-
-import com.yahoo.java7compat.Util;
-
-/**
- * Represents a condition which comparing two values
- *
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public class ComparisonCondition extends Condition {
-
- private final double rhs;
-
- /**
- * Constructs a new instance of this class.
- *
- * @param lhs The name of the feature to compare to a constant.
- * @param rhs The constant to compare the feature with.
- * @param ift The label to jump to if left &lt; right.
- * @param iff The label to jump to if left &gt;= right;
- */
- public ComparisonCondition(String lhs, double rhs, String ift, String iff) {
- super(lhs, ift, iff);
- this.rhs = rhs;
- }
-
- /**
- * Returns the constant to compare the feature with.
- *
- * @return The constant.
- */
- public double getConstant() { return rhs; }
-
- @Override
- public String conditionToRankingExpression() {
- return "< " + Util.toJava7String(rhs);
- }
-}
+package com.yahoo.searchlib.treenet.rule;
+
+import com.yahoo.java7compat.Util;
+
+/**
+ * Represents a condition which comparing two values
+ *
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class ComparisonCondition extends Condition {
+
+ private final double rhs;
+
+ /**
+ * Constructs a new instance of this class.
+ *
+ * @param lhs The name of the feature to compare to a constant.
+ * @param rhs The constant to compare the feature with.
+ * @param ift The label to jump to if left &lt; right.
+ * @param iff The label to jump to if left &gt;= right;
+ */
+ public ComparisonCondition(String lhs, double rhs, String ift, String iff) {
+ super(lhs, ift, iff);
+ this.rhs = rhs;
+ }
+
+ /**
+ * Returns the constant to compare the feature with.
+ *
+ * @return The constant.
+ */
+ public double getConstant() { return rhs; }
+
+ @Override
+ public String conditionToRankingExpression() {
+ return "< " + Util.toJava7String(rhs);
+ }
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Response.java b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Response.java
index 347dd84f419..9838cafcab3 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Response.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Response.java
@@ -1,45 +1,45 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet.rule;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public class Response extends TreeNode {
-
- // The id of the next tree to run after this.
- private final Double value;
-
- // The value of this response.
- private final String next;
-
- /**
- * Constructs a new response.
- *
- * @param next The id of the next tree to run after this.
- * @param value The value of this response.
- */
- public Response(Double value, String next) {
- super();
- this.value = value;
- this.next = next;
- }
-
- /**
- * Returns the value of this response.
- */
- public Double getValue() {
- return value;
- }
-
- /**
- * Returns the id of the next tree to run after this.
- */
- public String getNext() {
- return next;
- }
-
- @Override
- public String toRankingExpression() {
- return value.toString();
- }
-}
+package com.yahoo.searchlib.treenet.rule;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class Response extends TreeNode {
+
+ // The id of the next tree to run after this.
+ private final Double value;
+
+ // The value of this response.
+ private final String next;
+
+ /**
+ * Constructs a new response.
+ *
+ * @param next The id of the next tree to run after this.
+ * @param value The value of this response.
+ */
+ public Response(Double value, String next) {
+ super();
+ this.value = value;
+ this.next = next;
+ }
+
+ /**
+ * Returns the value of this response.
+ */
+ public Double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns the id of the next tree to run after this.
+ */
+ public String getNext() {
+ return next;
+ }
+
+ @Override
+ public String toRankingExpression() {
+ return value.toString();
+ }
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/SetMembershipCondition.java b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/SetMembershipCondition.java
index bb47947557c..a992d3b8032 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/SetMembershipCondition.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/SetMembershipCondition.java
@@ -1,57 +1,57 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet.rule;
-
-import com.yahoo.java7compat.Util;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Represents a set membership test on the form <code>feature IN (integer1, integer2 ...)</code>
- *
- * @author bratseth
- * @since 5.1.21
- */
-public class SetMembershipCondition extends Condition {
-
- private final List<Object> setValues;
-
- /**
- * Constructs a new instance of this class.
- *
- * @param testValue the name of the feature to test
- * @param setValues the set of values to compare to
- * @param trueLabel the label to jump to if the value is in the set
- * @param falseLabel the label to jumt to if the value is not in the set
- */
- public SetMembershipCondition(String testValue, List<Object> setValues, String trueLabel, String falseLabel) {
- super(testValue, trueLabel, falseLabel);
- this.setValues = Collections.unmodifiableList(new ArrayList<>(setValues));
- }
-
- /** Returns the unmodifiable set of values to check */
- public List<Object> getSetValues() { return setValues; }
-
- @Override
- protected String conditionToRankingExpression() {
- StringBuilder b = new StringBuilder("in [");
- for (Iterator<Object> i = setValues.iterator(); i.hasNext(); ) {
- Object value = i.next();
- if (value instanceof String)
- b.append("\"").append(value).append("\"");
- else if (value instanceof Integer)
- b.append(value);
- else
- throw new RuntimeException("Excepted a string or integer in a set membership test, not a " +
- value.getClass() + ": " + value);
-
- if (i.hasNext())
- b.append(",");
- }
- b.append("]");
- return b.toString();
- }
-
-}
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchlib.treenet.rule;
+
+import com.yahoo.java7compat.Util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Represents a set membership test on the form <code>feature IN (integer1, integer2 ...)</code>
+ *
+ * @author bratseth
+ * @since 5.1.21
+ */
+public class SetMembershipCondition extends Condition {
+
+ private final List<Object> setValues;
+
+ /**
+ * Constructs a new instance of this class.
+ *
+ * @param testValue the name of the feature to test
+ * @param setValues the set of values to compare to
+ * @param trueLabel the label to jump to if the value is in the set
+ * @param falseLabel the label to jumt to if the value is not in the set
+ */
+ public SetMembershipCondition(String testValue, List<Object> setValues, String trueLabel, String falseLabel) {
+ super(testValue, trueLabel, falseLabel);
+ this.setValues = Collections.unmodifiableList(new ArrayList<>(setValues));
+ }
+
+ /** Returns the unmodifiable set of values to check */
+ public List<Object> getSetValues() { return setValues; }
+
+ @Override
+ protected String conditionToRankingExpression() {
+ StringBuilder b = new StringBuilder("in [");
+ for (Iterator<Object> i = setValues.iterator(); i.hasNext(); ) {
+ Object value = i.next();
+ if (value instanceof String)
+ b.append("\"").append(value).append("\"");
+ else if (value instanceof Integer)
+ b.append(value);
+ else
+ throw new RuntimeException("Excepted a string or integer in a set membership test, not a " +
+ value.getClass() + ": " + value);
+
+ if (i.hasNext())
+ b.append(",");
+ }
+ b.append("]");
+ return b.toString();
+ }
+
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Tree.java b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Tree.java
index 2a7191baeba..6db319ebc6c 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Tree.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/Tree.java
@@ -1,110 +1,110 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet.rule;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public class Tree {
-
- private final String name;
-
- // The parent tree net of this.
- private TreeNet parent;
-
- // Returns the id of the next tree to run after this.
- private String next;
-
- // The initial response value of this tree, may be null.
- private final Double value;
-
- // The id of the first condition or response to run in this tree.
- private final String begin;
-
- // All named nodes of this tree.
- private final Map<String, TreeNode> nodes;
-
- /**
- * Constructs a new tree.
- *
- * @param name The name of this tree, used for error outputs.
- * @param value The initial response value of this tree, may be null.
- * @param begin The id of the first condition or response to run in this tree.
- * @param nodes All named nodes of this tree.
- */
- public Tree(String name, Double value, String begin, Map<String, TreeNode> nodes) {
- this.name = name;
- this.value = value;
- this.begin = begin;
- this.nodes = nodes;
-
- this.next = null;
- for (TreeNode node : this.nodes.values()) {
- node.setParent(this);
- if (node instanceof Response) {
- String next = ((Response)node).getNext();
- if (this.next == null) {
- this.next = next;
- } else if (!this.next.equals(next)) {
- throw new IllegalStateException("Not all child nodes of tree '" + name + "' agree on the next " +
- "tree to run. Initial name was '" + this.next + "', conflicting " +
- "name is '" + next + "'.");
- }
- }
- }
- }
-
- public String getName() { return name; }
-
- /**
- * Returns the parent tree net of this.
- */
- public TreeNet getParent() { return parent; }
-
- /**
- * Sets the parent tree net of this.
- *
- * @param parent The parent tree net.
- * @return This, to allow chaining.
- */
- public Tree setParent(TreeNet parent) {
- this.parent = parent;
- return this;
- }
-
- /**
- * Returns the id of the next tree to run after this.
- */
- public String getNext() {
- return next;
- }
-
- /**
- * Returns the initial response value of this tree, may be null.
- */
- public Double getValue() {
- return value;
- }
-
- /**
- * Returns the id of the first condition or response to run in this tree.
- */
- public String getBegin() {
- return begin;
- }
-
- /**
- * Returns all named nodes of this tree.
- */
- public Map<String, TreeNode> getNodes() {
- return nodes;
- }
-
- /**
- * Returns a ranking expression equivalent of this tree.
- */
- public String toRankingExpression() {
- return nodes.get(begin).toRankingExpression();
- }
-}
+package com.yahoo.searchlib.treenet.rule;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class Tree {
+
+ private final String name;
+
+ // The parent tree net of this.
+ private TreeNet parent;
+
+ // Returns the id of the next tree to run after this.
+ private String next;
+
+ // The initial response value of this tree, may be null.
+ private final Double value;
+
+ // The id of the first condition or response to run in this tree.
+ private final String begin;
+
+ // All named nodes of this tree.
+ private final Map<String, TreeNode> nodes;
+
+ /**
+ * Constructs a new tree.
+ *
+ * @param name The name of this tree, used for error outputs.
+ * @param value The initial response value of this tree, may be null.
+ * @param begin The id of the first condition or response to run in this tree.
+ * @param nodes All named nodes of this tree.
+ */
+ public Tree(String name, Double value, String begin, Map<String, TreeNode> nodes) {
+ this.name = name;
+ this.value = value;
+ this.begin = begin;
+ this.nodes = nodes;
+
+ this.next = null;
+ for (TreeNode node : this.nodes.values()) {
+ node.setParent(this);
+ if (node instanceof Response) {
+ String next = ((Response)node).getNext();
+ if (this.next == null) {
+ this.next = next;
+ } else if (!this.next.equals(next)) {
+ throw new IllegalStateException("Not all child nodes of tree '" + name + "' agree on the next " +
+ "tree to run. Initial name was '" + this.next + "', conflicting " +
+ "name is '" + next + "'.");
+ }
+ }
+ }
+ }
+
+ public String getName() { return name; }
+
+ /**
+ * Returns the parent tree net of this.
+ */
+ public TreeNet getParent() { return parent; }
+
+ /**
+ * Sets the parent tree net of this.
+ *
+ * @param parent The parent tree net.
+ * @return This, to allow chaining.
+ */
+ public Tree setParent(TreeNet parent) {
+ this.parent = parent;
+ return this;
+ }
+
+ /**
+ * Returns the id of the next tree to run after this.
+ */
+ public String getNext() {
+ return next;
+ }
+
+ /**
+ * Returns the initial response value of this tree, may be null.
+ */
+ public Double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns the id of the first condition or response to run in this tree.
+ */
+ public String getBegin() {
+ return begin;
+ }
+
+ /**
+ * Returns all named nodes of this tree.
+ */
+ public Map<String, TreeNode> getNodes() {
+ return nodes;
+ }
+
+ /**
+ * Returns a ranking expression equivalent of this tree.
+ */
+ public String toRankingExpression() {
+ return nodes.get(begin).toRankingExpression();
+ }
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNet.java b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNet.java
index 1db13b6c12e..47a2afad4d2 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNet.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNet.java
@@ -1,63 +1,63 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet.rule;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public class TreeNet {
-
- // The id of the first tree to run in this net.
- private String begin;
-
- // All named trees of this net.
- private final Map<String, Tree> trees;
-
- /**
- * Constructs a new tree net.
- *
- * @param begin The id of the first tree to run in this net.
- * @param trees All named trees of this net.
- */
- public TreeNet(String begin, Map<String, Tree> trees) {
- this.begin = begin;
- this.trees = trees;
- for (Tree tree : this.trees.values()) {
- tree.setParent(this);
- }
- }
-
- /**
- * Returns the id of the first tree to run in this net.
- */
- public String getBegin() {
- return begin;
- }
-
- /**
- * Returns all named trees of this net.
- */
- public Map<String, Tree> getTrees() {
- return trees;
- }
-
- /**
- * Returns a ranking expression equivalent of this net.
- */
- public String toRankingExpression() {
- StringBuilder ret = new StringBuilder();
- String next = begin;
- while (next != null) {
- Tree tree = trees.get(next);
- if (tree.getBegin() != null) {
- if (ret.length() > 0) {
- ret.append(" + \n");
- }
- ret.append(tree.toRankingExpression());
- }
- next = tree.getNext();
- }
- return ret.toString();
- }
-}
+package com.yahoo.searchlib.treenet.rule;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class TreeNet {
+
+ // The id of the first tree to run in this net.
+ private String begin;
+
+ // All named trees of this net.
+ private final Map<String, Tree> trees;
+
+ /**
+ * Constructs a new tree net.
+ *
+ * @param begin The id of the first tree to run in this net.
+ * @param trees All named trees of this net.
+ */
+ public TreeNet(String begin, Map<String, Tree> trees) {
+ this.begin = begin;
+ this.trees = trees;
+ for (Tree tree : this.trees.values()) {
+ tree.setParent(this);
+ }
+ }
+
+ /**
+ * Returns the id of the first tree to run in this net.
+ */
+ public String getBegin() {
+ return begin;
+ }
+
+ /**
+ * Returns all named trees of this net.
+ */
+ public Map<String, Tree> getTrees() {
+ return trees;
+ }
+
+ /**
+ * Returns a ranking expression equivalent of this net.
+ */
+ public String toRankingExpression() {
+ StringBuilder ret = new StringBuilder();
+ String next = begin;
+ while (next != null) {
+ Tree tree = trees.get(next);
+ if (tree.getBegin() != null) {
+ if (ret.length() > 0) {
+ ret.append(" + \n");
+ }
+ ret.append(tree.toRankingExpression());
+ }
+ next = tree.getNext();
+ }
+ return ret.toString();
+ }
+}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNode.java b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNode.java
index a637adafc73..178d6810193 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/TreeNode.java
@@ -1,34 +1,34 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet.rule;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public abstract class TreeNode {
-
- // The parent tree of this.
- private Tree parent = null;
-
- /**
- * Returns the parent tree of this.
- */
- public Tree getParent() {
- return parent;
- }
-
- /**
- * Sets the parent tree net of this.
- *
- * @param parent The parent tree net.
- * @return This, to allow chaining.
- */
- public TreeNode setParent(Tree parent) {
- this.parent = parent;
- return this;
- }
-
- /**
- * Returns a ranking expression equivalent of this net.
- */
- public abstract String toRankingExpression();
-}
+package com.yahoo.searchlib.treenet.rule;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public abstract class TreeNode {
+
+ // The parent tree of this.
+ private Tree parent = null;
+
+ /**
+ * Returns the parent tree of this.
+ */
+ public Tree getParent() {
+ return parent;
+ }
+
+ /**
+ * Sets the parent tree net of this.
+ *
+ * @param parent The parent tree net.
+ * @return This, to allow chaining.
+ */
+ public TreeNode setParent(Tree parent) {
+ this.parent = parent;
+ return this;
+ }
+
+ /**
+ * Returns a ranking expression equivalent of this net.
+ */
+ public abstract String toRankingExpression();
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/BiasEstimatorTest.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/BiasEstimatorTest.java
index 307214d8c1c..c9e510736c9 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/BiasEstimatorTest.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/BiasEstimatorTest.java
@@ -67,4 +67,4 @@ public class BiasEstimatorTest {
private static void assertEstimateEquals(double expected, double rawEstimate, BiasEstimator biasEstimator) {
assertEquals(expected, biasEstimator.estimateBias(rawEstimate), 0.00000001);
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/HyperLogLogEstimatorTest.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/HyperLogLogEstimatorTest.java
index 1ba4a71d102..28ebc385194 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/HyperLogLogEstimatorTest.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/HyperLogLogEstimatorTest.java
@@ -86,4 +86,4 @@ public class HyperLogLogEstimatorTest {
byte[] bytes = ByteBuffer.allocate(4).putInt(value).array();
return hashGenerator.hash(bytes, 0, 4, seed);
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/NormalSketchTest.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/NormalSketchTest.java
index 3b0a584f37b..b1f9d2cd96c 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/NormalSketchTest.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/NormalSketchTest.java
@@ -118,4 +118,4 @@ public class NormalSketchTest {
}
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SketchMergerTest.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SketchMergerTest.java
index 07488d21fd3..e435e76caa7 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SketchMergerTest.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SketchMergerTest.java
@@ -66,4 +66,4 @@ public class SketchMergerTest {
assertTrue("Should return the NormalSketch instance given by the arguments.", result == s2);
SketchUtils.assertSketchContains(result, 1, 2);
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SparseSketchTest.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SparseSketchTest.java
index 4be0f89514d..889050959e8 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SparseSketchTest.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/hll/SparseSketchTest.java
@@ -59,4 +59,4 @@ public class SparseSketchTest {
assertEquals(s1.data(), s2.data());
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/gbdt/TreeNodeTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/gbdt/TreeNodeTestCase.java
index 572bd2d8c11..2e39104f136 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/gbdt/TreeNodeTestCase.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/gbdt/TreeNodeTestCase.java
@@ -54,4 +54,4 @@ public class TreeNodeTestCase {
assertEquals("Unknown", e.getMessage());
}
}
-} \ No newline at end of file
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/FeatureListTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/FeatureListTestCase.java
index 7399088ac1c..dfa726ecb8f 100755
--- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/FeatureListTestCase.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/FeatureListTestCase.java
@@ -1,77 +1,77 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.rankingexpression;
-
-import com.yahoo.searchlib.rankingexpression.parser.ParseException;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public class FeatureListTestCase {
-
- @Test
- public void requireThatFeatureListFromStringWorks() throws ParseException {
- assertFromString("attribute(foo).out",
- Arrays.asList("attribute(foo).out"));
- assertFromString("attribute(foo).out attribute ( bar ) . out",
- Arrays.asList("attribute(foo).out", "attribute(bar).out"));
- assertFromString("foo\n bar\n \t \t \n baz \n",
- Arrays.asList("foo", "bar", "baz"));
- assertFromString("attribute attribute(foo) attribute(foo).out attribute(bar).out.out",
- Arrays.asList("attribute", "attribute(foo)", "attribute(foo).out", "attribute(bar).out.out"));
- }
-
- @Test
- public void requireThatFeatureListFromReaderWorks() throws ParseException {
- assertFromReader(new StringReader("attribute(foo).out"),
- Arrays.asList("attribute(foo).out"));
- assertFromReader(new StringReader("attribute(foo).out attribute ( bar ) . out"),
- Arrays.asList("attribute(foo).out", "attribute(bar).out"));
- assertFromReader(new StringReader("foo\n bar\n \t \t \n baz \n"),
- Arrays.asList("foo", "bar", "baz"));
- assertFromReader(new StringReader("attribute attribute(foo) attribute(foo).out attribute(bar).out.out"),
- Arrays.asList("attribute", "attribute(foo)", "attribute(foo).out", "attribute(bar).out.out"));
- }
-
- @Test
- public void requireThatFeatureListFromFileWorks() throws ParseException, FileNotFoundException {
- assertFromFile(new File("src/test/files/features01.expression"),
- Arrays.asList("attribute(foo).out"));
- assertFromFile(new File("src/test/files/features02.expression"),
- Arrays.asList("attribute(foo).out", "attribute(bar).out"));
- assertFromFile(new File("src/test/files/features03.expression"),
- Arrays.asList("foo", "bar", "baz"));
- assertFromFile(new File("src/test/files/features04.expression"),
- Arrays.asList("attribute", "attribute(foo)", "attribute(foo).out", "attribute(bar).out.out"));
- }
-
- public void assertFromString(String input, List<String> expected) throws ParseException {
- assertFeatureList(new FeatureList(input), expected);
- }
-
- public void assertFromReader(Reader input, List<String> expected) throws ParseException {
- assertFeatureList(new FeatureList(input), expected);
- }
-
- public void assertFromFile(File input, List<String> expected) throws ParseException, FileNotFoundException {
- assertFeatureList(new FeatureList(input), expected);
- }
-
- public void assertFeatureList(FeatureList features, List<String> expected) throws ParseException {
- assertEquals(expected.size(), features.size());
- for (int i = 0; i < features.size(); ++i) {
- assertTrue(features.get(i) != null);
- assertEquals(expected.get(i), features.get(i).toString());
- }
- }
-}
+package com.yahoo.searchlib.rankingexpression;
+
+import com.yahoo.searchlib.rankingexpression.parser.ParseException;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class FeatureListTestCase {
+
+ @Test
+ public void requireThatFeatureListFromStringWorks() throws ParseException {
+ assertFromString("attribute(foo).out",
+ Arrays.asList("attribute(foo).out"));
+ assertFromString("attribute(foo).out attribute ( bar ) . out",
+ Arrays.asList("attribute(foo).out", "attribute(bar).out"));
+ assertFromString("foo\n bar\n \t \t \n baz \n",
+ Arrays.asList("foo", "bar", "baz"));
+ assertFromString("attribute attribute(foo) attribute(foo).out attribute(bar).out.out",
+ Arrays.asList("attribute", "attribute(foo)", "attribute(foo).out", "attribute(bar).out.out"));
+ }
+
+ @Test
+ public void requireThatFeatureListFromReaderWorks() throws ParseException {
+ assertFromReader(new StringReader("attribute(foo).out"),
+ Arrays.asList("attribute(foo).out"));
+ assertFromReader(new StringReader("attribute(foo).out attribute ( bar ) . out"),
+ Arrays.asList("attribute(foo).out", "attribute(bar).out"));
+ assertFromReader(new StringReader("foo\n bar\n \t \t \n baz \n"),
+ Arrays.asList("foo", "bar", "baz"));
+ assertFromReader(new StringReader("attribute attribute(foo) attribute(foo).out attribute(bar).out.out"),
+ Arrays.asList("attribute", "attribute(foo)", "attribute(foo).out", "attribute(bar).out.out"));
+ }
+
+ @Test
+ public void requireThatFeatureListFromFileWorks() throws ParseException, FileNotFoundException {
+ assertFromFile(new File("src/test/files/features01.expression"),
+ Arrays.asList("attribute(foo).out"));
+ assertFromFile(new File("src/test/files/features02.expression"),
+ Arrays.asList("attribute(foo).out", "attribute(bar).out"));
+ assertFromFile(new File("src/test/files/features03.expression"),
+ Arrays.asList("foo", "bar", "baz"));
+ assertFromFile(new File("src/test/files/features04.expression"),
+ Arrays.asList("attribute", "attribute(foo)", "attribute(foo).out", "attribute(bar).out.out"));
+ }
+
+ public void assertFromString(String input, List<String> expected) throws ParseException {
+ assertFeatureList(new FeatureList(input), expected);
+ }
+
+ public void assertFromReader(Reader input, List<String> expected) throws ParseException {
+ assertFeatureList(new FeatureList(input), expected);
+ }
+
+ public void assertFromFile(File input, List<String> expected) throws ParseException, FileNotFoundException {
+ assertFeatureList(new FeatureList(input), expected);
+ }
+
+ public void assertFeatureList(FeatureList features, List<String> expected) throws ParseException {
+ assertEquals(expected.size(), features.size());
+ for (int i = 0; i < features.size(); ++i) {
+ assertTrue(features.get(i) != null);
+ assertEquals(expected.get(i), features.get(i).toString());
+ }
+ }
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/Benchmark.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/Benchmark.java
index 7690efb1112..b2633f13fe6 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/Benchmark.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/Benchmark.java
@@ -1,144 +1,144 @@
// Copyright 2016 Yahoo Inc. 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.RankingExpression;
-import com.yahoo.searchlib.rankingexpression.evaluation.gbdtoptimization.GBDTForestOptimizer;
-import com.yahoo.searchlib.rankingexpression.parser.ParseException;
-import com.yahoo.searchlib.rankingexpression.rule.CompositeNode;
-import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
-import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public final class Benchmark {
-
- public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println("Usage: Benchmark <filename> [<iterations>]");
- System.exit(1);
- }
- int numRuns = 1000;
- if (args.length == 2) {
- numRuns = Integer.valueOf(args[1]);
- }
- List<Result> res = new ArrayList<Result>();
- try {
- BufferedReader in = new BufferedReader(new FileReader(args[0]));
- StringBuilder str = new StringBuilder();
- String line;
- while ((line = in.readLine()) != null) {
- str.append(line);
- }
- String exp = str.toString();
- res.add(evaluateTree(exp, numRuns));
- res.add(evaluateTreeOptimized(exp, numRuns));
- res.add(evaluateForestOptimized(exp, numRuns));
- } catch (IOException e) {
- System.out.println("An error occured while reading the content of file '" + args[0] + "': " + e);
- System.exit(1);
- } catch (ParseException e) {
- System.out.println("An error occured while parsing the content of file '" + args[0] + "': " + e);
- System.exit(1);
- }
- for (Result lhs : res) {
- for (Result rhs : res) {
- if (lhs.res < rhs.res - 1e-6 || lhs.res > rhs.res + 1e-6) {
- System.err.println("Evaluation of '" + lhs.name + "' and '" + rhs.name + "' disagree on result; " +
- "expected " + lhs.res + ", got " + rhs.res + ".");
- System.exit(1);
- }
- }
- System.out.format("%1$-16s : %2$8.04f ms (%3$-6.04f)\n",
- lhs.name, lhs.millis, res.get(0).millis / lhs.millis);
- }
- }
-
- private static Result evaluateTree(String str, int numRuns) throws ParseException {
- Result ret = new Result();
- ret.name = "Unoptimized";
-
- RankingExpression exp = new RankingExpression(str);
- List<String> vars = new LinkedList<String>();
- getFeatures(exp.getRoot(), vars);
-
- benchmark(exp, vars, new MapContext(), numRuns, ret);
- return ret;
- }
-
- private static Result evaluateTreeOptimized(String str, int numRuns) throws ParseException {
- Result ret = new Result();
- ret.name = "Optimized tree";
-
- RankingExpression exp = new RankingExpression(str);
- List<String> vars = new LinkedList<String>();
- getFeatures(exp.getRoot(), vars);
-
- ArrayContext ctx = new ArrayContext(exp);
- ExpressionOptimizer optimizer = new ExpressionOptimizer();
- optimizer.getOptimizer(GBDTForestOptimizer.class).setEnabled(false);
- optimizer.optimize(exp, ctx);
-
- benchmark(exp, vars, ctx, numRuns, ret);
- return ret;
- }
-
- private static Result evaluateForestOptimized(String str, int numRuns) throws ParseException {
- Result ret = new Result();
- ret.name = "Optimized forest";
-
- RankingExpression exp = new RankingExpression(str);
- List<String> vars = new LinkedList<String>();
- getFeatures(exp.getRoot(), vars);
-
- ArrayContext ctx = new ArrayContext(exp);
- ExpressionOptimizer optimizer = new ExpressionOptimizer();
- optimizer.optimize(exp, ctx);
-
- benchmark(exp, vars, ctx, numRuns, ret);
- return ret;
- }
-
- private static void benchmark(RankingExpression exp, List<String> vars, Context ctx, int numRuns, Result out) {
- for (int i = 0, len = vars.size(); i < len; ++i) {
- ctx.put(vars.get(i), i / (double)len);
- }
- for (int i = 0; i < numRuns; ++i) {
- out.res = exp.evaluate(ctx).asDouble();
- }
- long begin = System.nanoTime();
- for (int i = 0; i < numRuns; ++i) {
- out.res = exp.evaluate(ctx).asDouble();
- }
- long end = System.nanoTime();
-
- out.millis = (end - begin) / (1000.0 * 1000.0);
- }
-
- private static void getFeatures(ExpressionNode node, List<String> out) {
- if (node instanceof ReferenceNode) {
- String feature = ((ReferenceNode)node).getName();
- if (!out.contains(feature)) {
- out.add(feature);
- }
- } else if (node instanceof CompositeNode) {
- CompositeNode cNode = (CompositeNode)node;
- for (ExpressionNode child : cNode.children()) {
- getFeatures(child, out);
- }
- }
- }
-
- private static class Result {
- String name = "anonymous";
- double millis = Double.MAX_VALUE;
- double res = 0;
- }
-}
+package com.yahoo.searchlib.rankingexpression.evaluation;
+
+import com.yahoo.searchlib.rankingexpression.RankingExpression;
+import com.yahoo.searchlib.rankingexpression.evaluation.gbdtoptimization.GBDTForestOptimizer;
+import com.yahoo.searchlib.rankingexpression.parser.ParseException;
+import com.yahoo.searchlib.rankingexpression.rule.CompositeNode;
+import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
+import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public final class Benchmark {
+
+ public static void main(String[] args) {
+ if (args.length < 1) {
+ System.err.println("Usage: Benchmark <filename> [<iterations>]");
+ System.exit(1);
+ }
+ int numRuns = 1000;
+ if (args.length == 2) {
+ numRuns = Integer.valueOf(args[1]);
+ }
+ List<Result> res = new ArrayList<Result>();
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(args[0]));
+ StringBuilder str = new StringBuilder();
+ String line;
+ while ((line = in.readLine()) != null) {
+ str.append(line);
+ }
+ String exp = str.toString();
+ res.add(evaluateTree(exp, numRuns));
+ res.add(evaluateTreeOptimized(exp, numRuns));
+ res.add(evaluateForestOptimized(exp, numRuns));
+ } catch (IOException e) {
+ System.out.println("An error occured while reading the content of file '" + args[0] + "': " + e);
+ System.exit(1);
+ } catch (ParseException e) {
+ System.out.println("An error occured while parsing the content of file '" + args[0] + "': " + e);
+ System.exit(1);
+ }
+ for (Result lhs : res) {
+ for (Result rhs : res) {
+ if (lhs.res < rhs.res - 1e-6 || lhs.res > rhs.res + 1e-6) {
+ System.err.println("Evaluation of '" + lhs.name + "' and '" + rhs.name + "' disagree on result; " +
+ "expected " + lhs.res + ", got " + rhs.res + ".");
+ System.exit(1);
+ }
+ }
+ System.out.format("%1$-16s : %2$8.04f ms (%3$-6.04f)\n",
+ lhs.name, lhs.millis, res.get(0).millis / lhs.millis);
+ }
+ }
+
+ private static Result evaluateTree(String str, int numRuns) throws ParseException {
+ Result ret = new Result();
+ ret.name = "Unoptimized";
+
+ RankingExpression exp = new RankingExpression(str);
+ List<String> vars = new LinkedList<String>();
+ getFeatures(exp.getRoot(), vars);
+
+ benchmark(exp, vars, new MapContext(), numRuns, ret);
+ return ret;
+ }
+
+ private static Result evaluateTreeOptimized(String str, int numRuns) throws ParseException {
+ Result ret = new Result();
+ ret.name = "Optimized tree";
+
+ RankingExpression exp = new RankingExpression(str);
+ List<String> vars = new LinkedList<String>();
+ getFeatures(exp.getRoot(), vars);
+
+ ArrayContext ctx = new ArrayContext(exp);
+ ExpressionOptimizer optimizer = new ExpressionOptimizer();
+ optimizer.getOptimizer(GBDTForestOptimizer.class).setEnabled(false);
+ optimizer.optimize(exp, ctx);
+
+ benchmark(exp, vars, ctx, numRuns, ret);
+ return ret;
+ }
+
+ private static Result evaluateForestOptimized(String str, int numRuns) throws ParseException {
+ Result ret = new Result();
+ ret.name = "Optimized forest";
+
+ RankingExpression exp = new RankingExpression(str);
+ List<String> vars = new LinkedList<String>();
+ getFeatures(exp.getRoot(), vars);
+
+ ArrayContext ctx = new ArrayContext(exp);
+ ExpressionOptimizer optimizer = new ExpressionOptimizer();
+ optimizer.optimize(exp, ctx);
+
+ benchmark(exp, vars, ctx, numRuns, ret);
+ return ret;
+ }
+
+ private static void benchmark(RankingExpression exp, List<String> vars, Context ctx, int numRuns, Result out) {
+ for (int i = 0, len = vars.size(); i < len; ++i) {
+ ctx.put(vars.get(i), i / (double)len);
+ }
+ for (int i = 0; i < numRuns; ++i) {
+ out.res = exp.evaluate(ctx).asDouble();
+ }
+ long begin = System.nanoTime();
+ for (int i = 0; i < numRuns; ++i) {
+ out.res = exp.evaluate(ctx).asDouble();
+ }
+ long end = System.nanoTime();
+
+ out.millis = (end - begin) / (1000.0 * 1000.0);
+ }
+
+ private static void getFeatures(ExpressionNode node, List<String> out) {
+ if (node instanceof ReferenceNode) {
+ String feature = ((ReferenceNode)node).getName();
+ if (!out.contains(feature)) {
+ out.add(feature);
+ }
+ } else if (node instanceof CompositeNode) {
+ CompositeNode cNode = (CompositeNode)node;
+ for (ExpressionNode child : cNode.children()) {
+ getFeatures(child, out);
+ }
+ }
+ }
+
+ private static class Result {
+ String name = "anonymous";
+ double millis = Double.MAX_VALUE;
+ double res = 0;
+ }
+}
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java
index 0e27d53338a..620da92ef95 100755
--- a/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java
@@ -1,79 +1,79 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.treenet;
-
-import com.yahoo.searchlib.rankingexpression.RankingExpression;
-import com.yahoo.searchlib.treenet.parser.ParseException;
-import com.yahoo.searchlib.treenet.parser.TreeNetParser;
-import junit.framework.TestCase;
-
-import java.io.*;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
- */
-public class TreeNetParserTestCase extends TestCase {
-
- private static final boolean WRITE_FILES = false;
-
- public void testRankingExpression() {
- for (int i = 1; i <= 8; ++i) {
- String inputFile = String.format("src/test/files/treenet%02d.model", i);
- String outputFile = String.format("src/test/files/ranking%02d.expression", i);
- String input = readFile(inputFile);
- String expression = convertModel(inputFile, input);
- if (WRITE_FILES) {
- writeFile(outputFile, expression);
- }
- else {
- String output = readFile(outputFile);
- assertParseable(output, outputFile);
- assertEquals(output.trim(), expression);
- }
- }
- }
-
- private void assertParseable(String rankingExpressionString,String fileName) {
- try {
- new RankingExpression(rankingExpressionString);
- }
- catch (com.yahoo.searchlib.rankingexpression.parser.ParseException e) {
- throw new RuntimeException("Could not parse ranking expression in '" + fileName + "'",e);
- }
- }
-
- private String convertModel(String modelFile, String model) {
- try {
- TreeNetParser parser = new TreeNetParser(new StringReader(model));
- return parser.treeNet().toRankingExpression();
- } catch (ParseException e) {
- throw new AssertionError("In model " + modelFile + ": " + e.getMessage(), e);
- }
- }
-
- private String readFile(String file) {
- try {
- StringBuilder ret = new StringBuilder();
- BufferedReader in = new BufferedReader(new FileReader(file));
- while (true) {
- String str = in.readLine();
- if (str == null) {
- break;
- }
- ret.append(str).append("\n");
- }
- return ret.toString();
- } catch (IOException e) {
- throw new AssertionError(e);
- }
- }
-
- private void writeFile(String file, String content) {
- try {
- FileWriter out = new FileWriter(file);
- out.write(content);
- out.close();
- } catch (IOException e) {
- throw new AssertionError(e);
- }
- }
-}
+package com.yahoo.searchlib.treenet;
+
+import com.yahoo.searchlib.rankingexpression.RankingExpression;
+import com.yahoo.searchlib.treenet.parser.ParseException;
+import com.yahoo.searchlib.treenet.parser.TreeNetParser;
+import junit.framework.TestCase;
+
+import java.io.*;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class TreeNetParserTestCase extends TestCase {
+
+ private static final boolean WRITE_FILES = false;
+
+ public void testRankingExpression() {
+ for (int i = 1; i <= 8; ++i) {
+ String inputFile = String.format("src/test/files/treenet%02d.model", i);
+ String outputFile = String.format("src/test/files/ranking%02d.expression", i);
+ String input = readFile(inputFile);
+ String expression = convertModel(inputFile, input);
+ if (WRITE_FILES) {
+ writeFile(outputFile, expression);
+ }
+ else {
+ String output = readFile(outputFile);
+ assertParseable(output, outputFile);
+ assertEquals(output.trim(), expression);
+ }
+ }
+ }
+
+ private void assertParseable(String rankingExpressionString,String fileName) {
+ try {
+ new RankingExpression(rankingExpressionString);
+ }
+ catch (com.yahoo.searchlib.rankingexpression.parser.ParseException e) {
+ throw new RuntimeException("Could not parse ranking expression in '" + fileName + "'",e);
+ }
+ }
+
+ private String convertModel(String modelFile, String model) {
+ try {
+ TreeNetParser parser = new TreeNetParser(new StringReader(model));
+ return parser.treeNet().toRankingExpression();
+ } catch (ParseException e) {
+ throw new AssertionError("In model " + modelFile + ": " + e.getMessage(), e);
+ }
+ }
+
+ private String readFile(String file) {
+ try {
+ StringBuilder ret = new StringBuilder();
+ BufferedReader in = new BufferedReader(new FileReader(file));
+ while (true) {
+ String str = in.readLine();
+ if (str == null) {
+ break;
+ }
+ ret.append(str).append("\n");
+ }
+ return ret.toString();
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ private void writeFile(String file, String content) {
+ try {
+ FileWriter out = new FileWriter(file);
+ out.write(content);
+ out.close();
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+}
diff --git a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
index 3621537c8fd..e38837c8630 100644
--- a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
+++ b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
@@ -415,4 +415,4 @@ TEST_F("onSerializeForDescendingSort() is forwarded to target vector", Serialize
} // attribute
} // search
-TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file
+TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
index f50767d22b3..a56d8285129 100644
--- a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
+++ b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
@@ -336,4 +336,4 @@ TEST_F("queryTerm() returns term context was created with", WsetValueFixture) {
} // attribute
} // search
-TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file
+TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/tests/diskindex/fusion/fusion_test.cpp b/searchlib/src/tests/diskindex/fusion/fusion_test.cpp
index f5f1f97d29b..e835448da9e 100644
--- a/searchlib/src/tests/diskindex/fusion/fusion_test.cpp
+++ b/searchlib/src/tests/diskindex/fusion/fusion_test.cpp
@@ -477,4 +477,4 @@ Test::Main()
}
-TEST_APPHOOK(search::diskindex::Test); \ No newline at end of file
+TEST_APPHOOK(search::diskindex::Test);
diff --git a/searchlib/src/vespa/searchlib/attribute/changevector.cpp b/searchlib/src/vespa/searchlib/attribute/changevector.cpp
index 912d6884279..b31e29bad63 100644
--- a/searchlib/src/vespa/searchlib/attribute/changevector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/changevector.cpp
@@ -23,4 +23,4 @@ template class ChangeVectorT<ChangeTemplate<StringChangeData>>;
template class ChangeVectorT<ChangeTemplate<NumericChangeData<int64_t>>>;
template class ChangeVectorT<ChangeTemplate<NumericChangeData<double>>>;
-} \ No newline at end of file
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
index 556ce7c2722..e07aa421c3a 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
@@ -93,4 +93,4 @@ private:
};
} // attribute
-} // search \ No newline at end of file
+} // search
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
index 51b765f725a..c117cdc66c5 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
@@ -68,4 +68,4 @@ bool ImportedSearchContext::cmp(DocId docId) const {
}
} // attribute
-} // search \ No newline at end of file
+} // search
diff --git a/searchlib/src/vespa/searchlib/datastore/datastore.cpp b/searchlib/src/vespa/searchlib/datastore/datastore.cpp
index 13b3bf3a6e2..14edb5b5cd5 100644
--- a/searchlib/src/vespa/searchlib/datastore/datastore.cpp
+++ b/searchlib/src/vespa/searchlib/datastore/datastore.cpp
@@ -16,4 +16,4 @@ template class DataStoreT<EntryRefT<22> >;
template void vespalib::Array<search::datastore::DataStoreBase::ElemHold1ListElem>::increase(size_t);
template class search::attribute::RcuVector<search::datastore::EntryRef>;
template class search::attribute::RcuVectorBase<search::datastore::EntryRef>;
-//template void search::attribute::RcuVectorBase<search::datastore::EntryRef>::expandAndInsert(const search::datastore::EntryRef &); \ No newline at end of file
+//template void search::attribute::RcuVectorBase<search::datastore::EntryRef>::expandAndInsert(const search::datastore::EntryRef &);
diff --git a/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp b/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp
index c24b4e25821..b850ddf79cc 100644
--- a/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp
+++ b/searchlib/src/vespa/searchlib/engine/propertiesmap.cpp
@@ -33,4 +33,4 @@ PropertiesMap::lookup(const vespalib::stringref &name) const
} // namespace engine
} // namespace search
-VESPALIB_HASH_MAP_INSTANTIATE(vespalib::string, search::fef::Properties); \ No newline at end of file
+VESPALIB_HASH_MAP_INSTANTIATE(vespalib::string, search::fef::Properties);
diff --git a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
index eb278280156..642b942390a 100644
--- a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
+++ b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
@@ -261,4 +261,4 @@ bool has_active_enum_guards(AttributeVector &attr) {
}
} // attribute
-} // search \ No newline at end of file
+} // search
diff --git a/searchlib/src/vespa/searchlib/test/statestring.h b/searchlib/src/vespa/searchlib/test/statestring.h
index 7fb6f1fce85..475872b8e89 100644
--- a/searchlib/src/vespa/searchlib/test/statestring.h
+++ b/searchlib/src/vespa/searchlib/test/statestring.h
@@ -10,4 +10,4 @@ void normalizeAddr(vespalib::string &s, void *addr);
void normalizeTimestamps(std::vector<vespalib::string> &sv);
void normalizeAddrs(std::vector<vespalib::string> &sv, void *addr);
-} \ No newline at end of file
+}
diff --git a/searchlib/src/vespa/searchlib/util/url.h b/searchlib/src/vespa/searchlib/util/url.h
index 88a4ef6d9f7..35de9d2206c 100644
--- a/searchlib/src/vespa/searchlib/util/url.h
+++ b/searchlib/src/vespa/searchlib/util/url.h
@@ -272,4 +272,4 @@ public:
void Dump();
};
-} \ No newline at end of file
+}