aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2018-01-09 16:07:43 +0100
committerJon Bratseth <bratseth@yahoo-inc.com>2018-01-09 16:07:43 +0100
commitdc0f70fac9167acf487453daf565636c675934df (patch)
treeaaccfae7aaf4a48e35655a66c75ea57412ede6a6 /config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
parentfa9fe82c82d6a562e3ae02b9577f536a16c72c92 (diff)
Basic TensorFlow integration
This wil replace any occurrence of tensorflow(...) in ranking expressions with the corresponding translated expression. It is functional but these tings are outstanding - Propagate warnings - Import a model just once even if referred multiple times - Add constants as tensor files rather than config
Diffstat (limited to 'config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java')
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java56
1 files changed, 7 insertions, 49 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
index 4dcf7523fd0..dba2bdbfbbf 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java
@@ -1,61 +1,19 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;
-import com.yahoo.searchdefinition.RankProfile;
-import com.yahoo.searchdefinition.RankProfileRegistry;
-import com.yahoo.searchdefinition.Search;
-import com.yahoo.searchdefinition.SearchBuilder;
import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
/**
* @author geirst
*/
public class RankingExpressionWithTensorTestCase {
- private static class SearchFixture {
- RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
- Search search;
- SearchFixture(String rankProfiles) throws ParseException {
- SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
- String sdContent = "search test {\n" +
- " document test {\n" +
- " }\n" +
- rankProfiles +
- "\n" +
- "}";
- builder.importString(sdContent);
- builder.build();
- search = builder.getSearch();
- }
- public void assertFirstPhaseExpression(String expExpression, String rankProfile) {
- assertEquals(expExpression, getRankProfile(rankProfile).getFirstPhaseRanking().getRoot().toString());
- }
- public void assertSecondPhaseExpression(String expExpression, String rankProfile) {
- assertEquals(expExpression, getRankProfile(rankProfile).getSecondPhaseRanking().getRoot().toString());
- }
- public void assertRankProperty(String expValue, String name, String rankProfile) {
- List<RankProfile.RankProperty> rankPropertyList = getRankProfile(rankProfile).getRankPropertyMap().get(name);
- assertEquals(1, rankPropertyList.size());
- assertEquals(expValue, rankPropertyList.get(0).getValue());
- }
- public void assertMacro(String expExpression, String macroName, String rankProfile) {
- assertEquals(expExpression, getRankProfile(rankProfile).getMacros().get(macroName).getRankingExpression().getRoot().toString());
- }
- private RankProfile getRankProfile(String rankProfile) {
- return rankProfileRegistry.getRankProfile(search, rankProfile).compile();
- }
- }
-
@Test
public void requireThatSingleLineConstantTensorAndTypeCanBeParsed() throws ParseException {
- SearchFixture f = new SearchFixture(
+ RankProfileSearchFixture f = new RankProfileSearchFixture(
" rank-profile my_profile {\n" +
" first-phase {\n" +
" expression: sum(my_tensor)\n" +
@@ -74,7 +32,7 @@ public class RankingExpressionWithTensorTestCase {
@Test
public void requireThatMultiLineConstantTensorAndTypeCanBeParsed() throws ParseException {
- SearchFixture f = new SearchFixture(
+ RankProfileSearchFixture f = new RankProfileSearchFixture(
" rank-profile my_profile {\n" +
" first-phase {\n" +
" expression: sum(my_tensor)\n" +
@@ -96,7 +54,7 @@ public class RankingExpressionWithTensorTestCase {
@Test
public void requireThatConstantTensorsCanBeUsedInSecondPhaseExpression() throws ParseException {
- SearchFixture f = new SearchFixture(
+ RankProfileSearchFixture f = new RankProfileSearchFixture(
" rank-profile my_profile {\n" +
" second-phase {\n" +
" expression: sum(my_tensor)\n" +
@@ -114,7 +72,7 @@ public class RankingExpressionWithTensorTestCase {
@Test
public void requireThatConstantTensorsCanBeUsedInInheritedRankProfile() throws ParseException {
- SearchFixture f = new SearchFixture(
+ RankProfileSearchFixture f = new RankProfileSearchFixture(
" rank-profile parent {\n" +
" constants {\n" +
" my_tensor {\n" +
@@ -134,7 +92,7 @@ public class RankingExpressionWithTensorTestCase {
@Test
public void requireThatConstantTensorsCanBeUsedInMacro() throws ParseException {
- SearchFixture f = new SearchFixture(
+ RankProfileSearchFixture f = new RankProfileSearchFixture(
" rank-profile my_profile {\n" +
" macro my_macro() {\n" +
" expression: sum(my_tensor)\n" +
@@ -156,7 +114,7 @@ public class RankingExpressionWithTensorTestCase {
@Test
public void requireThatCombinationOfConstantTensorsAndConstantValuesCanBeUsed() throws ParseException {
- SearchFixture f = new SearchFixture(
+ RankProfileSearchFixture f = new RankProfileSearchFixture(
" rank-profile my_profile {\n" +
" first-phase {\n" +
" expression: my_number_1 + sum(my_tensor) + my_number_2\n" +
@@ -181,7 +139,7 @@ public class RankingExpressionWithTensorTestCase {
public void requireThatInvalidTensorTypeSpecThrowsException() throws ParseException {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("For constant tensor 'my_tensor' in rank profile 'my_profile': Illegal tensor type spec: Failed parsing element 'x' in type spec 'tensor(x)'");
- new SearchFixture(
+ new RankProfileSearchFixture(
" rank-profile my_profile {\n" +
" constants {\n" +
" my_tensor {\n" +