1*993b0882SAndroid Build Coastguard Worker// 2*993b0882SAndroid Build Coastguard Worker// Copyright (C) 2018 The Android Open Source Project 3*993b0882SAndroid Build Coastguard Worker// 4*993b0882SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 5*993b0882SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 6*993b0882SAndroid Build Coastguard Worker// You may obtain a copy of the License at 7*993b0882SAndroid Build Coastguard Worker// 8*993b0882SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 9*993b0882SAndroid Build Coastguard Worker// 10*993b0882SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 11*993b0882SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 12*993b0882SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*993b0882SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 14*993b0882SAndroid Build Coastguard Worker// limitations under the License. 15*993b0882SAndroid Build Coastguard Worker// 16*993b0882SAndroid Build Coastguard Worker 17*993b0882SAndroid Build Coastguard Workerinclude "utils/zlib/buffer.fbs"; 18*993b0882SAndroid Build Coastguard Worker 19*993b0882SAndroid Build Coastguard Worker// The type of variable to fetch. 20*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 21*993b0882SAndroid Build Coastguard Workerenum AndroidSimpleIntentGeneratorVariableType : int { 22*993b0882SAndroid Build Coastguard Worker INVALID_VARIABLE = 0, 23*993b0882SAndroid Build Coastguard Worker 24*993b0882SAndroid Build Coastguard Worker // The raw text that was classified. 25*993b0882SAndroid Build Coastguard Worker RAW_TEXT = 1, 26*993b0882SAndroid Build Coastguard Worker 27*993b0882SAndroid Build Coastguard Worker // Text as a URL with explicit protocol. If no protocol was specified, http 28*993b0882SAndroid Build Coastguard Worker // is prepended. 29*993b0882SAndroid Build Coastguard Worker URL_TEXT = 2, 30*993b0882SAndroid Build Coastguard Worker 31*993b0882SAndroid Build Coastguard Worker // The raw text, but URL encoded. 32*993b0882SAndroid Build Coastguard Worker URL_ENCODED_TEXT = 3, 33*993b0882SAndroid Build Coastguard Worker 34*993b0882SAndroid Build Coastguard Worker // For dates/times: the instant of the event in UTC millis. 35*993b0882SAndroid Build Coastguard Worker EVENT_TIME_MS_UTC = 4, 36*993b0882SAndroid Build Coastguard Worker 37*993b0882SAndroid Build Coastguard Worker // For dates/times: the start of the event in UTC millis. 38*993b0882SAndroid Build Coastguard Worker EVENT_START_MS_UTC = 5, 39*993b0882SAndroid Build Coastguard Worker 40*993b0882SAndroid Build Coastguard Worker // For dates/times: the end of the event in UTC millis. 41*993b0882SAndroid Build Coastguard Worker EVENT_END_MS_UTC = 6, 42*993b0882SAndroid Build Coastguard Worker 43*993b0882SAndroid Build Coastguard Worker // Name of the package that's running the classifier. 44*993b0882SAndroid Build Coastguard Worker PACKAGE_NAME = 7, 45*993b0882SAndroid Build Coastguard Worker} 46*993b0882SAndroid Build Coastguard Worker 47*993b0882SAndroid Build Coastguard Worker// Enumerates the possible extra types for the simple intent generator. 48*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 49*993b0882SAndroid Build Coastguard Workerenum AndroidSimpleIntentGeneratorExtraType : int { 50*993b0882SAndroid Build Coastguard Worker INVALID_EXTRA_TYPE = 0, 51*993b0882SAndroid Build Coastguard Worker STRING = 1, 52*993b0882SAndroid Build Coastguard Worker // Use string_ field. 53*993b0882SAndroid Build Coastguard Worker 54*993b0882SAndroid Build Coastguard Worker BOOL = 2, 55*993b0882SAndroid Build Coastguard Worker // Use bool_ field. 56*993b0882SAndroid Build Coastguard Worker 57*993b0882SAndroid Build Coastguard Worker VARIABLE_AS_LONG = 3, 58*993b0882SAndroid Build Coastguard Worker // Use int32_ field for the variable index. 59*993b0882SAndroid Build Coastguard Worker} 60*993b0882SAndroid Build Coastguard Worker 61*993b0882SAndroid Build Coastguard Worker// Enumerates the possible condition types for the simple intent generator. 62*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 63*993b0882SAndroid Build Coastguard Workerenum AndroidSimpleIntentGeneratorConditionType : int { 64*993b0882SAndroid Build Coastguard Worker INVALID_CONDITION_TYPE = 0, 65*993b0882SAndroid Build Coastguard Worker 66*993b0882SAndroid Build Coastguard Worker // Queries the UserManager for the given boolean restriction. The condition 67*993b0882SAndroid Build Coastguard Worker // passes if the result is of getBoolean is false. The name of the 68*993b0882SAndroid Build Coastguard Worker // restriction to check is in the string_ field. 69*993b0882SAndroid Build Coastguard Worker USER_RESTRICTION_NOT_SET = 1, 70*993b0882SAndroid Build Coastguard Worker 71*993b0882SAndroid Build Coastguard Worker // Checks that the parsed event start time is at least a give number of 72*993b0882SAndroid Build Coastguard Worker // milliseconds in the future. (Only valid if there is a parsed event 73*993b0882SAndroid Build Coastguard Worker // time) The offset is stored in the int64_ field. 74*993b0882SAndroid Build Coastguard Worker EVENT_START_IN_FUTURE_MS = 2, 75*993b0882SAndroid Build Coastguard Worker} 76*993b0882SAndroid Build Coastguard Worker 77*993b0882SAndroid Build Coastguard Worker// Describes how intents for the various entity types should be generated on 78*993b0882SAndroid Build Coastguard Worker// Android. This is distributed through the model, but not used by 79*993b0882SAndroid Build Coastguard Worker// libtextclassifier yet - rather, it's passed to the calling Java code, which 80*993b0882SAndroid Build Coastguard Worker// implements the Intent generation logic. 81*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 82*993b0882SAndroid Build Coastguard Workertable AndroidIntentFactoryOptions { 83*993b0882SAndroid Build Coastguard Worker entity:[AndroidIntentFactoryEntityOptions]; 84*993b0882SAndroid Build Coastguard Worker} 85*993b0882SAndroid Build Coastguard Worker 86*993b0882SAndroid Build Coastguard Worker// Describes how intents should be generated for a particular entity type. 87*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 88*993b0882SAndroid Build Coastguard Workertable AndroidIntentFactoryEntityOptions { 89*993b0882SAndroid Build Coastguard Worker // The entity type as defined by one of the TextClassifier ENTITY_TYPE 90*993b0882SAndroid Build Coastguard Worker // constants. (e.g. "address", "phone", etc.) 91*993b0882SAndroid Build Coastguard Worker entity_type:string (shared); 92*993b0882SAndroid Build Coastguard Worker 93*993b0882SAndroid Build Coastguard Worker // List of generators for all the different types of intents that should 94*993b0882SAndroid Build Coastguard Worker // be made available for the entity type. 95*993b0882SAndroid Build Coastguard Worker generator:[AndroidIntentGeneratorOptions]; 96*993b0882SAndroid Build Coastguard Worker} 97*993b0882SAndroid Build Coastguard Worker 98*993b0882SAndroid Build Coastguard Worker// Configures a single Android Intent generator. 99*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 100*993b0882SAndroid Build Coastguard Workertable AndroidIntentGeneratorOptions { 101*993b0882SAndroid Build Coastguard Worker // Strings for UI elements. 102*993b0882SAndroid Build Coastguard Worker strings:[AndroidIntentGeneratorStrings]; 103*993b0882SAndroid Build Coastguard Worker 104*993b0882SAndroid Build Coastguard Worker // Generator specific configuration. 105*993b0882SAndroid Build Coastguard Worker simple:AndroidSimpleIntentGeneratorOptions; 106*993b0882SAndroid Build Coastguard Worker} 107*993b0882SAndroid Build Coastguard Worker 108*993b0882SAndroid Build Coastguard Worker// Language dependent configuration for an Android Intent generator. 109*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 110*993b0882SAndroid Build Coastguard Workertable AndroidIntentGeneratorStrings { 111*993b0882SAndroid Build Coastguard Worker // BCP 47 tag for the supported locale. Note that because of API level 112*993b0882SAndroid Build Coastguard Worker // restrictions, this must /not/ use wildcards. To e.g. match all English 113*993b0882SAndroid Build Coastguard Worker // locales, use only "en" and not "en_*". Reference the java.util.Locale 114*993b0882SAndroid Build Coastguard Worker // constructor for details. 115*993b0882SAndroid Build Coastguard Worker language_tag:string (shared); 116*993b0882SAndroid Build Coastguard Worker 117*993b0882SAndroid Build Coastguard Worker // Title shown for the action (see RemoteAction.getTitle). 118*993b0882SAndroid Build Coastguard Worker title:string (shared); 119*993b0882SAndroid Build Coastguard Worker 120*993b0882SAndroid Build Coastguard Worker // Description shown for the action (see 121*993b0882SAndroid Build Coastguard Worker // RemoteAction.getContentDescription). 122*993b0882SAndroid Build Coastguard Worker description:string (shared); 123*993b0882SAndroid Build Coastguard Worker} 124*993b0882SAndroid Build Coastguard Worker 125*993b0882SAndroid Build Coastguard Worker// An extra to set on a simple intent generator Intent. 126*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 127*993b0882SAndroid Build Coastguard Workertable AndroidSimpleIntentGeneratorExtra { 128*993b0882SAndroid Build Coastguard Worker // The name of the extra to set. 129*993b0882SAndroid Build Coastguard Worker name:string (shared); 130*993b0882SAndroid Build Coastguard Worker 131*993b0882SAndroid Build Coastguard Worker // The type of the extra to set. 132*993b0882SAndroid Build Coastguard Worker type:AndroidSimpleIntentGeneratorExtraType; 133*993b0882SAndroid Build Coastguard Worker 134*993b0882SAndroid Build Coastguard Worker string_:string (shared); 135*993b0882SAndroid Build Coastguard Worker bool_:bool; 136*993b0882SAndroid Build Coastguard Worker int32_:int; 137*993b0882SAndroid Build Coastguard Worker} 138*993b0882SAndroid Build Coastguard Worker 139*993b0882SAndroid Build Coastguard Worker// A condition that needs to be fulfilled for an Intent to get generated. 140*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 141*993b0882SAndroid Build Coastguard Workertable AndroidSimpleIntentGeneratorCondition { 142*993b0882SAndroid Build Coastguard Worker type:AndroidSimpleIntentGeneratorConditionType; 143*993b0882SAndroid Build Coastguard Worker string_:string (shared); 144*993b0882SAndroid Build Coastguard Worker int32_:int; 145*993b0882SAndroid Build Coastguard Worker int64_:long; 146*993b0882SAndroid Build Coastguard Worker} 147*993b0882SAndroid Build Coastguard Worker 148*993b0882SAndroid Build Coastguard Worker// Configures an intent generator where the logic is simple to be expressed with 149*993b0882SAndroid Build Coastguard Worker// basic rules - which covers the vast majority of use cases and is analogous 150*993b0882SAndroid Build Coastguard Worker// to Android Actions. 151*993b0882SAndroid Build Coastguard Worker// Most strings (action, data, type, ...) may contain variable references. To 152*993b0882SAndroid Build Coastguard Worker// use them, the generator must first declare all the variables it wishes to use 153*993b0882SAndroid Build Coastguard Worker// in the variables field. The values then become available as numbered 154*993b0882SAndroid Build Coastguard Worker// arguments (using the normal java.util.Formatter syntax) in the order they 155*993b0882SAndroid Build Coastguard Worker// were specified. 156*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 157*993b0882SAndroid Build Coastguard Workertable AndroidSimpleIntentGeneratorOptions { 158*993b0882SAndroid Build Coastguard Worker // The action to set on the Intent (see Intent.setAction). Supports variables. 159*993b0882SAndroid Build Coastguard Worker action:string (shared); 160*993b0882SAndroid Build Coastguard Worker 161*993b0882SAndroid Build Coastguard Worker // The data to set on the Intent (see Intent.setData). Supports variables. 162*993b0882SAndroid Build Coastguard Worker data:string (shared); 163*993b0882SAndroid Build Coastguard Worker 164*993b0882SAndroid Build Coastguard Worker // The type to set on the Intent (see Intent.setType). Supports variables. 165*993b0882SAndroid Build Coastguard Worker type:string (shared); 166*993b0882SAndroid Build Coastguard Worker 167*993b0882SAndroid Build Coastguard Worker // The list of all the extras to add to the Intent. 168*993b0882SAndroid Build Coastguard Worker extra:[AndroidSimpleIntentGeneratorExtra]; 169*993b0882SAndroid Build Coastguard Worker 170*993b0882SAndroid Build Coastguard Worker // The list of all the variables that become available for substitution in 171*993b0882SAndroid Build Coastguard Worker // the action, data, type and extra strings. To e.g. set a field to the value 172*993b0882SAndroid Build Coastguard Worker // of the first variable, use "%0$s". 173*993b0882SAndroid Build Coastguard Worker variable:[AndroidSimpleIntentGeneratorVariableType]; 174*993b0882SAndroid Build Coastguard Worker 175*993b0882SAndroid Build Coastguard Worker // The list of all conditions that need to be fulfilled for Intent generation. 176*993b0882SAndroid Build Coastguard Worker condition:[AndroidSimpleIntentGeneratorCondition]; 177*993b0882SAndroid Build Coastguard Worker} 178*993b0882SAndroid Build Coastguard Worker 179*993b0882SAndroid Build Coastguard Worker// Describes how intents should be generated for a particular entity type. 180*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3.IntentFactoryModel_; 181*993b0882SAndroid Build Coastguard Workertable IntentGenerator { 182*993b0882SAndroid Build Coastguard Worker // The type of the intent generator, e.g. the entity type as defined by 183*993b0882SAndroid Build Coastguard Worker // on the TextClassifier ENTITY_TYPE constants e.g. "address", "phone", etc. 184*993b0882SAndroid Build Coastguard Worker type:string (shared); 185*993b0882SAndroid Build Coastguard Worker 186*993b0882SAndroid Build Coastguard Worker // The template generator lua code, either as text source or precompiled 187*993b0882SAndroid Build Coastguard Worker // bytecode. 188*993b0882SAndroid Build Coastguard Worker lua_template_generator:[ubyte]; 189*993b0882SAndroid Build Coastguard Worker 190*993b0882SAndroid Build Coastguard Worker compressed_lua_template_generator:CompressedBuffer; 191*993b0882SAndroid Build Coastguard Worker} 192*993b0882SAndroid Build Coastguard Worker 193*993b0882SAndroid Build Coastguard Worker// Describes how intents for the various entity types should be generated. 194*993b0882SAndroid Build Coastguard Workernamespace libtextclassifier3; 195*993b0882SAndroid Build Coastguard Workertable IntentFactoryModel { 196*993b0882SAndroid Build Coastguard Worker generator:[IntentFactoryModel_.IntentGenerator]; 197*993b0882SAndroid Build Coastguard Worker 198*993b0882SAndroid Build Coastguard Worker // Whether to precompile the generators when loading. 199*993b0882SAndroid Build Coastguard Worker precompile_generators:bool = false; 200*993b0882SAndroid Build Coastguard Worker} 201*993b0882SAndroid Build Coastguard Worker 202