diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-01-31 18:05:38 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-01-31 18:05:38 +0100 |
commit | 6aa637558ae3dafc6112f2ac8fb192ede83744de (patch) | |
tree | cfc9cd9e74d60be0c5104336063c1be228d1954e /config-model/src | |
parent | c56889931e1547a6a6db420a3c886ddf03f5bd6e (diff) |
Add attribute access test
Diffstat (limited to 'config-model/src')
3 files changed, 31 insertions, 3 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 136d09304da..492f4e56465 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -750,8 +750,9 @@ public class RankProfile implements Serializable, Cloneable { getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type())); // Add attributes - for (SDField field : getSearch().allConcreteFields()) + for (SDField field : getSearch().allConcreteFields()) { 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"); 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 8ba0a42f799..79bdbddbdd6 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 @@ -29,9 +29,14 @@ class RankProfileSearchFixture { } RankProfileSearchFixture(ApplicationPackage applicationpackage, String rankProfiles) throws ParseException { + this(applicationpackage, rankProfiles, null); + } + + RankProfileSearchFixture(ApplicationPackage applicationpackage, String rankProfiles, String field) throws ParseException { SearchBuilder builder = new SearchBuilder(applicationpackage, rankProfileRegistry); String sdContent = "search test {\n" + " document test {\n" + + (field != null ? field : "") + " }\n" + rankProfiles + "\n" + 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 598ed04e657..60a2c5326a0 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 @@ -69,6 +69,19 @@ public class RankingExpressionWithTensorFlowTestCase { queryProfileType); RankProfileSearchFixture search = fixtureWith("query(mytensor)", "tensorflow('mnist_softmax/saved')", + null, + application); + search.assertFirstPhaseExpression(vespaExpression, "my_profile"); + assertConstant("Variable_1", search, Optional.of(10L)); + assertConstant("Variable", search, Optional.of(7840L)); + } + + @Test + public void testTensorFlowReferenceWithDocumentFeature() throws ParseException { + StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); + RankProfileSearchFixture search = fixtureWith("attribute(mytensor)", + "tensorflow('mnist_softmax/saved')", + "field mytensor type tensor(d0[],d1[784]) { indexing: attribute }", application); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); assertConstant("Variable_1", search, Optional.of(10L)); @@ -186,6 +199,7 @@ public class RankingExpressionWithTensorFlowTestCase { StoringApplicationPackage storedApplication = new StoringApplicationPackage(storedApplicationDirectory); RankProfileSearchFixture searchFromStored = fixtureWith("tensor(d0[2],d1[784])(0.0)", "tensorflow('mnist_softmax/saved')", + null, storedApplication); searchFromStored.assertFirstPhaseExpression(vespaExpression, "my_profile"); // Verify that the constants exists, but don't verify the content as we are not @@ -225,11 +239,18 @@ public class RankingExpressionWithTensorFlowTestCase { } private RankProfileSearchFixture fixtureWith(String placeholderExpression, String firstPhaseExpression) { - return fixtureWith(placeholderExpression, firstPhaseExpression, new StoringApplicationPackage(applicationDir)); + return fixtureWith(placeholderExpression, firstPhaseExpression, null, + new StoringApplicationPackage(applicationDir)); + } + + private RankProfileSearchFixture fixtureWith(String placeholderExpression, String firstPhaseExpression, String field) { + return fixtureWith(placeholderExpression, firstPhaseExpression, field, + new StoringApplicationPackage(applicationDir)); } private RankProfileSearchFixture fixtureWith(String placeholderExpression, String firstPhaseExpression, + String field, StoringApplicationPackage application) { try { return new RankProfileSearchFixture( @@ -241,7 +262,8 @@ public class RankingExpressionWithTensorFlowTestCase { " first-phase {\n" + " expression: " + firstPhaseExpression + " }\n" + - " }"); + " }", + field); } catch (ParseException e) { throw new IllegalArgumentException(e); |