summaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/main/java/com')
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java17
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java8
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java18
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ModelImporter.java14
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/IntermediateOperation.java22
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/PlaceholderWithDefault.java6
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java4
7 files changed, 53 insertions, 36 deletions
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 c6d8f70fde8..da34ab8822d 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/ExpressionFunction.java
@@ -3,13 +3,16 @@ package com.yahoo.searchlib.rankingexpression;
import com.google.common.collect.ImmutableList;
import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
-import com.yahoo.searchlib.rankingexpression.rule.FunctionReferenceContext;
import com.yahoo.searchlib.rankingexpression.rule.SerializationContext;
import com.yahoo.text.Utf8;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.*;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* A function defined by a ranking expression
@@ -24,6 +27,16 @@ public class ExpressionFunction {
private final RankingExpression body;
/**
+ * Constructs a new function with no arguments
+ *
+ * @param name the name of this function
+ * @param body the ranking expression that defines this function
+ */
+ public ExpressionFunction(String name, RankingExpression body) {
+ this(name, Collections.emptyList(), body);
+ }
+
+ /**
* Constructs a new function
*
* @param name the name of this function
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java
index ed82ba20fbe..722520fea08 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java
@@ -250,12 +250,12 @@ public class RankingExpression implements Serializable {
/**
* Creates the necessary rank properties required to implement this expression.
*
- * @param macros the expression macros to expand.
- * @return a list of named rank properties required to implement this expression.
+ * @param functions the expression functions to expand
+ * @return a list of named rank properties required to implement this expression
*/
- public Map<String, String> getRankProperties(List<ExpressionFunction> macros) {
+ public Map<String, String> getRankProperties(List<ExpressionFunction> functions) {
Deque<String> path = new LinkedList<>();
- SerializationContext context = new SerializationContext(macros);
+ SerializationContext context = new SerializationContext(functions);
String serializedRoot = root.toString(new StringBuilder(), context, path, null).toString();
Map<String, String> serializedExpressions = context.serializedFunctions();
serializedExpressions.put(propertyName(name), serializedRoot);
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java
index ac5eefcc5b2..282a4c5e0a9 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java
@@ -30,8 +30,8 @@ public class ImportedModel {
private final Map<String, Tensor> smallConstants = new HashMap<>();
private final Map<String, Tensor> largeConstants = new HashMap<>();
private final Map<String, RankingExpression> expressions = new HashMap<>();
- private final Map<String, RankingExpression> macros = new HashMap<>();
- private final Map<String, TensorType> requiredMacros = new HashMap<>();
+ private final Map<String, RankingExpression> functions = new HashMap<>();
+ private final Map<String, TensorType> requiredFunctions = new HashMap<>();
/**
* Creates a new imported model.
@@ -77,13 +77,13 @@ public class ImportedModel {
public Map<String, RankingExpression> expressions() { return Collections.unmodifiableMap(expressions); }
/**
- * Returns an immutable map of macros that are part of this model.
- * Note that the macros themselves are *not* copies and *not* immutable - they must be copied before modification.
+ * Returns an immutable map of the functions that are part of this model.
+ * Note that the functions themselves are *not* copies and *not* immutable - they must be copied before modification.
*/
- public Map<String, RankingExpression> macros() { return Collections.unmodifiableMap(macros); }
+ public Map<String, RankingExpression> functions() { return Collections.unmodifiableMap(functions); }
- /** Returns an immutable map of the macros that must be provided by the environment running this model */
- public Map<String, TensorType> requiredMacros() { return Collections.unmodifiableMap(requiredMacros); }
+ /** Returns an immutable map of the functions that must be provided by the environment running this model */
+ public Map<String, TensorType> requiredFunctions() { return Collections.unmodifiableMap(requiredFunctions); }
/** Returns an immutable map of the signatures of this */
public Map<String, Signature> signatures() { return Collections.unmodifiableMap(signatures); }
@@ -100,8 +100,8 @@ public class ImportedModel {
void smallConstant(String name, Tensor constant) { smallConstants.put(name, constant); }
void largeConstant(String name, Tensor constant) { largeConstants.put(name, constant); }
void expression(String name, RankingExpression expression) { expressions.put(name, expression); }
- void macro(String name, RankingExpression expression) { macros.put(name, expression); }
- void requiredMacro(String name, TensorType type) { requiredMacros.put(name, type); }
+ void function(String name, RankingExpression expression) { functions.put(name, expression); }
+ void requiredFunction(String name, TensorType type) { requiredFunctions.put(name, type); }
/**
* Returns all the output expressions of this indexed by name. The names consist of one or two parts
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ModelImporter.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ModelImporter.java
index 2ae107a5770..d25502fd149 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ModelImporter.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ModelImporter.java
@@ -24,7 +24,7 @@ import java.util.logging.Logger;
* ranking expressions. The general mechanism for import is for the
* specific ML platform import implementations to create an
* IntermediateGraph. This class offers common code to convert the
- * IntermediateGraph to Vespa ranking expressions and macros.
+ * IntermediateGraph to Vespa ranking expressions and functions.
*
* @author lesters
*/
@@ -122,7 +122,7 @@ public abstract class ModelImporter {
importExpressionInputs(operation, model);
importRankingExpression(operation, model);
importArgumentExpression(operation, model);
- importMacroExpression(operation, model);
+ importFunctionExpression(operation, model);
return operation.function();
}
@@ -188,15 +188,15 @@ public abstract class ModelImporter {
// All inputs must have dimensions with standard naming convention: d0, d1, ...
OrderedTensorType standardNamingConvention = OrderedTensorType.standardType(operation.type().get());
model.argument(operation.vespaName(), standardNamingConvention.type());
- model.requiredMacro(operation.vespaName(), standardNamingConvention.type());
+ model.requiredFunction(operation.vespaName(), standardNamingConvention.type());
}
}
- private static void importMacroExpression(IntermediateOperation operation, ImportedModel model) {
- if (operation.macro().isPresent()) {
- TensorFunction function = operation.macro().get();
+ private static void importFunctionExpression(IntermediateOperation operation, ImportedModel model) {
+ if (operation.rankingExpressionFunction().isPresent()) {
+ TensorFunction function = operation.rankingExpressionFunction().get();
try {
- model.macro(operation.macroName(), new RankingExpression(operation.macroName(), function.toString()));
+ model.function(operation.rankingExpressionFunctionName(), new RankingExpression(operation.rankingExpressionFunctionName(), function.toString()));
}
catch (ParseException e) {
throw new RuntimeException("Tensorflow function " + function +
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/IntermediateOperation.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/IntermediateOperation.java
index 43de29cedd5..34f5f1365a1 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/IntermediateOperation.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/IntermediateOperation.java
@@ -29,7 +29,7 @@ import java.util.function.Function;
*/
public abstract class IntermediateOperation {
- private final static String MACRO_PREFIX = "imported_ml_macro_";
+ private final static String FUNCTION_PREFIX = "imported_ml_function_";
protected final String name;
protected final String modelName;
@@ -38,7 +38,7 @@ public abstract class IntermediateOperation {
protected OrderedTensorType type;
protected TensorFunction function;
- protected TensorFunction macro = null;
+ protected TensorFunction rankingExpressionFunction = null;
private final List<String> importWarnings = new ArrayList<>();
private Value constantValue = null;
@@ -71,8 +71,8 @@ public abstract class IntermediateOperation {
ExpressionNode constant = new ReferenceNode(Reference.simple("constant", vespaName()));
function = new TensorFunctionNode.TensorFunctionExpressionNode(constant);
} else if (outputs.size() > 1) {
- macro = lazyGetFunction();
- function = new VariableTensor(macroName(), type.type());
+ rankingExpressionFunction = lazyGetFunction();
+ function = new VariableTensor(rankingExpressionFunctionName(), type.type());
} else {
function = lazyGetFunction();
}
@@ -86,11 +86,13 @@ public abstract class IntermediateOperation {
/** Return unmodifiable list of inputs */
public List<IntermediateOperation> inputs() { return inputs; }
- /** Return unmodifiable list of outputs. If a node has multiple outputs, consider adding a macro. */
+ /** Return unmodifiable list of outputs. If a node has multiple outputs, consider adding a function. */
public List<IntermediateOperation> outputs() { return Collections.unmodifiableList(outputs); }
- /** Returns a Vespa ranking expression that should be added as a macro */
- public Optional<TensorFunction> macro() { return Optional.ofNullable(macro); }
+ /** Returns a function that should be added as a ranking expression function */
+ public Optional<TensorFunction> rankingExpressionFunction() {
+ return Optional.ofNullable(rankingExpressionFunction);
+ }
/** Add dimension name constraints for this operation */
public void addDimensionNameConstraints(DimensionRenamer renamer) { }
@@ -131,8 +133,10 @@ public abstract class IntermediateOperation {
public String vespaName() { return vespaName(name); }
public String vespaName(String name) { return name != null ? namePartOf(name).replace('/', '_') : null; }
- /** Retrieve the valid Vespa name of this node if it is a macro */
- public String macroName() { return vespaName() != null ? MACRO_PREFIX + modelName + "_" + vespaName() : null; }
+ /** Retrieve the valid Vespa name of this node if it is a ranking expression function */
+ public String rankingExpressionFunctionName() {
+ return vespaName() != null ? FUNCTION_PREFIX + modelName + "_" + vespaName() : null;
+ }
/** Retrieve the list of warnings produced during its lifetime */
public List<String> warnings() { return Collections.unmodifiableList(importWarnings); }
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/PlaceholderWithDefault.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/PlaceholderWithDefault.java
index 9299ae9be12..b335fd7e1c5 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/PlaceholderWithDefault.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/importer/operations/PlaceholderWithDefault.java
@@ -26,13 +26,13 @@ public class PlaceholderWithDefault extends IntermediateOperation {
if (!allInputFunctionsPresent(1)) {
return null;
}
- // This should be a call to the macro we add below, but for now
+ // This should be a call to the function we add below, but for now
// we treat this as as identity function and just pass the constant.
return inputs.get(0).function().orElse(null);
}
@Override
- public Optional<TensorFunction> macro() {
+ public Optional<TensorFunction> rankingExpressionFunction() {
// For now, it is much more efficient to assume we always will return
// the default value, as we can prune away large parts of the expression
// tree by having it calculated as a constant. If a case arises where
@@ -42,7 +42,7 @@ public class PlaceholderWithDefault extends IntermediateOperation {
@Override
public boolean isConstant() {
- return true; // not true if we add to macro
+ return true; // not true if we add to function
}
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
index e2dc170c168..eb8d2229a6d 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
@@ -15,7 +15,7 @@ import java.util.Deque;
import java.util.List;
/**
- * A node referring either to a value in the context or to a named ranking expression (function aka macro).
+ * A node referring either to a value in the context or to a named ranking expression function.
*
* @author bratseth
*/
@@ -64,7 +64,7 @@ public final class ReferenceNode extends CompositeNode {
@Override
public StringBuilder toString(StringBuilder string, SerializationContext context, Deque<String> path, CompositeNode parent) {
- // A reference to a macro argument?
+ // A reference to a function argument?
if (reference.isIdentifier() && context.getBinding(getName()) != null) {
// a bound identifier: replace by the value it is bound to
return string.append(context.getBinding(getName()));