• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright (C) 2018 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17include "utils/flatbuffers/flatbuffers.fbs";
18
19namespace libtextclassifier3.grammar.SemanticExpression_;
20union Expression {
21  ConstValueExpression,
22  ConstituentExpression,
23  ComposeExpression,
24  SpanAsStringExpression,
25  ParseNumberExpression,
26  MergeValueExpression,
27  ArithmeticExpression,
28}
29
30// A semantic expression.
31namespace libtextclassifier3.grammar;
32table SemanticExpression {
33  expression:SemanticExpression_.Expression;
34}
35
36// A constant flatbuffer value.
37namespace libtextclassifier3.grammar;
38table ConstValueExpression {
39  // The base type of the value.
40  base_type:int;
41
42  // The id of the type of the value.
43  // The id is used for lookup in the semantic values type metadata.
44  type:int;
45
46  // The serialized value.
47  value:[ubyte];
48}
49
50// The value of a rule constituent.
51namespace libtextclassifier3.grammar;
52table ConstituentExpression {
53  // The id of the constituent.
54  id:ushort;
55}
56
57// The fields to set.
58namespace libtextclassifier3.grammar.ComposeExpression_;
59table Field {
60  // The field to set.
61  path:libtextclassifier3.FlatbufferFieldPath;
62
63  // The value.
64  value:SemanticExpression;
65}
66
67// A combination: Compose a result from arguments.
68// https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-4.html#%_toc_%_sec_1.1.1
69namespace libtextclassifier3.grammar;
70table ComposeExpression {
71  // The id of the type of the result.
72  type:int;
73
74  fields:[ComposeExpression_.Field];
75}
76
77// Lifts a span as a value.
78namespace libtextclassifier3.grammar;
79table SpanAsStringExpression {
80}
81
82// Parses a string as a number.
83namespace libtextclassifier3.grammar;
84table ParseNumberExpression {
85  // The base type of the value.
86  base_type:int;
87
88  value:SemanticExpression;
89}
90
91// Merge the semantic expressions.
92namespace libtextclassifier3.grammar;
93table MergeValueExpression {
94  // The id of the type of the result.
95  type:int;
96
97  values:[SemanticExpression];
98}
99
100// The operator of the arithmetic expression.
101namespace libtextclassifier3.grammar.ArithmeticExpression_;
102enum Operator : int {
103  NO_OP = 0,
104  OP_ADD = 1,
105  OP_MUL = 2,
106  OP_MAX = 3,
107  OP_MIN = 4,
108}
109
110// Simple arithmetic expression.
111namespace libtextclassifier3.grammar;
112table ArithmeticExpression {
113  // The base type of the operation.
114  base_type:int;
115
116  op:ArithmeticExpression_.Operator;
117  values:[SemanticExpression];
118}
119
120