summaryrefslogtreecommitdiffstats
path: root/model-integration
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-18 11:55:45 +0200
committerJon Bratseth <bratseth@gmail.com>2022-05-18 11:55:45 +0200
commit9aa29161dfe87e498caf292ce9201b78cb199a79 (patch)
tree649d3fad62792f9c58fa0f485905068813cf85c6 /model-integration
parent619d924440939076e399f2504fa6850976d2a303 (diff)
Unify input syntax across models and rank profiles
Diffstat (limited to 'model-integration')
-rw-r--r--model-integration/src/main/javacc/ModelParser.jj14
-rw-r--r--model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java9
-rw-r--r--model-integration/src/test/models/vespa/example.model6
-rw-r--r--model-integration/src/test/models/vespa/legacy_syntax.model26
4 files changed, 51 insertions, 4 deletions
diff --git a/model-integration/src/main/javacc/ModelParser.jj b/model-integration/src/main/javacc/ModelParser.jj
index 668fd017aa9..c850d223612 100644
--- a/model-integration/src/main/javacc/ModelParser.jj
+++ b/model-integration/src/main/javacc/ModelParser.jj
@@ -92,6 +92,7 @@ TOKEN :
| < DOT: "." >
| < COMMA: "," >
| < DOUBLE_KEYWORD: "double" >
+| < INPUTS: "inputs" >
| < MODEL: "model" >
| < TYPE: "type" >
| < EXPRESSION_SL: "expression" (" ")* ":" (("{"<BRACE_SL_LEVEL_1>)|<BRACE_SL_CONTENT>)* ("\n")? >
@@ -156,17 +157,25 @@ void model() :
}
void modelContent() :
-{
-}
+{}
{
( <NL> |
constants() |
largeConstant() |
function() |
+ inputs() |
input()
)*
}
+void inputs() :
+{}
+{
+ <INPUTS> (<NL>)* <LBRACE> (<NL>)*
+ ( input() (<NL>)* )*
+ <RBRACE>
+}
+
/** Declared input variables (aka features). All non-scalar inputs must be declared. */
void input() :
{
@@ -536,6 +545,7 @@ String identifier() : { }
<DOUBLE_KEYWORD> |
<FILE> |
<IDENTIFIER> |
+ <INPUTS> |
<INTEGER> |
<MODEL> |
<TYPE> |
diff --git a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java
index fc92883a90f..25c51a75b0b 100644
--- a/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java
+++ b/model-integration/src/test/java/ai/vespa/rankingexpression/importer/vespa/VespaImportTestCase.java
@@ -25,7 +25,16 @@ public class VespaImportTestCase {
@Test
public void testExample() {
ImportedModel model = importModel("example");
+ assertModel(model);
+ }
+
+ @Test
+ public void testLegacySyntax() {
+ ImportedModel model = importModel("legacy_syntax");
+ assertModel(model);
+ }
+ private void assertModel(ImportedModel model) {
assertEquals(2, model.inputs().size());
assertEquals("tensor(name{},x[3])", model.inputs().get("input1").toString());
assertEquals("tensor(x[3])", model.inputs().get("input2").toString());
diff --git a/model-integration/src/test/models/vespa/example.model b/model-integration/src/test/models/vespa/example.model
index fd8565f2b92..25d27033cfd 100644
--- a/model-integration/src/test/models/vespa/example.model
+++ b/model-integration/src/test/models/vespa/example.model
@@ -1,8 +1,10 @@
model example {
# All inputs that are not scalar (aka 0-dimensional tensor) must be declared
- input1: tensor(name{}, x[3])
- input2: tensor(x[3])
+ inputs {
+ input1: tensor(name{}, x[3])
+ input2: tensor(x[3])
+ }
constants {
constant1: tensor(x[3]):{{x:0}:0.5, {x:1}:1.5, {x:2}:2.5}
diff --git a/model-integration/src/test/models/vespa/legacy_syntax.model b/model-integration/src/test/models/vespa/legacy_syntax.model
new file mode 100644
index 00000000000..2a5031a5ff9
--- /dev/null
+++ b/model-integration/src/test/models/vespa/legacy_syntax.model
@@ -0,0 +1,26 @@
+model legacy_syntax {
+
+ # Syntax not supported in rank profiles which probably should be removed on Vespa 9
+ input1: tensor(name{}, x[3])
+ input2: tensor(x[3])
+
+ constants {
+ constant1: tensor(x[3]):{{x:0}:0.5, {x:1}:1.5, {x:2}:2.5}
+ constant2: 3.0
+ }
+
+ # Syntax to be removed on Vespa 9
+ constant constant1asLarge {
+ type: tensor(x[3])
+ file: constant1asLarge.json
+ }
+
+ function foo1() {
+ expression: file:test.expression
+ }
+
+ function foo2() {
+ expression: reduce(sum(input1 * input2, name) * constant(constant1asLarge), max, x) * constant2
+ }
+
+} \ No newline at end of file