1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition;
import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels;
import com.yahoo.collections.Pair;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.searchdefinition.derived.AttributeFields;
import com.yahoo.searchdefinition.derived.RawRankProfile;
import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* @author lesters
*/
public class RankingExpressionFeatureArgumentsTestCase extends SchemaTestCase {
@Test
public void testFeatureWithExpressionArguments() throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
builder.importString(
"search test {\n" +
" document test { \n" +
" field t1 type tensor<float>(x{}) { \n" +
" indexing: attribute | summary \n" +
" }\n" +
" field t2 type tensor<float>(x{}) { \n" +
" indexing: attribute | summary \n" +
" }\n" +
" }\n" +
" rank-profile test {\n" +
" function my_func(t) {\n" +
" expression: sum(t, x) \n" +
" }\n" +
" function eval_func() {\n" +
" expression: my_func( attribute(t1) ) \n" +
" }\n" +
" function eval_func_with_expr() {\n" +
" expression: my_func( attribute(t1) * attribute(t2) ) \n" +
" }\n" +
" function eval_func_with_expr_2() {\n" +
" expression: my_func( attribute(t1){x:0} ) \n" +
" }\n" +
" function eval_func_via_func_with_expr() {\n" +
" expression: call_func_with_expr( attribute(t1), attribute(t2) ) \n" +
" }\n" +
" function call_func_with_expr(a, b) {\n" +
" expression: my_func( a * b ) \n" +
" }\n" +
" first-phase {\n" +
" expression: 42 \n" +
" }\n" +
" }\n" +
"\n" +
"}\n");
builder.build();
Search s = builder.getSearch();
RankProfile test = rankProfileRegistry.get(s, "test").compile(new QueryProfileRegistry(), new ImportedMlModels());
List<Pair<String, String>> testRankProperties = new RawRankProfile(test,
new QueryProfileRegistry(),
new ImportedMlModels(),
new AttributeFields(s)).configProperties();
for(Pair<String,String> prop : testRankProperties) {
System.out.println(prop);
}
assertEquals("(rankingExpression(my_func).rankingScript, reduce(t, sum, x))",
testRankProperties.get(0).toString());
// eval_func
assertEquals("(rankingExpression(eval_func).rankingScript, rankingExpression(my_func@9bbaee2bad5a2fc0))",
testRankProperties.get(2).toString());
assertEquals("(rankingExpression(my_func@9bbaee2bad5a2fc0).rankingScript, reduce(attribute(t1), sum, x))",
testRankProperties.get(1).toString());
// The following functions should generate features to evaluate the expression argument before passing to my_func
// eval_func_with_expr
assertEquals("(rankingExpression(eval_func_with_expr).rankingScript, rankingExpression(my_func@45673ba956ae9b77))",
testRankProperties.get(5).toString());
assertEquals("(rankingExpression(my_func@45673ba956ae9b77).rankingScript, reduce(autogenerated_ranking_feature@43bc412603c00a4a, sum, x))",
testRankProperties.get(4).toString());
assertEquals("(rankingExpression(autogenerated_ranking_feature@43bc412603c00a4a).rankingScript, attribute(t1) * attribute(t2))",
testRankProperties.get(3).toString());
// eval_func_with_expr_2
assertEquals("(rankingExpression(eval_func_with_expr_2).rankingScript, rankingExpression(my_func@2192533eaad2293d))",
testRankProperties.get(8).toString());
assertEquals("(rankingExpression(my_func@2192533eaad2293d).rankingScript, reduce(autogenerated_ranking_feature@71a4196136b577cf, sum, x))",
testRankProperties.get(7).toString());
assertEquals("(rankingExpression(autogenerated_ranking_feature@71a4196136b577cf).rankingScript, attribute(t1){x:0})",
testRankProperties.get(6).toString());
// eval_func_via_func_with_expr
assertEquals("(rankingExpression(eval_func_via_func_with_expr).rankingScript, rankingExpression(call_func_with_expr@640470df47a83000.c156faa8f98c0b0c))",
testRankProperties.get(10).toString());
assertEquals("(rankingExpression(call_func_with_expr@640470df47a83000.c156faa8f98c0b0c).rankingScript, rankingExpression(my_func@45673ba956ae9b77))",
testRankProperties.get(9).toString());
// my_func@45673ba956ae9b77 is the same as under eval_func_with_expr
}
}
|