aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-01-31 17:36:21 +0100
committerJon Bratseth <bratseth@oath.com>2018-01-31 17:36:21 +0100
commitc56889931e1547a6a6db420a3c886ddf03f5bd6e (patch)
treea718a9bbacf236c54c8164def703f4e108e7287d /config-model/src/test
parent2c25a02adbe644b3f50dc44252c6b61974d0c8d6 (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/test')
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java44
1 files changed, 40 insertions, 4 deletions
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 82d0d66a82a..598ed04e657 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
@@ -6,6 +6,7 @@ import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.io.GrowableByteBuffer;
import com.yahoo.io.IOUtils;
+import com.yahoo.io.reader.NamedReader;
import com.yahoo.path.Path;
import com.yahoo.searchdefinition.RankingConstant;
import com.yahoo.searchdefinition.parser.ParseException;
@@ -22,6 +23,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.io.StringReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Collections;
@@ -48,7 +50,7 @@ public class RankingExpressionWithTensorFlowTestCase {
}
@Test
- public void testMinimalTensorFlowReference() throws ParseException {
+ public void testTensorFlowReference() throws ParseException {
RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)",
"tensorflow('mnist_softmax/saved')");
search.assertFirstPhaseExpression(vespaExpression, "my_profile");
@@ -57,6 +59,23 @@ public class RankingExpressionWithTensorFlowTestCase {
}
@Test
+ public void testTensorFlowReferenceWithQueryFeature() throws ParseException {
+ String queryProfile = "<query-profile id='default' type='root'/>";
+ String queryProfileType = "<query-profile-type id='root'>" +
+ " <field name='mytensor' type='tensor(d0[3],d1[784])'/>" +
+ "</query-profile-type>";
+ StoringApplicationPackage application = new StoringApplicationPackage(applicationDir,
+ queryProfile,
+ queryProfileType);
+ RankProfileSearchFixture search = fixtureWith("query(mytensor)",
+ "tensorflow('mnist_softmax/saved')",
+ application);
+ search.assertFirstPhaseExpression(vespaExpression, "my_profile");
+ assertConstant("Variable_1", search, Optional.of(10L));
+ assertConstant("Variable", search, Optional.of(7840L));
+ }
+
+ @Test
public void testNestedTensorFlowReference() throws ParseException {
RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)",
"5 + sum(tensorflow('mnist_softmax/saved'))");
@@ -233,14 +252,19 @@ public class RankingExpressionWithTensorFlowTestCase {
private final File root;
+ /** The content of the single query profile and type present in this, or null if none */
+ private final String queryProfile, queryProfileType;
+
StoringApplicationPackage(Path applicationPackageWritableRoot) {
- this(applicationPackageWritableRoot.toFile());
+ this(applicationPackageWritableRoot, null, null);
}
- StoringApplicationPackage(File applicationPackageWritableRoot) {
+ StoringApplicationPackage(Path applicationPackageWritableRoot, String queryProfile, String queryProfileType) {
super(null, null, Collections.emptyList(), null,
null, null, false);
- this.root = applicationPackageWritableRoot;
+ this.root = new File(applicationPackageWritableRoot.toString());
+ this.queryProfile = queryProfile;
+ this.queryProfileType = queryProfileType;
}
@Override
@@ -253,6 +277,18 @@ public class RankingExpressionWithTensorFlowTestCase {
return new StoringApplicationPackageFile(file, Path.fromString(root.toString()));
}
+ @Override
+ public List<NamedReader> getQueryProfileFiles() {
+ if (queryProfile == null) return Collections.emptyList();
+ return Collections.singletonList(new NamedReader("default.xml", new StringReader(queryProfile)));
+ }
+
+ @Override
+ public List<NamedReader> getQueryProfileTypeFiles() {
+ if (queryProfileType == null) return Collections.emptyList();
+ return Collections.singletonList(new NamedReader("root.xml", new StringReader(queryProfileType)));
+ }
+
}
private static class StoringApplicationPackageFile extends ApplicationFile {