File size: 6,927 Bytes
d552aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

include "buffer.fbs";

// The type of variable to fetch.
namespace libtextclassifier3;
enum AndroidSimpleIntentGeneratorVariableType : int {
  INVALID_VARIABLE = 0,

  // The raw text that was classified.
  RAW_TEXT = 1,

  // Text as a URL with explicit protocol. If no protocol was specified, http
  // is prepended.
  URL_TEXT = 2,

  // The raw text, but URL encoded.
  URL_ENCODED_TEXT = 3,

  // For dates/times: the instant of the event in UTC millis.
  EVENT_TIME_MS_UTC = 4,

  // For dates/times: the start of the event in UTC millis.
  EVENT_START_MS_UTC = 5,

  // For dates/times: the end of the event in UTC millis.
  EVENT_END_MS_UTC = 6,

  // Name of the package that's running the classifier.
  PACKAGE_NAME = 7,
}

// Enumerates the possible extra types for the simple intent generator.
namespace libtextclassifier3;
enum AndroidSimpleIntentGeneratorExtraType : int {
  INVALID_EXTRA_TYPE = 0,
  STRING = 1,
  // Use string_ field.

  BOOL = 2,
  // Use bool_ field.

  VARIABLE_AS_LONG = 3,
  // Use int32_ field for the variable index.
}

// Enumerates the possible condition types for the simple intent generator.
namespace libtextclassifier3;
enum AndroidSimpleIntentGeneratorConditionType : int {
  INVALID_CONDITION_TYPE = 0,

  // Queries the UserManager for the given boolean restriction. The condition
  // passes if the result is of getBoolean is false. The name of the
  // restriction to check is in the string_ field.
  USER_RESTRICTION_NOT_SET = 1,

  // Checks that the parsed event start time is at least a give number of
  // milliseconds in the future. (Only valid if there is a parsed event
  // time) The offset is stored in the int64_ field.
  EVENT_START_IN_FUTURE_MS = 2,
}

// Describes how intents for the various entity types should be generated on
// Android. This is distributed through the model, but not used by
// libtextclassifier yet - rather, it's passed to the calling Java code, which
// implements the Intent generation logic.
namespace libtextclassifier3;
table AndroidIntentFactoryOptions {
  entity:[AndroidIntentFactoryEntityOptions];
}

// Describes how intents should be generated for a particular entity type.
namespace libtextclassifier3;
table AndroidIntentFactoryEntityOptions {
  // The entity type as defined by one of the TextClassifier ENTITY_TYPE
  // constants. (e.g. "address", "phone", etc.)
  entity_type:string;

  // List of generators for all the different types of intents that should
  // be made available for the entity type.
  generator:[AndroidIntentGeneratorOptions];
}

// Configures a single Android Intent generator.
namespace libtextclassifier3;
table AndroidIntentGeneratorOptions {
  // Strings for UI elements.
  strings:[AndroidIntentGeneratorStrings];

  // Generator specific configuration.
  simple:AndroidSimpleIntentGeneratorOptions;
}

// Language dependent configuration for an Android Intent generator.
namespace libtextclassifier3;
table AndroidIntentGeneratorStrings {
  // BCP 47 tag for the supported locale. Note that because of API level
  // restrictions, this must /not/ use wildcards. To e.g. match all English
  // locales, use only "en" and not "en_*". Reference the java.util.Locale
  // constructor for details.
  language_tag:string;

  // Title shown for the action (see RemoteAction.getTitle).
  title:string;

  // Description shown for the action (see
  // RemoteAction.getContentDescription).
  description:string;
}

// An extra to set on a simple intent generator Intent.
namespace libtextclassifier3;
table AndroidSimpleIntentGeneratorExtra {
  // The name of the extra to set.
  name:string;

  // The type of the extra to set.
  type:AndroidSimpleIntentGeneratorExtraType;

  string_:string;
  bool_:bool;
  int32_:int;
}

// A condition that needs to be fulfilled for an Intent to get generated.
namespace libtextclassifier3;
table AndroidSimpleIntentGeneratorCondition {
  type:AndroidSimpleIntentGeneratorConditionType;
  string_:string;
  int32_:int;
  int64_:long;
}

// Configures an intent generator where the logic is simple to be expressed with
// basic rules - which covers the vast majority of use cases and is analogous
// to Android Actions.
// Most strings (action, data, type, ...) may contain variable references. To
// use them, the generator must first declare all the variables it wishes to use
// in the variables field. The values then become available as numbered
// arguments (using the normal java.util.Formatter syntax) in the order they
// were specified.
namespace libtextclassifier3;
table AndroidSimpleIntentGeneratorOptions {
  // The action to set on the Intent (see Intent.setAction). Supports variables.
  action:string;

  // The data to set on the Intent (see Intent.setData). Supports variables.
  data:string;

  // The type to set on the Intent (see Intent.setType). Supports variables.
  type:string;

  // The list of all the extras to add to the Intent.
  extra:[AndroidSimpleIntentGeneratorExtra];

  // The list of all the variables that become available for substitution in
  // the action, data, type and extra strings. To e.g. set a field to the value
  // of the first variable, use "%0$s".
  variable:[AndroidSimpleIntentGeneratorVariableType];

  // The list of all conditions that need to be fulfilled for Intent generation.
  condition:[AndroidSimpleIntentGeneratorCondition];
}

// Describes how intents should be generated for a particular entity type.
namespace libtextclassifier3.IntentFactoryModel_;
table IntentGenerator {
  // The type of the intent generator, e.g. the entity type as defined by
  // on the TextClassifier ENTITY_TYPE constants e.g. "address", "phone", etc.
  type:string;

  // The template generator lua code, either as text source or precompiled
  // bytecode.
  lua_template_generator:[ubyte];

  compressed_lua_template_generator:CompressedBuffer;
}

// Describes how intents for the various entity types should be generated.
namespace libtextclassifier3;
table IntentFactoryModel {
  generator:[IntentFactoryModel_.IntentGenerator];

  // Whether to precompile the generators when loading.
  precompile_generators:bool = false;
}