summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-09-17 11:23:38 +0200
committerJon Bratseth <bratseth@oath.com>2018-09-17 11:23:38 +0200
commit493adba229cc53c5766b0b63060562d6256abdd8 (patch)
treef6988d869d1e8bc07825482d72b289f881935de3 /config-model
parente2bc647f01162d7b5f0886337f308a9be6629a40 (diff)
Refactor: macro -> function
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java2
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java104
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java46
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ExpressionTransforms.java4
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionInliner.java (renamed from config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroInliner.java)6
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java (renamed from config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroShadower.java)14
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java8
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java2
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java (renamed from config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedMacroNames.java)18
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java4
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java190
-rw-r--r--config-model/src/main/javacc/SDParser.jj6
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java6
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java14
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java2
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java2
18 files changed, 217 insertions, 219 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
index e094dd0ebcd..0d9ea00bf73 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java
@@ -70,7 +70,7 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement
currentResolutionCallStack.stream().map(Reference::toString).collect(Collectors.joining(" -> ")) +
" -> " + reference);
- // A reference to a macro argument?
+ // A reference to a function argument?
Optional<String> binding = boundIdentifier(reference);
if (binding.isPresent()) {
try {
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
index 509fa243bc3..30737365844 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
@@ -101,7 +101,7 @@ public class RankProfile implements Serializable, Cloneable {
private String firstPhaseRankingString = null;
- private Map<String, RankingExpressionFunction> macros= new LinkedHashMap<>();
+ private Map<String, RankingExpressionFunction> functions = new LinkedHashMap<>();
private Set<String> filterFields = new HashSet<>();
@@ -548,39 +548,39 @@ public class RankProfile implements Serializable, Cloneable {
return null;
}
- /** Adds a new macro and returns it */
- public RankingExpressionFunction addMacro(String name, List<String> arguments, String expression, boolean inline) {
+ /** Adds a function and returns it */
+ public RankingExpressionFunction addFunction(String name, List<String> arguments, String expression, boolean inline) {
try {
- return addMacro(new ExpressionFunction(name, arguments, parseRankingExpression(name, expression)), inline);
+ return addFunction(new ExpressionFunction(name, arguments, parseRankingExpression(name, expression)), inline);
}
catch (ParseException e) {
- throw new IllegalArgumentException("Could not parse macro '" + name + "'", e);
+ throw new IllegalArgumentException("Could not parse function '" + name + "'", e);
}
}
- /** Adds a new macro and returns it */
- public RankingExpressionFunction addMacro(ExpressionFunction function, boolean inline) {
+ /** Adds a function and returns it */
+ public RankingExpressionFunction addFunction(ExpressionFunction function, boolean inline) {
RankingExpressionFunction rankingExpressionFunction = new RankingExpressionFunction(function, inline);
- macros.put(function.getName(), rankingExpressionFunction);
+ functions.put(function.getName(), rankingExpressionFunction);
return rankingExpressionFunction;
}
- /** Returns an unmodifiable view of the macros in this */
- public Map<String, RankingExpressionFunction> getMacros() {
- if (macros.size() == 0 && getInherited()==null) return Collections.emptyMap();
- if (macros.size() == 0) return getInherited().getMacros();
- if (getInherited() == null) return Collections.unmodifiableMap(macros);
+ /** Returns an unmodifiable view of the functions in this */
+ public Map<String, RankingExpressionFunction> getFunctions() {
+ if (functions.size() == 0 && getInherited() == null) return Collections.emptyMap();
+ if (functions.size() == 0) return getInherited().getFunctions();
+ if (getInherited() == null) return Collections.unmodifiableMap(functions);
// Neither is null
- Map<String, RankingExpressionFunction> allMacros = new LinkedHashMap<>(getInherited().getMacros());
- allMacros.putAll(macros);
- return Collections.unmodifiableMap(allMacros);
+ Map<String, RankingExpressionFunction> allFunctions = new LinkedHashMap<>(getInherited().getFunctions());
+ allFunctions.putAll(functions);
+ return Collections.unmodifiableMap(allFunctions);
}
public int getKeepRankCount() {
- if (keepRankCount>=0) return keepRankCount;
- if (getInherited()!=null) return getInherited().getKeepRankCount();
+ if (keepRankCount >= 0) return keepRankCount;
+ if (getInherited() != null) return getInherited().getKeepRankCount();
return -1;
}
@@ -679,14 +679,13 @@ public class RankProfile implements Serializable, Cloneable {
@Override
public RankProfile clone() {
try {
- // Note: This treats RankingExpression in Macros as immutables even though they are not
RankProfile clone = (RankProfile)super.clone();
clone.rankSettings = new LinkedHashSet<>(this.rankSettings);
clone.matchPhaseSettings = this.matchPhaseSettings; // hmm?
clone.summaryFeatures = summaryFeatures != null ? new LinkedHashSet<>(this.summaryFeatures) : null;
clone.rankFeatures = rankFeatures != null ? new LinkedHashSet<>(this.rankFeatures) : null;
clone.rankProperties = new LinkedHashMap<>(this.rankProperties);
- clone.macros = new LinkedHashMap<>(this.macros);
+ clone.functions = new LinkedHashMap<>(this.functions);
clone.filterFields = new HashSet<>(this.filterFields);
clone.constants = new HashMap<>(this.constants);
return clone;
@@ -713,58 +712,59 @@ public class RankProfile implements Serializable, Cloneable {
private void compileThis(QueryProfileRegistry queryProfiles, ImportedModels importedModels) {
parseExpressions();
- checkNameCollisions(getMacros(), getConstants());
+ checkNameCollisions(getFunctions(), getConstants());
ExpressionTransforms expressionTransforms = new ExpressionTransforms();
- // Macro compiling first pass: compile inline macros without resolving other macros
- Map<String, RankingExpressionFunction> inlineMacros = compileMacros(getInlineMacros(), queryProfiles, importedModels, Collections.emptyMap(), expressionTransforms);
+ // Function compiling first pass: compile inline functions without resolving other functions
+ Map<String, RankingExpressionFunction> inlineFunctions =
+ compileFunctions(getInlineFunctions(), queryProfiles, importedModels, Collections.emptyMap(), expressionTransforms);
- // Macro compiling second pass: compile all macros and insert previously compiled inline macros
- macros = compileMacros(getMacros(), queryProfiles, importedModels, inlineMacros, expressionTransforms);
+ // Function compiling second pass: compile all functions and insert previously compiled inline functions
+ functions = compileFunctions(getFunctions(), queryProfiles, importedModels, inlineFunctions, expressionTransforms);
- firstPhaseRanking = compile(this.getFirstPhaseRanking(), queryProfiles, importedModels, getConstants(), inlineMacros, expressionTransforms);
- secondPhaseRanking = compile(this.getSecondPhaseRanking(), queryProfiles, importedModels, getConstants(), inlineMacros, expressionTransforms);
+ firstPhaseRanking = compile(this.getFirstPhaseRanking(), queryProfiles, importedModels, getConstants(), inlineFunctions, expressionTransforms);
+ secondPhaseRanking = compile(this.getSecondPhaseRanking(), queryProfiles, importedModels, getConstants(), inlineFunctions, expressionTransforms);
}
- private void checkNameCollisions(Map<String, RankingExpressionFunction> macros, Map<String, Value> constants) {
- for (Map.Entry<String, RankingExpressionFunction> macroEntry : macros.entrySet()) {
- if (constants.get(macroEntry.getKey()) != null)
- throw new IllegalArgumentException("Cannot have both a constant and macro named '" +
- macroEntry.getKey() + "'");
+ private void checkNameCollisions(Map<String, RankingExpressionFunction> functions, Map<String, Value> constants) {
+ for (Map.Entry<String, RankingExpressionFunction> functionEntry : functions.entrySet()) {
+ if (constants.get(functionEntry.getKey()) != null)
+ throw new IllegalArgumentException("Cannot have both a constant and function named '" +
+ functionEntry.getKey() + "'");
}
}
- private Map<String, RankingExpressionFunction> getInlineMacros() {
- return getMacros().entrySet().stream().filter(x -> x.getValue().inline())
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ private Map<String, RankingExpressionFunction> getInlineFunctions() {
+ return getFunctions().entrySet().stream().filter(x -> x.getValue().inline())
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
- private Map<String, RankingExpressionFunction> compileMacros(Map<String, RankingExpressionFunction> macros,
- QueryProfileRegistry queryProfiles,
- ImportedModels importedModels,
- Map<String, RankingExpressionFunction> inlineMacros,
- ExpressionTransforms expressionTransforms) {
- Map<String, RankingExpressionFunction> compiledMacros = new LinkedHashMap<>();
- for (Map.Entry<String, RankingExpressionFunction> entry : macros.entrySet()) {
+ private Map<String, RankingExpressionFunction> compileFunctions(Map<String, RankingExpressionFunction> functions,
+ QueryProfileRegistry queryProfiles,
+ ImportedModels importedModels,
+ Map<String, RankingExpressionFunction> inlineFunctions,
+ ExpressionTransforms expressionTransforms) {
+ Map<String, RankingExpressionFunction> compiledFunctions = new LinkedHashMap<>();
+ for (Map.Entry<String, RankingExpressionFunction> entry : functions.entrySet()) {
RankingExpressionFunction rankingExpressionFunction = entry.getValue();
- RankingExpression compiled = compile(rankingExpressionFunction.function().getBody(), queryProfiles, importedModels, getConstants(), inlineMacros, expressionTransforms);
- compiledMacros.put(entry.getKey(), rankingExpressionFunction.withBody(compiled));
+ RankingExpression compiled = compile(rankingExpressionFunction.function().getBody(), queryProfiles, importedModels, getConstants(), inlineFunctions, expressionTransforms);
+ compiledFunctions.put(entry.getKey(), rankingExpressionFunction.withBody(compiled));
}
- return compiledMacros;
+ return compiledFunctions;
}
private RankingExpression compile(RankingExpression expression,
QueryProfileRegistry queryProfiles,
ImportedModels importedModels,
Map<String, Value> constants,
- Map<String, RankingExpressionFunction> inlineMacros,
+ Map<String, RankingExpressionFunction> inlineFunctions,
ExpressionTransforms expressionTransforms) {
if (expression == null) return null;
RankProfileTransformContext context = new RankProfileTransformContext(this,
queryProfiles,
importedModels,
constants,
- inlineMacros);
+ inlineFunctions);
expression = expressionTransforms.transform(expression, context);
for (Map.Entry<String, String> rankProperty : context.rankProperties().entrySet()) {
addRankProperty(rankProperty.getKey(), rankProperty.getValue());
@@ -777,9 +777,9 @@ public class RankProfile implements Serializable, Cloneable {
* referable from this rank profile.
*/
public TypeContext<Reference> typeContext(QueryProfileRegistry queryProfiles) {
- MapEvaluationTypeContext context = new MapEvaluationTypeContext(getMacros().values().stream()
- .map(RankingExpressionFunction::function)
- .collect(Collectors.toList()));
+ MapEvaluationTypeContext context = new MapEvaluationTypeContext(getFunctions().values().stream()
+ .map(RankingExpressionFunction::function)
+ .collect(Collectors.toList()));
// Add small and large constants, respectively
getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type()));
@@ -950,7 +950,7 @@ public class RankProfile implements Serializable, Cloneable {
private final ExpressionFunction function;
- /** True if this should be inlined into calling expressions. Useful for very cheap macros. */
+ /** True if this should be inlined into calling expressions. Useful for very cheap functions. */
private final boolean inline;
public RankingExpressionFunction(ExpressionFunction function, boolean inline) {
@@ -961,7 +961,7 @@ public class RankProfile implements Serializable, Cloneable {
public ExpressionFunction function() { return function; }
public boolean inline() {
- return inline && function.arguments().isEmpty(); // only inline no-arg macros;
+ return inline && function.arguments().isEmpty(); // only inline no-arg functions;
}
public RankingExpressionFunction withBody(RankingExpression expression) {
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java
index 98d147aca79..c041d5c6a89 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java
@@ -175,57 +175,57 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
rankScoreDropLimit = rankProfile.getRankScoreDropLimit();
ignoreDefaultRankFeatures = rankProfile.getIgnoreDefaultRankFeatures();
rankProperties = new ArrayList<>(rankProfile.getRankProperties());
- derivePropertiesAndSummaryFeaturesFromMacros(rankProfile.getMacros());
+ derivePropertiesAndSummaryFeaturesFromFunctions(rankProfile.getFunctions());
}
- private void derivePropertiesAndSummaryFeaturesFromMacros(Map<String, RankProfile.RankingExpressionFunction> macros) {
- if (macros.isEmpty()) return;
- Map<String, ExpressionFunction> expressionMacros = new LinkedHashMap<>();
- for (Map.Entry<String, RankProfile.RankingExpressionFunction> macro : macros.entrySet()) {
- expressionMacros.put(macro.getKey(), macro.getValue().function());
+ private void derivePropertiesAndSummaryFeaturesFromFunctions(Map<String, RankProfile.RankingExpressionFunction> functions) {
+ if (functions.isEmpty()) return;
+ Map<String, ExpressionFunction> expressionFunctions = new LinkedHashMap<>();
+ for (Map.Entry<String, RankProfile.RankingExpressionFunction> function : functions.entrySet()) {
+ expressionFunctions.put(function.getKey(), function.getValue().function());
}
- Map<String, String> macroProperties = new LinkedHashMap<>();
- macroProperties.putAll(deriveMacroProperties(expressionMacros));
+ Map<String, String> functionProperties = new LinkedHashMap<>();
+ functionProperties.putAll(deriveFunctionProperties(expressionFunctions));
if (firstPhaseRanking != null) {
- macroProperties.putAll(firstPhaseRanking.getRankProperties(new ArrayList<>(expressionMacros.values())));
+ functionProperties.putAll(firstPhaseRanking.getRankProperties(new ArrayList<>(expressionFunctions.values())));
}
if (secondPhaseRanking != null) {
- macroProperties.putAll(secondPhaseRanking.getRankProperties(new ArrayList<>(expressionMacros.values())));
+ functionProperties.putAll(secondPhaseRanking.getRankProperties(new ArrayList<>(expressionFunctions.values())));
}
- for (Map.Entry<String, String> e : macroProperties.entrySet()) {
+ for (Map.Entry<String, String> e : functionProperties.entrySet()) {
rankProperties.add(new RankProfile.RankProperty(e.getKey(), e.getValue()));
}
- SerializationContext context = new SerializationContext(expressionMacros.values(), null, macroProperties);
- replaceMacroSummaryFeatures(context);
+ SerializationContext context = new SerializationContext(expressionFunctions.values(), null, functionProperties);
+ replaceFunctionSummaryFeatures(context);
}
- private Map<String, String> deriveMacroProperties(Map<String, ExpressionFunction> eMacros) {
- SerializationContext context = new SerializationContext(eMacros);
- for (Map.Entry<String, ExpressionFunction> e : eMacros.entrySet()) {
+ private Map<String, String> deriveFunctionProperties(Map<String, ExpressionFunction> functions) {
+ SerializationContext context = new SerializationContext(functions);
+ for (Map.Entry<String, ExpressionFunction> e : functions.entrySet()) {
String expression = e.getValue().getBody().getRoot().toString(new StringBuilder(), context, null, null).toString();
context.addFunctionSerialization(RankingExpression.propertyName(e.getKey()), expression);
}
return context.serializedFunctions();
}
- private void replaceMacroSummaryFeatures(SerializationContext context) {
+ private void replaceFunctionSummaryFeatures(SerializationContext context) {
if (summaryFeatures == null) return;
- Map<String, ReferenceNode> macroSummaryFeatures = new LinkedHashMap<>();
+ Map<String, ReferenceNode> functionSummaryFeatures = new LinkedHashMap<>();
for (Iterator<ReferenceNode> i = summaryFeatures.iterator(); i.hasNext(); ) {
ReferenceNode referenceNode = i.next();
- // Is the feature a macro?
+ // Is the feature a function?
if (context.getFunction(referenceNode.getName()) != null) {
context.addFunctionSerialization(RankingExpression.propertyName(referenceNode.getName()),
referenceNode.toString(new StringBuilder(), context, null, null).toString());
ReferenceNode newReferenceNode = new ReferenceNode("rankingExpression(" + referenceNode.getName() + ")", referenceNode.getArguments().expressions(), referenceNode.getOutput());
- macroSummaryFeatures.put(referenceNode.getName(), newReferenceNode);
+ functionSummaryFeatures.put(referenceNode.getName(), newReferenceNode);
i.remove(); // Will add the expanded one in next block
}
}
- // Then, replace the summary features that were macros
- for (Map.Entry<String, ReferenceNode> e : macroSummaryFeatures.entrySet()) {
+ // Then, replace the summary features that were functions
+ for (Map.Entry<String, ReferenceNode> e : functionSummaryFeatures.entrySet()) {
summaryFeatures.add(e.getValue());
}
}
@@ -295,7 +295,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
List<Pair<String, String>> properties = new ArrayList<>();
for (RankProfile.RankProperty property : rankProperties) {
if ("rankingExpression(firstphase).rankingScript".equals(property.getName())) {
- // Could have been set by macro expansion. Set expressions, then skip this property.
+ // Could have been set by function expansion. Set expressions, then skip this property.
try {
firstPhaseRanking = new RankingExpression(property.getValue());
} catch (ParseException e) {
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ExpressionTransforms.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ExpressionTransforms.java
index a639165d297..cbabfffb7a1 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ExpressionTransforms.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ExpressionTransforms.java
@@ -28,8 +28,8 @@ public class ExpressionTransforms {
new XgboostFeatureConverter(),
new ConstantDereferencer(),
new ConstantTensorTransformer(),
- new MacroInliner(),
- new MacroShadower(),
+ new FunctionInliner(),
+ new FunctionShadower(),
new TensorTransformer(),
new Simplifier());
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroInliner.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionInliner.java
index 155568825e0..c15ef20a455 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroInliner.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionInliner.java
@@ -8,11 +8,11 @@ import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode;
import com.yahoo.searchlib.rankingexpression.transform.ExpressionTransformer;
/**
- * Inlines macros in ranking expressions
+ * Inlines functions in ranking expressions
*
* @author bratseth
*/
-public class MacroInliner extends ExpressionTransformer<RankProfileTransformContext> {
+public class FunctionInliner extends ExpressionTransformer<RankProfileTransformContext> {
@Override
public ExpressionNode transform(ExpressionNode node, RankProfileTransformContext context) {
@@ -24,7 +24,7 @@ public class MacroInliner extends ExpressionTransformer<RankProfileTransformCont
}
private ExpressionNode transformFeatureNode(ReferenceNode feature, RankProfileTransformContext context) {
- RankProfile.RankingExpressionFunction rankingExpressionFunction = context.inlineMacros().get(feature.getName());
+ RankProfile.RankingExpressionFunction rankingExpressionFunction = context.inlineFunctions().get(feature.getName());
if (rankingExpressionFunction == null) return feature;
return transform(rankingExpressionFunction.function().getBody().getRoot(), context); // inline recursively and return
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroShadower.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java
index 62315257c2c..74b6471d291 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroShadower.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/FunctionShadower.java
@@ -10,19 +10,19 @@ import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode;
import com.yahoo.searchlib.rankingexpression.transform.ExpressionTransformer;
/**
- * Transforms function nodes to reference nodes if a macro shadows a built-in function.
- * This has the effect of allowing macros to redefine built-in functions.
- * Another effect is that we can more or less add built-in functions over time
- * without fear of breaking existing users' macros with the same name.
+ * Transforms function nodes to reference nodes if a rank profile function shadows a built-in function.
+ * This has the effect of allowing rank profile functions to redefine built-in functions.
+ * Another effect is that we can add built-in functions over time
+ * without fear of breaking existing users' functions with the same name.
*
- * However, there is a (largish) caveat. If a user has a macro with a certain number
+ * However, there is a (largish) caveat. If a user has a function with a certain number
* of arguments, and we add in a built-in function with a different arity,
* this will cause parse errors as the Java parser gives precedence to
* built-in functions.
*
* @author lesters
*/
-public class MacroShadower extends ExpressionTransformer<RankProfileTransformContext> {
+public class FunctionShadower extends ExpressionTransformer<RankProfileTransformContext> {
@Override
public RankingExpression transform(RankingExpression expression, RankProfileTransformContext context) {
@@ -43,7 +43,7 @@ public class MacroShadower extends ExpressionTransformer<RankProfileTransformCon
private ExpressionNode transformFunctionNode(FunctionNode function, RankProfileTransformContext context) {
String name = function.getFunction().toString();
- RankProfile.RankingExpressionFunction rankingExpressionFunction = context.rankProfile().getMacros().get(name);
+ RankProfile.RankingExpressionFunction rankingExpressionFunction = context.rankProfile().getFunctions().get(name);
if (rankingExpressionFunction == null) {
return transformChildren(function, context);
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java
index f45ef359338..2fe2dacf2ce 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java
@@ -20,25 +20,25 @@ public class RankProfileTransformContext extends TransformContext {
private final RankProfile rankProfile;
private final QueryProfileRegistry queryProfiles;
private final ImportedModels importedModels;
- private final Map<String, RankProfile.RankingExpressionFunction> inlineMacros;
+ private final Map<String, RankProfile.RankingExpressionFunction> inlineFunctions;
private final Map<String, String> rankProperties = new HashMap<>();
public RankProfileTransformContext(RankProfile rankProfile,
QueryProfileRegistry queryProfiles,
ImportedModels importedModels,
Map<String, Value> constants,
- Map<String, RankProfile.RankingExpressionFunction> inlineMacros) {
+ Map<String, RankProfile.RankingExpressionFunction> inlineFunctions) {
super(constants);
this.rankProfile = rankProfile;
this.queryProfiles = queryProfiles;
this.importedModels = importedModels;
- this.inlineMacros = inlineMacros;
+ this.inlineFunctions = inlineFunctions;
}
public RankProfile rankProfile() { return rankProfile; }
public QueryProfileRegistry queryProfiles() { return queryProfiles; }
public ImportedModels importedModels() { return importedModels; }
- public Map<String, RankProfile.RankingExpressionFunction> inlineMacros() { return inlineMacros; }
+ public Map<String, RankProfile.RankingExpressionFunction> inlineFunctions() { return inlineFunctions; }
public Map<String, String> rankProperties() { return rankProperties; }
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
index 19025d37f8c..fdef93e21ed 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
@@ -74,7 +74,7 @@ public class Processing {
RankProfileTypeSettingsProcessor::new,
ReferenceFieldsProcessor::new,
FastAccessValidator::new,
- ReservedMacroNames::new,
+ ReservedFunctionNames::new,
RankingExpressionTypeValidator::new,
// These should be last.
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedMacroNames.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java
index adcebed9254..8aa8ff56756 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedMacroNames.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReservedFunctionNames.java
@@ -13,16 +13,16 @@ import java.util.Set;
import java.util.logging.Level;
/**
- * Issues a warning if some macro has a reserved name. This is not necessarily
- * an error, as a macro can shadow a built-in function.
+ * Issues a warning if some function has a reserved name. This is not necessarily
+ * an error, as a rank profile function can shadow a built-in function.
*
* @author lesters
*/
-public class ReservedMacroNames extends Processor {
+public class ReservedFunctionNames extends Processor {
private static Set<String> reservedNames = getReservedNames();
- public ReservedMacroNames(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
+ public ReservedFunctionNames(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(search, deployLogger, rankProfileRegistry, queryProfiles);
}
@@ -31,11 +31,11 @@ public class ReservedMacroNames extends Processor {
if ( ! validate) return;
for (RankProfile rp : rankProfileRegistry.all()) {
- for (String macroName : rp.getMacros().keySet()) {
- if (reservedNames.contains(macroName)) {
- deployLogger.log(Level.WARNING, "Macro \"" + macroName + "\" " +
- "in rank profile \"" + rp.getName() + "\" " +
- "has a reserved name. This might mean that the macro shadows " +
+ for (String functionName : rp.getFunctions().keySet()) {
+ if (reservedNames.contains(functionName)) {
+ deployLogger.log(Level.WARNING, "Funcion '" + functionName + "' " +
+ "in rank profile '" + rp.getName() + "' " +
+ "has a reserved name. This might mean that the function shadows " +
"the built-in function with the same name."
);
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java
index bc2b2f70eae..4b70b1b5ae2 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java
@@ -237,7 +237,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri
ConvertedModel convertedModel = ConvertedModel.fromSource(new ModelName(model.name()),
model.name(), profile, queryProfiles, model);
for (Map.Entry<String, RankingExpression> entry : convertedModel.expressions().entrySet()) {
- profile.addMacro(new ExpressionFunction(entry.getKey(), entry.getValue()), false);
+ profile.addFunction(new ExpressionFunction(entry.getKey(), entry.getValue()), false);
}
}
}
@@ -249,7 +249,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri
rankProfileRegistry.add(profile);
ConvertedModel convertedModel = ConvertedModel.fromStore(new ModelName(modelName), modelName, profile);
for (Map.Entry<String, RankingExpression> entry : convertedModel.expressions().entrySet()) {
- profile.addMacro(new ExpressionFunction(entry.getKey(), entry.getValue()), false);
+ profile.addFunction(new ExpressionFunction(entry.getKey(), entry.getValue()), false);
}
}
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java b/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java
index ffc3c53fdb6..adf5c81283e 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/ml/ConvertedModel.java
@@ -140,7 +140,7 @@ public class ConvertedModel {
public ExpressionNode expression(FeatureArguments arguments, RankProfileTransformContext context) {
RankingExpression expression = selectExpression(arguments);
if (sourceModel.isPresent()) // we can verify
- verifyRequiredMacros(expression, sourceModel.get(), context.rankProfile(), context.queryProfiles());
+ verifyRequiredFunctions(expression, sourceModel.get(), context.rankProfile(), context.queryProfiles());
return expression.getRoot();
}
@@ -184,41 +184,41 @@ public class ConvertedModel {
QueryProfileRegistry queryProfiles,
ModelStore store) {
// Add constants
- Set<String> constantsReplacedByMacros = new HashSet<>();
+ Set<String> constantsReplacedByFunctions = new HashSet<>();
model.smallConstants().forEach((k, v) -> transformSmallConstant(store, profile, k, v));
model.largeConstants().forEach((k, v) -> transformLargeConstant(store, profile, queryProfiles,
- constantsReplacedByMacros, k, v));
+ constantsReplacedByFunctions, k, v));
- // Add macros
- addGeneratedMacros(model, profile);
+ // Add functions
+ addGeneratedFunctions(model, profile);
// Add expressions
Map<String, RankingExpression> expressions = new HashMap<>();
for (Pair<String, RankingExpression> output : model.outputExpressions()) {
addExpression(output.getSecond(), output.getFirst(),
- constantsReplacedByMacros,
+ constantsReplacedByFunctions,
model, store, profile, queryProfiles,
expressions);
}
- // Transform and save macro - must come after reading expressions due to optimization transforms
- // and must use the macro expression added to the profile, which may differ from the one saved in the model,
+ // Transform and save function - must come after reading expressions due to optimization transforms
+ // and must use the function expression added to the profile, which may differ from the one saved in the model,
// after rewrite
- model.macros().forEach((k, v) -> transformGeneratedMacro(store, constantsReplacedByMacros, k,
- profile.getMacros().get(k).function().getBody()));
+ model.functions().forEach((k, v) -> transformGeneratedFunction(store, constantsReplacedByFunctions, k,
+ profile.getFunctions().get(k).function().getBody()));
return expressions;
}
private static void addExpression(RankingExpression expression,
String expressionName,
- Set<String> constantsReplacedByMacros,
+ Set<String> constantsReplacedByFunctions,
ImportedModel model,
ModelStore store,
RankProfile profile,
QueryProfileRegistry queryProfiles,
Map<String, RankingExpression> expressions) {
- expression = replaceConstantsByMacros(expression, constantsReplacedByMacros);
+ expression = replaceConstantsByFunctions(expression, constantsReplacedByFunctions);
reduceBatchDimensions(expression, model, profile, queryProfiles);
store.writeExpression(expressionName, expression);
expressions.put(expressionName, expression);
@@ -233,8 +233,8 @@ public class ConvertedModel {
profile.rankingConstants().add(constant);
}
- for (Pair<String, RankingExpression> macro : store.readMacros()) {
- addGeneratedMacroToProfile(profile, macro.getFirst(), macro.getSecond());
+ for (Pair<String, RankingExpression> function : store.readFunctions()) {
+ addGeneratedFunctionToProfile(profile, function.getFirst(), function.getSecond());
}
return store.readExpressions();
@@ -248,16 +248,16 @@ public class ConvertedModel {
private static void transformLargeConstant(ModelStore store,
RankProfile profile,
QueryProfileRegistry queryProfiles,
- Set<String> constantsReplacedByMacros,
+ Set<String> constantsReplacedByFunctions,
String constantName,
Tensor constantValue) {
- RankProfile.RankingExpressionFunction rankingExpressionFunctionOverridingConstant = profile.getMacros().get(constantName);
+ RankProfile.RankingExpressionFunction rankingExpressionFunctionOverridingConstant = profile.getFunctions().get(constantName);
if (rankingExpressionFunctionOverridingConstant != null) {
- TensorType macroType = rankingExpressionFunctionOverridingConstant.function().getBody().type(profile.typeContext(queryProfiles));
- if ( ! macroType.equals(constantValue.type()))
- throw new IllegalArgumentException("Macro '" + constantName + "' replaces the constant with this name. " +
- typeMismatchExplanation(constantValue.type(), macroType));
- constantsReplacedByMacros.add(constantName); // will replace constant(constantName) by constantName later
+ TensorType functionType = rankingExpressionFunctionOverridingConstant.function().getBody().type(profile.typeContext(queryProfiles));
+ if ( ! functionType.equals(constantValue.type()))
+ throw new IllegalArgumentException("Function '" + constantName + "' replaces the constant with this name. " +
+ typeMismatchExplanation(constantValue.type(), functionType));
+ constantsReplacedByFunctions.add(constantName); // will replace constant(constantName) by constantName later
}
else {
Path constantPath = store.writeLargeConstant(constantName, constantValue);
@@ -268,77 +268,75 @@ public class ConvertedModel {
}
}
- private static void transformGeneratedMacro(ModelStore store,
- Set<String> constantsReplacedByMacros,
- String macroName,
- RankingExpression expression) {
+ private static void transformGeneratedFunction(ModelStore store,
+ Set<String> constantsReplacedByFunctions,
+ String functionName,
+ RankingExpression expression) {
- expression = replaceConstantsByMacros(expression, constantsReplacedByMacros);
- store.writeMacro(macroName, expression);
+ expression = replaceConstantsByFunctions(expression, constantsReplacedByFunctions);
+ store.writeFunction(functionName, expression);
}
- private static void addGeneratedMacroToProfile(RankProfile profile, String macroName, RankingExpression expression) {
- if (profile.getMacros().containsKey(macroName)) {
- if ( ! profile.getMacros().get(macroName).function().getBody().equals(expression))
- throw new IllegalArgumentException("Generated macro '" + macroName + "' already exists in " + profile +
+ private static void addGeneratedFunctionToProfile(RankProfile profile, String functionName, RankingExpression expression) {
+ if (profile.getFunctions().containsKey(functionName)) {
+ if ( ! profile.getFunctions().get(functionName).function().getBody().equals(expression))
+ throw new IllegalArgumentException("Generated function '" + functionName + "' already exists in " + profile +
" - with a different definition" +
- ": Has\n" + profile.getMacros().get(macroName).function().getBody() +
+ ": Has\n" + profile.getFunctions().get(functionName).function().getBody() +
"\nwant to add " + expression + "\n");
return;
}
- profile.addMacro(new ExpressionFunction(macroName, expression), false); // TODO: Inline if only used once
+ profile.addFunction(new ExpressionFunction(functionName, expression), false); // TODO: Inline if only used once
}
/**
- * Verify that the macros referred in the given expression exists in the given rank profile,
- * and return tensors of the types specified in requiredMacros.
+ * Verify that the functions referred in the given expression exists in the given rank profile,
+ * and return tensors of the types specified in requiredFunctions.
*/
- private static void verifyRequiredMacros(RankingExpression expression, ImportedModel model,
- RankProfile profile, QueryProfileRegistry queryProfiles) {
- Set<String> macroNames = new HashSet<>();
- addMacroNamesIn(expression.getRoot(), macroNames, model);
- for (String macroName : macroNames) {
- TensorType requiredType = model.requiredMacros().get(macroName);
- if (requiredType == null) continue; // Not a required macro
-
- RankProfile.RankingExpressionFunction rankingExpressionFunction = profile.getMacros().get(macroName);
+ private static void verifyRequiredFunctions(RankingExpression expression, ImportedModel model,
+ RankProfile profile, QueryProfileRegistry queryProfiles) {
+ Set<String> functionNames = new HashSet<>();
+ addFunctionNamesIn(expression.getRoot(), functionNames, model);
+ for (String functionName : functionNames) {
+ TensorType requiredType = model.requiredFunctions().get(functionName);
+ if (requiredType == null) continue; // Not a required function
+
+ RankProfile.RankingExpressionFunction rankingExpressionFunction = profile.getFunctions().get(functionName);
if (rankingExpressionFunction == null)
- throw new IllegalArgumentException("Model refers input '" + macroName +
- "' of type " + requiredType + " but this macro is not present in " +
+ throw new IllegalArgumentException("Model refers input '" + functionName +
+ "' of type " + requiredType + " but this function is not present in " +
profile);
// TODO: We should verify this in the (function reference(s) this is invoked (starting from first/second
// phase and summary features), as it may only resolve correctly given those bindings
- // Or, probably better, annotate the macros with type constraints here and verify during general
+ // Or, probably better, annotate the functions with type constraints here and verify during general
// type verification
TensorType actualType = rankingExpressionFunction.function().getBody().getRoot().type(profile.typeContext(queryProfiles));
if ( actualType == null)
- throw new IllegalArgumentException("Model refers input '" + macroName +
+ throw new IllegalArgumentException("Model refers input '" + functionName +
"' of type " + requiredType +
- " which must be produced by a macro in the rank profile, but " +
- "this macro references a feature which is not declared");
+ " which must be produced by a function in the rank profile, but " +
+ "this function references a feature which is not declared");
if ( ! actualType.isAssignableTo(requiredType))
- throw new IllegalArgumentException("Model refers input '" + macroName + "'. " +
+ throw new IllegalArgumentException("Model refers input '" + functionName + "'. " +
typeMismatchExplanation(requiredType, actualType));
}
}
private static String typeMismatchExplanation(TensorType requiredType, TensorType actualType) {
- return "The required type of this is " + requiredType + ", but this macro returns " + actualType +
+ return "The required type of this is " + requiredType + ", but this function returns " + actualType +
(actualType.rank() == 0 ? ". This is often due to missing declaration of query tensor features " +
"in query profile types - see the documentation."
: "");
}
- /**
- * Add the generated macros to the rank profile
- */
- private static void addGeneratedMacros(ImportedModel model, RankProfile profile) {
- model.macros().forEach((k, v) -> addGeneratedMacroToProfile(profile, k, v.copy()));
+ /** Add the generated functions to the rank profile */
+ private static void addGeneratedFunctions(ImportedModel model, RankProfile profile) {
+ model.functions().forEach((k, v) -> addGeneratedFunctionToProfile(profile, k, v.copy()));
}
/**
* Check if batch dimensions of inputs can be reduced out. If the input
- * macro specifies that a single exemplar should be evaluated, we can
+ * function specifies that a single exemplar should be evaluated, we can
* reduce the batch dimension out.
*/
private static void reduceBatchDimensions(RankingExpression expression, ImportedModel model,
@@ -346,19 +344,19 @@ public class ConvertedModel {
TypeContext<Reference> typeContext = profile.typeContext(queryProfiles);
TensorType typeBeforeReducing = expression.getRoot().type(typeContext);
- // Check generated macros for inputs to reduce
- Set<String> macroNames = new HashSet<>();
- addMacroNamesIn(expression.getRoot(), macroNames, model);
- for (String macroName : macroNames) {
- if ( ! model.macros().containsKey(macroName)) continue;
+ // Check generated functions for inputs to reduce
+ Set<String> functionNames = new HashSet<>();
+ addFunctionNamesIn(expression.getRoot(), functionNames, model);
+ for (String functionName : functionNames) {
+ if ( ! model.functions().containsKey(functionName)) continue;
- RankProfile.RankingExpressionFunction rankingExpressionFunction = profile.getMacros().get(macroName);
+ RankProfile.RankingExpressionFunction rankingExpressionFunction = profile.getFunctions().get(functionName);
if (rankingExpressionFunction == null) {
- throw new IllegalArgumentException("Model refers to generated macro '" + macroName +
- "but this macro is not present in " + profile);
+ throw new IllegalArgumentException("Model refers to generated function '" + functionName +
+ "but this function is not present in " + profile);
}
- RankingExpression macroExpression = rankingExpressionFunction.function().getBody();
- macroExpression.setRoot(reduceBatchDimensionsAtInput(macroExpression.getRoot(), model, typeContext));
+ RankingExpression functionExpression = rankingExpressionFunction.function().getBody();
+ functionExpression.setRoot(reduceBatchDimensionsAtInput(functionExpression.getRoot(), model, typeContext));
}
// Check expression for inputs to reduce
@@ -377,7 +375,7 @@ public class ConvertedModel {
List<ExpressionNode> children = ((TensorFunctionNode)node).children();
if (children.size() == 1 && children.get(0) instanceof ReferenceNode) {
ReferenceNode referenceNode = (ReferenceNode) children.get(0);
- if (model.requiredMacros().containsKey(referenceNode.getName())) {
+ if (model.requiredFunctions().containsKey(referenceNode.getName())) {
return reduceBatchDimensionExpression(tensorFunction, typeContext);
}
}
@@ -385,7 +383,7 @@ public class ConvertedModel {
}
if (node instanceof ReferenceNode) {
ReferenceNode referenceNode = (ReferenceNode) node;
- if (model.requiredMacros().containsKey(referenceNode.getName())) {
+ if (model.requiredFunctions().containsKey(referenceNode.getName())) {
return reduceBatchDimensionExpression(TensorFunctionNode.wrapArgument(node), typeContext);
}
}
@@ -446,47 +444,47 @@ public class ConvertedModel {
}
/**
- * If a constant c is overridden by a macro, we need to replace instances of "constant(c)" by "c" in expressions.
+ * If a constant c is overridden by a function, we need to replace instances of "constant(c)" by "c" in expressions.
* This method does that for the given expression and returns the result.
*/
- private static RankingExpression replaceConstantsByMacros(RankingExpression expression,
- Set<String> constantsReplacedByMacros) {
- if (constantsReplacedByMacros.isEmpty()) return expression;
+ private static RankingExpression replaceConstantsByFunctions(RankingExpression expression,
+ Set<String> constantsReplacedByFunctions) {
+ if (constantsReplacedByFunctions.isEmpty()) return expression;
return new RankingExpression(expression.getName(),
- replaceConstantsByMacros(expression.getRoot(), constantsReplacedByMacros));
+ replaceConstantsByFunctions(expression.getRoot(), constantsReplacedByFunctions));
}
- private static ExpressionNode replaceConstantsByMacros(ExpressionNode node, Set<String> constantsReplacedByMacros) {
+ private static ExpressionNode replaceConstantsByFunctions(ExpressionNode node, Set<String> constantsReplacedByFunctions) {
if (node instanceof ReferenceNode) {
Reference reference = ((ReferenceNode)node).reference();
if (FeatureNames.isSimpleFeature(reference) && reference.name().equals("constant")) {
String argument = reference.simpleArgument().get();
- if (constantsReplacedByMacros.contains(argument))
+ if (constantsReplacedByFunctions.contains(argument))
return new ReferenceNode(argument);
}
}
if (node instanceof CompositeNode) { // not else: this matches some of the same nodes as the outer if above
CompositeNode composite = (CompositeNode)node;
return composite.setChildren(composite.children().stream()
- .map(child -> replaceConstantsByMacros(child, constantsReplacedByMacros))
+ .map(child -> replaceConstantsByFunctions(child, constantsReplacedByFunctions))
.collect(Collectors.toList()));
}
return node;
}
- private static void addMacroNamesIn(ExpressionNode node, Set<String> names, ImportedModel model) {
+ private static void addFunctionNamesIn(ExpressionNode node, Set<String> names, ImportedModel model) {
if (node instanceof ReferenceNode) {
ReferenceNode referenceNode = (ReferenceNode)node;
- if (referenceNode.getOutput() == null) { // macro references cannot specify outputs
+ if (referenceNode.getOutput() == null) { // function references cannot specify outputs
names.add(referenceNode.getName());
- if (model.macros().containsKey(referenceNode.getName())) {
- addMacroNamesIn(model.macros().get(referenceNode.getName()).getRoot(), names, model);
+ if (model.functions().containsKey(referenceNode.getName())) {
+ addFunctionNamesIn(model.functions().get(referenceNode.getName()).getRoot(), names, model);
}
}
}
else if (node instanceof CompositeNode) {
for (ExpressionNode child : ((CompositeNode)node).children())
- addMacroNamesIn(child, names, model);
+ addFunctionNamesIn(child, names, model);
}
}
@@ -550,19 +548,19 @@ public class ConvertedModel {
return expressions;
}
- /** Adds this macro expression to the application package so it can be read later. */
- void writeMacro(String name, RankingExpression expression) {
- application.getFile(modelFiles.macrosPath()).appendFile(name + "\t" +
- expression.getRoot().toString() + "\n");
+ /** Adds this function expression to the application package so it can be read later. */
+ void writeFunction(String name, RankingExpression expression) {
+ application.getFile(modelFiles.functionsPath()).appendFile(name + "\t" +
+ expression.getRoot().toString() + "\n");
}
- /** Reads the previously stored macro expressions for these arguments */
- List<Pair<String, RankingExpression>> readMacros() {
+ /** Reads the previously stored function expressions for these arguments */
+ List<Pair<String, RankingExpression>> readFunctions() {
try {
- ApplicationFile file = application.getFile(modelFiles.macrosPath());
+ ApplicationFile file = application.getFile(modelFiles.functionsPath());
if ( ! file.exists()) return Collections.emptyList();
- List<Pair<String, RankingExpression>> macros = new ArrayList<>();
+ List<Pair<String, RankingExpression>> functions = new ArrayList<>();
BufferedReader reader = new BufferedReader(file.createReader());
String line;
while (null != (line = reader.readLine())) {
@@ -570,13 +568,13 @@ public class ConvertedModel {
String name = parts[0];
try {
RankingExpression expression = new RankingExpression(parts[0], parts[1]);
- macros.add(new Pair<>(name, expression));
+ functions.add(new Pair<>(name, expression));
}
catch (ParseException e) {
throw new IllegalStateException("Could not parse " + name, e);
}
}
- return macros;
+ return functions;
}
catch (IOException e) {
throw new UncheckedIOException(e);
@@ -724,9 +722,9 @@ public class ConvertedModel {
return storedModelReplicatedPath().append("constants");
}
- /** Path to the macros file */
- public Path macrosPath() {
- return storedModelReplicatedPath().append("macros.txt");
+ /** Path to the functions file */
+ public Path functionsPath() {
+ return storedModelReplicatedPath().append("functions.txt");
}
}
diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj
index 2c60ab3771b..21edbb7eb58 100644
--- a/config-model/src/main/javacc/SDParser.jj
+++ b/config-model/src/main/javacc/SDParser.jj
@@ -1887,7 +1887,7 @@ Object rankProfileItem(RankProfile profile) : { }
| fieldRankFilter(profile)
| firstPhase(profile)
| matchPhase(profile)
- | macro(profile)
+ | function(profile)
| ignoreRankFeatures(profile)
| numThreadsPerSearch(profile)
| minHitsPerThread(profile)
@@ -1920,7 +1920,7 @@ void inheritsRankProfile(RankProfile profile) :
*
* @param profile The profile to modify.
*/
-void macro(RankProfile profile) :
+void function(RankProfile profile) :
{
String name, expression, parameter;
List parameters = new ArrayList();
@@ -1933,7 +1933,7 @@ void macro(RankProfile profile) :
( <COMMA> parameter = identifier() { parameters.add(parameter); } )* ]
")"
lbrace() expression = expression() (<NL>)* <RBRACE> )
- { profile.addMacro(name, parameters, expression, inline); }
+ { profile.addFunction(name, parameters, expression, inline); }
}
boolean inline() :
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
index 7b262bdc4d0..fda4bdeea47 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
@@ -45,11 +45,11 @@ public class RankProfileRegistryTest {
RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(search);
for (String rankProfileName : RankProfileRegistry.overridableRankProfileNames) {
- assertNull(rankProfileRegistry.get(search, rankProfileName).getMacros().get("foo"));
+ assertNull(rankProfileRegistry.get(search, rankProfileName).getFunctions().get("foo"));
RankProfile rankProfileWithAddedMacro = new RankProfile(rankProfileName, search, rankProfileRegistry);
- rankProfileWithAddedMacro.addMacro(new ExpressionFunction("foo", RankingExpression.from("1+2")), true);
+ rankProfileWithAddedMacro.addFunction(new ExpressionFunction("foo", RankingExpression.from("1+2")), true);
rankProfileRegistry.add(rankProfileWithAddedMacro);
- assertNotNull(rankProfileRegistry.get(search, rankProfileName).getMacros().get("foo"));
+ assertNotNull(rankProfileRegistry.get(search, rankProfileName).getFunctions().get("foo"));
}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java
index bceafc8e415..6b08c013a07 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionConstantsTestCase.java
@@ -76,7 +76,7 @@ public class RankingExpressionConstantsTestCase extends SearchDefinitionTestCase
RankProfile child2 = rankProfileRegistry.get(s, "child2").compile(queryProfileRegistry, new ImportedModels());
assertEquals("16.6", child2.getFirstPhaseRanking().getRoot().toString());
- assertEquals("foo: 14.0", child2.getMacros().get("foo").function().getBody().toString());
+ assertEquals("foo: 14.0", child2.getFunctions().get("foo").function().getBody().toString());
List<Pair<String, String>> rankProperties = new RawRankProfile(child2,
queryProfileRegistry,
new ImportedModels(),
@@ -114,7 +114,7 @@ public class RankingExpressionConstantsTestCase extends SearchDefinitionTestCase
fail("Should have caused an exception");
}
catch (IllegalArgumentException e) {
- assertEquals("Rank profile 'test' is invalid: Cannot have both a constant and macro named 'c'",
+ assertEquals("Rank profile 'test' is invalid: Cannot have both a constant and function named 'c'",
Exceptions.toMessageString(e));
}
}
@@ -142,7 +142,7 @@ public class RankingExpressionConstantsTestCase extends SearchDefinitionTestCase
Search s = builder.getSearch();
RankProfile profile = rankProfileRegistry.get(s, "test");
profile.parseExpressions(); // TODO: Do differently
- assertEquals("safeLog(popShareSlowDecaySignal,-9.21034037)", profile.getMacros().get("POP_SLOW_SCORE").function().getBody().getRoot().toString());
+ assertEquals("safeLog(popShareSlowDecaySignal,-9.21034037)", profile.getFunctions().get("POP_SLOW_SCORE").function().getBody().getRoot().toString());
}
@Test
@@ -171,9 +171,9 @@ public class RankingExpressionConstantsTestCase extends SearchDefinitionTestCase
Search s = builder.getSearch();
RankProfile profile = rankProfileRegistry.get(s, "test");
profile.parseExpressions(); // TODO: Do differently
- assertEquals("safeLog(popShareSlowDecaySignal,myValue)", profile.getMacros().get("POP_SLOW_SCORE").function().getBody().getRoot().toString());
+ assertEquals("safeLog(popShareSlowDecaySignal,myValue)", profile.getFunctions().get("POP_SLOW_SCORE").function().getBody().getRoot().toString());
assertEquals("safeLog(popShareSlowDecaySignal,-9.21034037)",
- profile.compile(new QueryProfileRegistry(), new ImportedModels()).getMacros().get("POP_SLOW_SCORE").function().getBody().getRoot().toString());
+ profile.compile(new QueryProfileRegistry(), new ImportedModels()).getFunctions().get("POP_SLOW_SCORE").function().getBody().getRoot().toString());
}
@Test
@@ -196,7 +196,7 @@ public class RankingExpressionConstantsTestCase extends SearchDefinitionTestCase
Search s = builder.getSearch();
RankProfile profile = rankProfileRegistry.get(s, "test");
assertEquals("k1 + (k2 + k3) / 100000000.0",
- profile.compile(new QueryProfileRegistry(), new ImportedModels()).getMacros().get("rank_default").function().getBody().getRoot().toString());
+ profile.compile(new QueryProfileRegistry(), new ImportedModels()).getFunctions().get("rank_default").function().getBody().getRoot().toString());
}
@Test
@@ -222,7 +222,7 @@ public class RankingExpressionConstantsTestCase extends SearchDefinitionTestCase
Search s = builder.getSearch();
RankProfile profile = rankProfileRegistry.get(s, "test");
assertEquals("0.5 + 50 * (attribute(rating_yelp) - 3)",
- profile.compile(new QueryProfileRegistry(), new ImportedModels()).getMacros().get("rank_default").function().getBody().getRoot().toString());
+ profile.compile(new QueryProfileRegistry(), new ImportedModels()).getFunctions().get("rank_default").function().getBody().getRoot().toString());
}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java
index 749a97bf12f..0075a781950 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java
@@ -74,7 +74,7 @@ class RankProfileSearchFixture {
public void assertMacro(String expexctedExpression, String macroName, String rankProfile) {
assertEquals(expexctedExpression,
- compiledRankProfile(rankProfile).getMacros().get(macroName).function().getBody().getRoot().toString());
+ compiledRankProfile(rankProfile).getFunctions().get(macroName).function().getBody().getRoot().toString());
}
public RankProfile compileRankProfile(String rankProfile) {
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
index b046d60f948..23ca59edb1c 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
@@ -145,7 +145,7 @@ public class RankingExpressionWithOnnxTestCase {
catch (IllegalArgumentException expected) {
assertEquals("Rank profile 'my_profile' is invalid: Could not use Onnx model from " +
"onnx('mnist_softmax.onnx'): " +
- "Model refers input 'Placeholder' of type tensor(d0[],d1[784]) but this macro is " +
+ "Model refers input 'Placeholder' of type tensor(d0[],d1[784]) but this function is " +
"not present in rank profile 'my_profile'",
Exceptions.toMessageString(expected));
}
@@ -163,7 +163,7 @@ public class RankingExpressionWithOnnxTestCase {
assertEquals("Rank profile 'my_profile' is invalid: Could not use Onnx model from " +
"onnx('mnist_softmax.onnx'): " +
"Model refers input 'Placeholder'. The required type of this is tensor(d0[],d1[784]), " +
- "but this macro returns tensor(d0[2],d5[10])",
+ "but this function returns tensor(d0[2],d5[10])",
Exceptions.toMessageString(expected));
}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java
index 14632a568ea..d8602d438a8 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java
@@ -177,7 +177,7 @@ public class RankingExpressionWithTensorFlowTestCase {
catch (IllegalArgumentException expected) {
assertEquals("Rank profile 'my_profile' is invalid: Could not use tensorflow model from " +
"tensorflow('mnist_softmax/saved'): " +
- "Model refers input 'Placeholder' of type tensor(d0[],d1[784]) but this macro is " +
+ "Model refers input 'Placeholder' of type tensor(d0[],d1[784]) but this function is " +
"not present in rank profile 'my_profile'",
Exceptions.toMessageString(expected));
}
@@ -195,7 +195,7 @@ public class RankingExpressionWithTensorFlowTestCase {
assertEquals("Rank profile 'my_profile' is invalid: Could not use tensorflow model from " +
"tensorflow('mnist_softmax/saved'): " +
"Model refers input 'Placeholder'. The required type of this is tensor(d0[],d1[784]), " +
- "but this macro returns tensor(d0[2],d5[10])",
+ "but this function returns tensor(d0[2],d5[10])",
Exceptions.toMessageString(expected));
}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java
index 76a7a01a3aa..d4fd48cfaca 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java
@@ -27,7 +27,7 @@ public class RankingExpressionsTestCase extends SearchDefinitionTestCase {
new QueryProfileRegistry()).getSearch();
final RankProfile macrosRankProfile = rankProfileRegistry.get(search, "macros");
macrosRankProfile.parseExpressions();
- final Map<String, RankProfile.RankingExpressionFunction> macros = macrosRankProfile.getMacros();
+ final Map<String, RankProfile.RankingExpressionFunction> macros = macrosRankProfile.getFunctions();
assertEquals(2, macros.get("titlematch$").function().arguments().size());
assertEquals("var1", macros.get("titlematch$").function().arguments().get(0));
assertEquals("var2", macros.get("titlematch$").function().arguments().get(1));