diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-01-31 17:36:21 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-01-31 17:36:21 +0100 |
commit | c56889931e1547a6a6db420a3c886ddf03f5bd6e (patch) | |
tree | a718a9bbacf236c54c8164def703f4e108e7287d /config-model/src/main/java/com/yahoo | |
parent | 2c25a02adbe644b3f50dc44252c6b61974d0c8d6 (diff) |
Canonicalize features
This allows us to find the type of features referenced in
ranking expressions regardless of the form they are written in.
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
2 files changed, 10 insertions, 16 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 cd65c6ef761..136d09304da 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -16,6 +16,7 @@ import com.yahoo.searchdefinition.parser.ParseException; import com.yahoo.searchlib.rankingexpression.ExpressionFunction; import com.yahoo.searchlib.rankingexpression.FeatureList; import com.yahoo.searchlib.rankingexpression.RankingExpression; +import com.yahoo.searchlib.rankingexpression.evaluation.FeatureNames; import com.yahoo.searchlib.rankingexpression.evaluation.TensorValue; import com.yahoo.searchlib.rankingexpression.evaluation.TypeMapContext; import com.yahoo.searchlib.rankingexpression.evaluation.Value; @@ -746,11 +747,11 @@ public class RankProfile implements Serializable, Cloneable { TypeMapContext context = new TypeMapContext(); // Add constants - getConstants().forEach((k, v) -> context.setType(asConstantFeature(k), v.type())); + getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type())); // Add attributes for (SDField field : getSearch().allConcreteFields()) - field.getAttributes().forEach((k, a) -> context.setType(asAttributeFeature(k), a.tensorType().orElse(TensorType.empty))); + field.getAttributes().forEach((k, a) -> context.setType(FeatureNames.asAttributeFeature(k), a.tensorType().orElse(TensorType.empty))); // Add query features from rank profile types reached from the "default" profile QueryProfile profile = queryProfilesOf(getSearch().sourceApplication()).getComponent("default"); @@ -761,7 +762,7 @@ public class RankProfile implements Serializable, Cloneable { if (field.getType() instanceof TensorFieldType) type = ((TensorFieldType)field.getType()).type().get(); - String feature = asQueryFeature(prefix.append(field.getName()).toString()); + String feature = FeatureNames.asQueryFeature(prefix.append(field.getName()).toString()); context.setType(feature, type); } }); @@ -776,7 +777,7 @@ public class RankProfile implements Serializable, Cloneable { try { queryProfileFiles = applicationPackage.getQueryProfileFiles(); queryProfileTypeFiles = applicationPackage.getQueryProfileTypeFiles(); - return new QueryProfileXMLReader().read(queryProfileFiles, queryProfileTypeFiles); + return new QueryProfileXMLReader().read(queryProfileTypeFiles, queryProfileFiles); } finally { NamedReader.closeAll(queryProfileFiles); @@ -784,18 +785,6 @@ public class RankProfile implements Serializable, Cloneable { } } - private String asConstantFeature(String constantName) { - return "constant(\"" + constantName + "\")"; - } - - private String asAttributeFeature(String constantName) { - return "attribute(\"" + constantName + "\")"; - } - - private String asQueryFeature(String constantName) { - return "query(\"" + constantName + "\")"; - } - /** * A rank setting. The identity of a rank setting is its field name and type (not value). * A rank setting is immutable. diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/TensorFlowFeatureConverter.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/TensorFlowFeatureConverter.java index 9c7fd7d9f0a..da85e9f65ec 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/TensorFlowFeatureConverter.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/TensorFlowFeatureConverter.java @@ -185,6 +185,11 @@ public class TensorFlowFeatureConverter extends ExpressionTransformer<RankProfil "' of type " + requiredType + " but this macro is not present in " + profile); TensorType actualType = macro.getRankingExpression().getRoot().type(profile.typeContext()); + if ( actualType == null) + throw new IllegalArgumentException("Model refers Placeholder '" + macroName + + "' of type " + requiredType + + " which must be produced by a macro in the rank profile, but " + + "this macro references a feature which is not declared"); if ( ! actualType.isAssignableTo(requiredType)) throw new IllegalArgumentException("Model refers Placeholder '" + macroName + "' of type " + requiredType + |