diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-09-17 09:11:30 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-09-17 09:11:30 +0200 |
commit | 5a6f9b703f228a6bb5565d5e680f22a3e3059ff0 (patch) | |
tree | 8d14380b2b01ed175da493a3e9c88b06cf8ce4ce /config-model/src | |
parent | 688812e215e1e85d7d486344dc433fd24caa43c2 (diff) |
Refactor: Expose function
Diffstat (limited to 'config-model/src')
7 files changed, 24 insertions, 24 deletions
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 9afced44b1d..98238d886db 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -740,7 +740,7 @@ public class RankProfile implements Serializable, Cloneable { } private Map<String, Macro> getInlineMacros() { - return getMacros().entrySet().stream().filter(x -> x.getValue().getInline()) + return getMacros().entrySet().stream().filter(x -> x.getValue().inline()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } @@ -752,7 +752,7 @@ public class RankProfile implements Serializable, Cloneable { Map<String, Macro> compiledMacros = new LinkedHashMap<>(); for (Map.Entry<String, Macro> entry : macros.entrySet()) { Macro macro = entry.getValue(); - RankingExpression compiled = compile(macro.getRankingExpression(), queryProfiles, importedModels, getConstants(), inlineMacros, expressionTransforms); + RankingExpression compiled = compile(macro.function().getBody(), queryProfiles, importedModels, getConstants(), inlineMacros, expressionTransforms); compiledMacros.put(entry.getKey(), macro.withExpression(compiled)); } return compiledMacros; @@ -783,7 +783,7 @@ public class RankProfile implements Serializable, Cloneable { */ public TypeContext<Reference> typeContext(QueryProfileRegistry queryProfiles) { MapEvaluationTypeContext context = new MapEvaluationTypeContext(getMacros().values().stream() - .map(Macro::asExpressionFunction) + .map(Macro::function) .collect(Collectors.toList())); // Add small and large constants, respectively @@ -981,17 +981,17 @@ public class RankProfile implements Serializable, Cloneable { return function.getName(); } - public boolean getInline() { + public boolean inline() { return inline && function.arguments().isEmpty(); // only inline no-arg macros; } - public ExpressionFunction asExpressionFunction() { - return new ExpressionFunction(getName(), getArguments(), getRankingExpression()); + public ExpressionFunction function() { + return function; } @Override public String toString() { - return "macro " + getName() + ": " + getRankingExpression(); + return "macro " + getName() + ": " + function().getBody(); } } 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 ffd7f74cfe0..d3ba7d4b613 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 @@ -182,7 +182,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer { if (macros.isEmpty()) return; Map<String, ExpressionFunction> expressionMacros = new LinkedHashMap<>(); for (Map.Entry<String, RankProfile.Macro> macro : macros.entrySet()) { - expressionMacros.put(macro.getKey(), macro.getValue().asExpressionFunction()); + expressionMacros.put(macro.getKey(), macro.getValue().function()); } Map<String, String> macroProperties = new LinkedHashMap<>(); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroInliner.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroInliner.java index 6aef39db4da..b5642a5426f 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroInliner.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/MacroInliner.java @@ -26,7 +26,7 @@ public class MacroInliner extends ExpressionTransformer<RankProfileTransformCont private ExpressionNode transformFeatureNode(ReferenceNode feature, RankProfileTransformContext context) { RankProfile.Macro macro = context.inlineMacros().get(feature.getName()); if (macro == null) return feature; - return transform(macro.getRankingExpression().getRoot(), context); // inline recursively and return + return transform(macro.function().getBody().getRoot(), context); // inline recursively and return } } 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 807235d22dd..390fd32f0ba 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 @@ -204,7 +204,7 @@ public class ConvertedModel { // and must use the macro 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).getRankingExpression())); + profile.getMacros().get(k).function().getBody())); return expressions; } @@ -252,7 +252,7 @@ public class ConvertedModel { Tensor constantValue) { RankProfile.Macro macroOverridingConstant = profile.getMacros().get(constantName); if (macroOverridingConstant != null) { - TensorType macroType = macroOverridingConstant.getRankingExpression().type(profile.typeContext(queryProfiles)); + TensorType macroType = macroOverridingConstant.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)); @@ -278,10 +278,10 @@ public class ConvertedModel { private static void addGeneratedMacroToProfile(RankProfile profile, String macroName, RankingExpression expression) { if (profile.getMacros().containsKey(macroName)) { - if ( ! profile.getMacros().get(macroName).getRankingExpression().equals(expression)) + if ( ! profile.getMacros().get(macroName).function().getBody().equals(expression)) throw new IllegalArgumentException("Generated macro '" + macroName + "' already exists in " + profile + " - with a different definition" + - ": Has\n" + profile.getMacros().get(macroName).getRankingExpression() + + ": Has\n" + profile.getMacros().get(macroName).function().getBody() + "\nwant to add " + expression + "\n"); return; } @@ -309,7 +309,7 @@ public class ConvertedModel { // 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 // type verification - TensorType actualType = macro.getRankingExpression().getRoot().type(profile.typeContext(queryProfiles)); + TensorType actualType = macro.function().getBody().getRoot().type(profile.typeContext(queryProfiles)); if ( actualType == null) throw new IllegalArgumentException("Model refers input '" + macroName + "' of type " + requiredType + @@ -356,7 +356,7 @@ public class ConvertedModel { throw new IllegalArgumentException("Model refers to generated macro '" + macroName + "but this macro is not present in " + profile); } - RankingExpression macroExpression = macro.getRankingExpression(); + RankingExpression macroExpression = macro.function().getBody(); macroExpression.setRoot(reduceBatchDimensionsAtInput(macroExpression.getRoot(), model, typeContext)); } 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 a524a26cbef..bceafc8e415 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").getRankingExpression().toString()); + assertEquals("foo: 14.0", child2.getMacros().get("foo").function().getBody().toString()); List<Pair<String, String>> rankProperties = new RawRankProfile(child2, queryProfileRegistry, new ImportedModels(), @@ -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").getRankingExpression().getRoot().toString()); + assertEquals("safeLog(popShareSlowDecaySignal,-9.21034037)", profile.getMacros().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").getRankingExpression().getRoot().toString()); + assertEquals("safeLog(popShareSlowDecaySignal,myValue)", profile.getMacros().get("POP_SLOW_SCORE").function().getBody().getRoot().toString()); assertEquals("safeLog(popShareSlowDecaySignal,-9.21034037)", - profile.compile(new QueryProfileRegistry(), new ImportedModels()).getMacros().get("POP_SLOW_SCORE").getRankingExpression().getRoot().toString()); + profile.compile(new QueryProfileRegistry(), new ImportedModels()).getMacros().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").getRankingExpression().getRoot().toString()); + profile.compile(new QueryProfileRegistry(), new ImportedModels()).getMacros().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").getRankingExpression().getRoot().toString()); + profile.compile(new QueryProfileRegistry(), new ImportedModels()).getMacros().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 f67c85e2881..749a97bf12f 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).getRankingExpression().getRoot().toString()); + compiledRankProfile(rankProfile).getMacros().get(macroName).function().getBody().getRoot().toString()); } public RankProfile compileRankProfile(String rankProfile) { 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 deff4b20139..0f8e6072d53 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 @@ -31,9 +31,9 @@ public class RankingExpressionsTestCase extends SearchDefinitionTestCase { assertEquals(2, macros.get("titlematch$").getArguments().size()); assertEquals("var1", macros.get("titlematch$").getArguments().get(0)); assertEquals("var2", macros.get("titlematch$").getArguments().get(1)); - assertEquals("var1 * var2 + 890", macros.get("titlematch$").getRankingExpression().getRoot().toString()); + assertEquals("var1 * var2 + 890", macros.get("titlematch$").function().getBody().getRoot().toString()); assertEquals("0.8+0.2*titlematch$(4,5)+0.8*titlematch$(7,8)*closeness(distance)", macrosRankProfile.getFirstPhaseRankingString().trim()); - assertEquals("78 + closeness(distance)", macros.get("artistmatch").getRankingExpression().getRoot().toString()); + assertEquals("78 + closeness(distance)", macros.get("artistmatch").function().getBody().getRoot().toString()); assertEquals(0, macros.get("artistmatch").getArguments().size()); List<Pair<String, String>> rankProperties = new RawRankProfile(macrosRankProfile, |