• 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 
17 package com.google.android.textclassifier;
18 
19 import android.content.res.AssetFileDescriptor;
20 import com.google.errorprone.annotations.CanIgnoreReturnValue;
21 import java.util.Collection;
22 import java.util.concurrent.atomic.AtomicBoolean;
23 import javax.annotation.Nullable;
24 
25 /**
26  * Java wrapper for Annotator native library interface. This library is used for detecting entities
27  * in text.
28  *
29  * @hide
30  */
31 public final class AnnotatorModel implements AutoCloseable {
32   private final AtomicBoolean isClosed = new AtomicBoolean(false);
33 
34   static {
35     System.loadLibrary("textclassifier");
36   }
37 
38   // Keep these in sync with the constants defined in AOSP.
39   static final String TYPE_UNKNOWN = "";
40   static final String TYPE_OTHER = "other";
41   static final String TYPE_EMAIL = "email";
42   static final String TYPE_PHONE = "phone";
43   static final String TYPE_ADDRESS = "address";
44   static final String TYPE_URL = "url";
45   static final String TYPE_DATE = "date";
46   static final String TYPE_DATE_TIME = "datetime";
47   static final String TYPE_FLIGHT_NUMBER = "flight";
48 
49   public static final double INVALID_LATITUDE = 180;
50   public static final double INVALID_LONGITUDE = 360;
51   public static final float INVALID_LOCATION_ACCURACY_METERS = 0;
52 
53   private long annotatorPtr;
54   // To tell GC to keep the LangID model alive at least as long as this object.
55   @Nullable private LangIdModel langIdModel;
56 
57   /** Enumeration for specifying the usecase of the annotations. */
58   public static enum AnnotationUsecase {
59     /** Results are optimized for Smart{Select,Share,Linkify}. */
60     SMART(0),
61 
62     /**
63      * Results are optimized for using TextClassifier as an infrastructure that annotates as much as
64      * possible.
65      */
66     RAW(1);
67 
68     private final int value;
69 
AnnotationUsecase(int value)70     AnnotationUsecase(int value) {
71       this.value = value;
72     }
73 
getValue()74     public int getValue() {
75       return value;
76     }
77   };
78 
79   /** Enumeration for specifying the annotate mode. */
80   public static enum AnnotateMode {
81     /** Result contains entity annotation for each input fragment. */
82     ENTITY_ANNOTATION(0),
83 
84     /** Result will include both entity annotation and topicality annotation. */
85     ENTITY_AND_TOPICALITY_ANNOTATION(1);
86 
87     private final int value;
88 
AnnotateMode(int value)89     AnnotateMode(int value) {
90       this.value = value;
91     }
92 
getValue()93     public int getValue() {
94       return value;
95     }
96   };
97 
98   /**
99    * Creates a new instance of SmartSelect predictor, using the provided model image, given as a
100    * file descriptor.
101    */
AnnotatorModel(int fileDescriptor)102   public AnnotatorModel(int fileDescriptor) {
103     annotatorPtr = nativeNewAnnotator(fileDescriptor);
104     if (annotatorPtr == 0L) {
105       throw new IllegalArgumentException("Couldn't initialize TC from file descriptor.");
106     }
107   }
108 
109   /**
110    * Creates a new instance of SmartSelect predictor, using the provided model image, given as a
111    * file path.
112    */
AnnotatorModel(String path)113   public AnnotatorModel(String path) {
114     annotatorPtr = nativeNewAnnotatorFromPath(path);
115     if (annotatorPtr == 0L) {
116       throw new IllegalArgumentException("Couldn't initialize TC from given file.");
117     }
118   }
119 
120   /**
121    * Creates a new instance of SmartSelect predictor, using the provided model image, given as an
122    * {@link AssetFileDescriptor}.
123    */
AnnotatorModel(AssetFileDescriptor assetFileDescriptor)124   public AnnotatorModel(AssetFileDescriptor assetFileDescriptor) {
125     annotatorPtr =
126         nativeNewAnnotatorWithOffset(
127             assetFileDescriptor.getParcelFileDescriptor().getFd(),
128             assetFileDescriptor.getStartOffset(),
129             assetFileDescriptor.getLength());
130     if (annotatorPtr == 0L) {
131       throw new IllegalArgumentException("Couldn't initialize TC from asset file descriptor.");
132     }
133   }
134 
135   /** Initializes the knowledge engine, passing the given serialized config to it. */
initializeKnowledgeEngine(byte[] serializedConfig)136   public void initializeKnowledgeEngine(byte[] serializedConfig) {
137     if (!nativeInitializeKnowledgeEngine(annotatorPtr, serializedConfig)) {
138       throw new IllegalArgumentException("Couldn't initialize the KG engine");
139     }
140   }
141 
142   /** Initializes the contact engine, passing the given serialized config to it. */
initializeContactEngine(byte[] serializedConfig)143   public void initializeContactEngine(byte[] serializedConfig) {
144     if (!nativeInitializeContactEngine(annotatorPtr, serializedConfig)) {
145       throw new IllegalArgumentException("Couldn't initialize the contact engine");
146     }
147   }
148 
149   /** Initializes the installed app engine, passing the given serialized config to it. */
initializeInstalledAppEngine(byte[] serializedConfig)150   public void initializeInstalledAppEngine(byte[] serializedConfig) {
151     if (!nativeInitializeInstalledAppEngine(annotatorPtr, serializedConfig)) {
152       throw new IllegalArgumentException("Couldn't initialize the installed app engine");
153     }
154   }
155 
156   /**
157    * Sets the LangId model to the annotator. Do not call close on the given LangIdModel object
158    * before this object is closed. Also, this object does not take the memory ownership of the given
159    * LangIdModel object.
160    */
setLangIdModel(@ullable LangIdModel langIdModel)161   public void setLangIdModel(@Nullable LangIdModel langIdModel) {
162     this.langIdModel = langIdModel;
163     nativeSetLangId(annotatorPtr, langIdModel == null ? 0 : langIdModel.getNativePointer());
164   }
165 
166   /**
167    * Initializes the person name engine, using the provided model image, given as an {@link
168    * AssetFileDescriptor}.
169    */
initializePersonNameEngine(AssetFileDescriptor assetFileDescriptor)170   public void initializePersonNameEngine(AssetFileDescriptor assetFileDescriptor) {
171     if (!nativeInitializePersonNameEngine(
172         annotatorPtr,
173         assetFileDescriptor.getParcelFileDescriptor().getFd(),
174         assetFileDescriptor.getStartOffset(),
175         assetFileDescriptor.getLength())) {
176       throw new IllegalArgumentException("Couldn't initialize the person name engine");
177     }
178   }
179 
180   /**
181    * Given a string context and current selection, computes the selection suggestion.
182    *
183    * <p>The begin and end are character indices into the context UTF8 string. selectionBegin is the
184    * character index where the selection begins, and selectionEnd is the index of one character past
185    * the selection span.
186    *
187    * <p>The return value is an array of two ints: suggested selection beginning and end, with the
188    * same semantics as the input selectionBeginning and selectionEnd.
189    */
suggestSelection( String context, int selectionBegin, int selectionEnd, SelectionOptions options)190   public int[] suggestSelection(
191       String context, int selectionBegin, int selectionEnd, SelectionOptions options) {
192     return nativeSuggestSelection(annotatorPtr, context, selectionBegin, selectionEnd, options);
193   }
194 
195   /**
196    * Given a string context and current selection, classifies the type of the selected text.
197    *
198    * <p>The begin and end params are character indices in the context string.
199    *
200    * <p>Returns an array of ClassificationResult objects with the probability scores for different
201    * collections.
202    */
classifyText( String context, int selectionBegin, int selectionEnd, ClassificationOptions options)203   public ClassificationResult[] classifyText(
204       String context, int selectionBegin, int selectionEnd, ClassificationOptions options) {
205     return classifyText(
206         context,
207         selectionBegin,
208         selectionEnd,
209         options,
210         /*appContext=*/ null,
211         /*resourcesLocale=*/ null);
212   }
213 
classifyText( String context, int selectionBegin, int selectionEnd, ClassificationOptions options, Object appContext, String resourcesLocale)214   public ClassificationResult[] classifyText(
215       String context,
216       int selectionBegin,
217       int selectionEnd,
218       ClassificationOptions options,
219       Object appContext,
220       String resourcesLocale) {
221     return nativeClassifyText(
222         annotatorPtr, context, selectionBegin, selectionEnd, options, appContext, resourcesLocale);
223   }
224 
225   /**
226    * Annotates given input text. The annotations should cover the whole input context except for
227    * whitespaces, and are sorted by their position in the context string.
228    */
annotate(String text, AnnotationOptions options)229   public AnnotatedSpan[] annotate(String text, AnnotationOptions options) {
230     return nativeAnnotate(annotatorPtr, text, options);
231   }
232 
233   /**
234    * Annotates multiple fragments of text at once. There will be one AnnotatedSpan array for each
235    * input fragment to annotate.
236    */
annotateStructuredInput(InputFragment[] fragments, AnnotationOptions options)237   public Annotations annotateStructuredInput(InputFragment[] fragments, AnnotationOptions options) {
238     return nativeAnnotateStructuredInput(annotatorPtr, fragments, options);
239   }
240 
241   /**
242    * Looks up a knowledge entity by its identifier. Returns null if the entity is not found or on
243    * error.
244    */
lookUpKnowledgeEntity(String id)245   public byte[] lookUpKnowledgeEntity(String id) {
246     return nativeLookUpKnowledgeEntity(annotatorPtr, id);
247   }
248 
249   /** Frees up the allocated memory. */
250   @Override
close()251   public void close() {
252     if (isClosed.compareAndSet(false, true)) {
253       nativeCloseAnnotator(annotatorPtr);
254       annotatorPtr = 0L;
255     }
256   }
257 
258   @Override
finalize()259   protected void finalize() throws Throwable {
260     try {
261       close();
262     } finally {
263       super.finalize();
264     }
265   }
266 
267   /** Returns a comma separated list of locales supported by the model as BCP 47 tags. */
getLocales(int fd)268   public static String getLocales(int fd) {
269     return nativeGetLocales(fd);
270   }
271 
272   /** Returns a comma separated list of locales supported by the model as BCP 47 tags. */
getLocales(AssetFileDescriptor assetFileDescriptor)273   public static String getLocales(AssetFileDescriptor assetFileDescriptor) {
274     return nativeGetLocalesWithOffset(
275         assetFileDescriptor.getParcelFileDescriptor().getFd(),
276         assetFileDescriptor.getStartOffset(),
277         assetFileDescriptor.getLength());
278   }
279 
280   /** Returns the version of the model. */
getVersion(int fd)281   public static int getVersion(int fd) {
282     return nativeGetVersion(fd);
283   }
284 
285   /** Returns the version of the model. */
getVersion(AssetFileDescriptor assetFileDescriptor)286   public static int getVersion(AssetFileDescriptor assetFileDescriptor) {
287     return nativeGetVersionWithOffset(
288         assetFileDescriptor.getParcelFileDescriptor().getFd(),
289         assetFileDescriptor.getStartOffset(),
290         assetFileDescriptor.getLength());
291   }
292 
293   /** Returns the name of the model. */
getName(int fd)294   public static String getName(int fd) {
295     return nativeGetName(fd);
296   }
297 
298   /** Returns the name of the model. */
getName(AssetFileDescriptor assetFileDescriptor)299   public static String getName(AssetFileDescriptor assetFileDescriptor) {
300     return nativeGetNameWithOffset(
301         assetFileDescriptor.getParcelFileDescriptor().getFd(),
302         assetFileDescriptor.getStartOffset(),
303         assetFileDescriptor.getLength());
304   }
305 
306   /** Information about a parsed time/date. */
307   public static final class DatetimeResult {
308 
309     public static final int GRANULARITY_YEAR = 0;
310     public static final int GRANULARITY_MONTH = 1;
311     public static final int GRANULARITY_WEEK = 2;
312     public static final int GRANULARITY_DAY = 3;
313     public static final int GRANULARITY_HOUR = 4;
314     public static final int GRANULARITY_MINUTE = 5;
315     public static final int GRANULARITY_SECOND = 6;
316 
317     private final long timeMsUtc;
318     private final int granularity;
319 
DatetimeResult(long timeMsUtc, int granularity)320     public DatetimeResult(long timeMsUtc, int granularity) {
321       this.timeMsUtc = timeMsUtc;
322       this.granularity = granularity;
323     }
324 
getTimeMsUtc()325     public long getTimeMsUtc() {
326       return timeMsUtc;
327     }
328 
getGranularity()329     public int getGranularity() {
330       return granularity;
331     }
332   }
333 
334   /** Classification result for classifyText method. */
335   public static final class ClassificationResult {
336     private final String collection;
337     private final float score;
338     @Nullable private final DatetimeResult datetimeResult;
339     @Nullable private final byte[] serializedKnowledgeResult;
340     @Nullable private final String contactName;
341     @Nullable private final String contactGivenName;
342     @Nullable private final String contactFamilyName;
343     @Nullable private final String contactNickname;
344     @Nullable private final String contactEmailAddress;
345     @Nullable private final String contactPhoneNumber;
346     @Nullable private final String contactAccountType;
347     @Nullable private final String contactAccountName;
348     @Nullable private final String contactId;
349     @Nullable private final String appName;
350     @Nullable private final String appPackageName;
351     @Nullable private final NamedVariant[] entityData;
352     @Nullable private final byte[] serializedEntityData;
353     @Nullable private final RemoteActionTemplate[] remoteActionTemplates;
354     private final long durationMs;
355     private final long numericValue;
356     private final double numericDoubleValue;
357 
ClassificationResult( String collection, float score, @Nullable DatetimeResult datetimeResult, @Nullable byte[] serializedKnowledgeResult, @Nullable String contactName, @Nullable String contactGivenName, @Nullable String contactFamilyName, @Nullable String contactNickname, @Nullable String contactEmailAddress, @Nullable String contactPhoneNumber, @Nullable String contactAccountType, @Nullable String contactAccountName, @Nullable String contactId, @Nullable String appName, @Nullable String appPackageName, @Nullable NamedVariant[] entityData, @Nullable byte[] serializedEntityData, @Nullable RemoteActionTemplate[] remoteActionTemplates, long durationMs, long numericValue, double numericDoubleValue)358     public ClassificationResult(
359         String collection,
360         float score,
361         @Nullable DatetimeResult datetimeResult,
362         @Nullable byte[] serializedKnowledgeResult,
363         @Nullable String contactName,
364         @Nullable String contactGivenName,
365         @Nullable String contactFamilyName,
366         @Nullable String contactNickname,
367         @Nullable String contactEmailAddress,
368         @Nullable String contactPhoneNumber,
369         @Nullable String contactAccountType,
370         @Nullable String contactAccountName,
371         @Nullable String contactId,
372         @Nullable String appName,
373         @Nullable String appPackageName,
374         @Nullable NamedVariant[] entityData,
375         @Nullable byte[] serializedEntityData,
376         @Nullable RemoteActionTemplate[] remoteActionTemplates,
377         long durationMs,
378         long numericValue,
379         double numericDoubleValue) {
380       this.collection = collection;
381       this.score = score;
382       this.datetimeResult = datetimeResult;
383       this.serializedKnowledgeResult = serializedKnowledgeResult;
384       this.contactName = contactName;
385       this.contactGivenName = contactGivenName;
386       this.contactFamilyName = contactFamilyName;
387       this.contactNickname = contactNickname;
388       this.contactEmailAddress = contactEmailAddress;
389       this.contactPhoneNumber = contactPhoneNumber;
390       this.contactAccountType = contactAccountType;
391       this.contactAccountName = contactAccountName;
392       this.contactId = contactId;
393       this.appName = appName;
394       this.appPackageName = appPackageName;
395       this.entityData = entityData;
396       this.serializedEntityData = serializedEntityData;
397       this.remoteActionTemplates = remoteActionTemplates;
398       this.durationMs = durationMs;
399       this.numericValue = numericValue;
400       this.numericDoubleValue = numericDoubleValue;
401     }
402 
403     /** Returns the classified entity type. */
getCollection()404     public String getCollection() {
405       return collection;
406     }
407 
408     /** Confidence score between 0 and 1. */
getScore()409     public float getScore() {
410       return score;
411     }
412 
413     @Nullable
getDatetimeResult()414     public DatetimeResult getDatetimeResult() {
415       return datetimeResult;
416     }
417 
418     @Nullable
getSerializedKnowledgeResult()419     public byte[] getSerializedKnowledgeResult() {
420       return serializedKnowledgeResult;
421     }
422 
423     @Nullable
getContactName()424     public String getContactName() {
425       return contactName;
426     }
427 
428     @Nullable
getContactGivenName()429     public String getContactGivenName() {
430       return contactGivenName;
431     }
432 
433     @Nullable
getContactFamilyName()434     public String getContactFamilyName() {
435       return contactFamilyName;
436     }
437 
438     @Nullable
getContactNickname()439     public String getContactNickname() {
440       return contactNickname;
441     }
442 
443     @Nullable
getContactEmailAddress()444     public String getContactEmailAddress() {
445       return contactEmailAddress;
446     }
447 
448     @Nullable
getContactPhoneNumber()449     public String getContactPhoneNumber() {
450       return contactPhoneNumber;
451     }
452 
453     @Nullable
getContactAccountType()454     public String getContactAccountType() {
455       return contactAccountType;
456     }
457 
458     @Nullable
getContactAccountName()459     public String getContactAccountName() {
460       return contactAccountName;
461     }
462 
463     @Nullable
getContactId()464     public String getContactId() {
465       return contactId;
466     }
467 
468     @Nullable
getAppName()469     public String getAppName() {
470       return appName;
471     }
472 
473     @Nullable
getAppPackageName()474     public String getAppPackageName() {
475       return appPackageName;
476     }
477 
478     @Nullable
getEntityData()479     public NamedVariant[] getEntityData() {
480       return entityData;
481     }
482 
483     @Nullable
getSerializedEntityData()484     public byte[] getSerializedEntityData() {
485       return serializedEntityData;
486     }
487 
488     @Nullable
getRemoteActionTemplates()489     public RemoteActionTemplate[] getRemoteActionTemplates() {
490       return remoteActionTemplates;
491     }
492 
getDurationMs()493     public long getDurationMs() {
494       return durationMs;
495     }
496 
getNumericValue()497     public long getNumericValue() {
498       return numericValue;
499     }
500 
getNumericDoubleValue()501     public double getNumericDoubleValue() {
502       return numericDoubleValue;
503     }
504   }
505 
506   /** Represents a result of Annotate call. */
507   public static final class AnnotatedSpan {
508     private final int startIndex;
509     private final int endIndex;
510     private final ClassificationResult[] classification;
511 
AnnotatedSpan(int startIndex, int endIndex, ClassificationResult[] classification)512     AnnotatedSpan(int startIndex, int endIndex, ClassificationResult[] classification) {
513       this.startIndex = startIndex;
514       this.endIndex = endIndex;
515       this.classification = classification;
516     }
517 
getStartIndex()518     public int getStartIndex() {
519       return startIndex;
520     }
521 
getEndIndex()522     public int getEndIndex() {
523       return endIndex;
524     }
525 
getClassification()526     public ClassificationResult[] getClassification() {
527       return classification;
528     }
529   }
530 
531   /**
532    * Represents a result of Annotate call, which will include both entity annotations and topicality
533    * annotations.
534    */
535   public static final class Annotations {
536     private final AnnotatedSpan[][] annotatedSpans;
537     private final ClassificationResult[] topicalityResults;
538 
Annotations(AnnotatedSpan[][] annotatedSpans, ClassificationResult[] topicalityResults)539     Annotations(AnnotatedSpan[][] annotatedSpans, ClassificationResult[] topicalityResults) {
540       this.annotatedSpans = annotatedSpans;
541       this.topicalityResults = topicalityResults;
542     }
543 
getAnnotatedSpans()544     public AnnotatedSpan[][] getAnnotatedSpans() {
545       return annotatedSpans;
546     }
547 
getTopicalityResults()548     public ClassificationResult[] getTopicalityResults() {
549       return topicalityResults;
550     }
551   }
552 
553   /** Represents a fragment of text to the AnnotateStructuredInput call. */
554   public static final class InputFragment {
555 
556     /** Encapsulates the data required to set the relative time of an InputFragment. */
557     public static final class DatetimeOptions {
558       private final String referenceTimezone;
559       private final Long referenceTimeMsUtc;
560 
DatetimeOptions(String referenceTimezone, Long referenceTimeMsUtc)561       public DatetimeOptions(String referenceTimezone, Long referenceTimeMsUtc) {
562         this.referenceTimeMsUtc = referenceTimeMsUtc;
563         this.referenceTimezone = referenceTimezone;
564       }
565     }
566 
InputFragment(String text)567     public InputFragment(String text) {
568       this.text = text;
569       this.datetimeOptionsNullable = null;
570       this.boundingBoxTop = 0;
571       this.boundingBoxHeight = 0;
572     }
573 
InputFragment( String text, DatetimeOptions datetimeOptions, float boundingBoxTop, float boundingBoxHeight)574     public InputFragment(
575         String text,
576         DatetimeOptions datetimeOptions,
577         float boundingBoxTop,
578         float boundingBoxHeight) {
579       this.text = text;
580       this.datetimeOptionsNullable = datetimeOptions;
581       this.boundingBoxTop = boundingBoxTop;
582       this.boundingBoxHeight = boundingBoxHeight;
583     }
584 
585     private final String text;
586     // The DatetimeOptions can't be Optional because the _api16 build of the TCLib SDK does not
587     // support java.util.Optional.
588     private final DatetimeOptions datetimeOptionsNullable;
589     private final float boundingBoxTop;
590     private final float boundingBoxHeight;
591 
getText()592     public String getText() {
593       return text;
594     }
595 
getBoundingBoxTop()596     public float getBoundingBoxTop() {
597       return boundingBoxTop;
598     }
599 
getBoundingBoxHeight()600     public float getBoundingBoxHeight() {
601       return boundingBoxHeight;
602     }
603 
hasDatetimeOptions()604     public boolean hasDatetimeOptions() {
605       return datetimeOptionsNullable != null;
606     }
607 
getReferenceTimeMsUtc()608     public long getReferenceTimeMsUtc() {
609       return datetimeOptionsNullable.referenceTimeMsUtc;
610     }
611 
getReferenceTimezone()612     public String getReferenceTimezone() {
613       return datetimeOptionsNullable.referenceTimezone;
614     }
615   }
616 
617   /** Represents options for the suggestSelection call. */
618   public static final class SelectionOptions {
619     @Nullable private final String locales;
620     @Nullable private final String detectedTextLanguageTags;
621     private final int annotationUsecase;
622     private final double userLocationLat;
623     private final double userLocationLng;
624     private final float userLocationAccuracyMeters;
625     private final boolean usePodNer;
626     private final boolean useVocabAnnotator;
627 
SelectionOptions( @ullable String locales, @Nullable String detectedTextLanguageTags, int annotationUsecase, double userLocationLat, double userLocationLng, float userLocationAccuracyMeters, boolean usePodNer, boolean useVocabAnnotator)628     private SelectionOptions(
629         @Nullable String locales,
630         @Nullable String detectedTextLanguageTags,
631         int annotationUsecase,
632         double userLocationLat,
633         double userLocationLng,
634         float userLocationAccuracyMeters,
635         boolean usePodNer,
636         boolean useVocabAnnotator) {
637       this.locales = locales;
638       this.detectedTextLanguageTags = detectedTextLanguageTags;
639       this.annotationUsecase = annotationUsecase;
640       this.userLocationLat = userLocationLat;
641       this.userLocationLng = userLocationLng;
642       this.userLocationAccuracyMeters = userLocationAccuracyMeters;
643       this.usePodNer = usePodNer;
644       this.useVocabAnnotator = useVocabAnnotator;
645     }
646 
647     /** Can be used to build a SelectionsOptions instance. */
648     public static class Builder {
649       @Nullable private String locales;
650       @Nullable private String detectedTextLanguageTags;
651       private int annotationUsecase = AnnotationUsecase.SMART.getValue();
652       private double userLocationLat = INVALID_LATITUDE;
653       private double userLocationLng = INVALID_LONGITUDE;
654       private float userLocationAccuracyMeters = INVALID_LOCATION_ACCURACY_METERS;
655       private boolean usePodNer = true;
656       private boolean useVocabAnnotator = true;
657 
658       @CanIgnoreReturnValue
setLocales(@ullable String locales)659       public Builder setLocales(@Nullable String locales) {
660         this.locales = locales;
661         return this;
662       }
663 
664       @CanIgnoreReturnValue
setDetectedTextLanguageTags(@ullable String detectedTextLanguageTags)665       public Builder setDetectedTextLanguageTags(@Nullable String detectedTextLanguageTags) {
666         this.detectedTextLanguageTags = detectedTextLanguageTags;
667         return this;
668       }
669 
670       @CanIgnoreReturnValue
setAnnotationUsecase(int annotationUsecase)671       public Builder setAnnotationUsecase(int annotationUsecase) {
672         this.annotationUsecase = annotationUsecase;
673         return this;
674       }
675 
676       @CanIgnoreReturnValue
setUserLocationLat(double userLocationLat)677       public Builder setUserLocationLat(double userLocationLat) {
678         this.userLocationLat = userLocationLat;
679         return this;
680       }
681 
682       @CanIgnoreReturnValue
setUserLocationLng(double userLocationLng)683       public Builder setUserLocationLng(double userLocationLng) {
684         this.userLocationLng = userLocationLng;
685         return this;
686       }
687 
688       @CanIgnoreReturnValue
setUserLocationAccuracyMeters(float userLocationAccuracyMeters)689       public Builder setUserLocationAccuracyMeters(float userLocationAccuracyMeters) {
690         this.userLocationAccuracyMeters = userLocationAccuracyMeters;
691         return this;
692       }
693 
694       @CanIgnoreReturnValue
setUsePodNer(boolean usePodNer)695       public Builder setUsePodNer(boolean usePodNer) {
696         this.usePodNer = usePodNer;
697         return this;
698       }
699 
700       @CanIgnoreReturnValue
setUseVocabAnnotator(boolean useVocabAnnotator)701       public Builder setUseVocabAnnotator(boolean useVocabAnnotator) {
702         this.useVocabAnnotator = useVocabAnnotator;
703         return this;
704       }
705 
build()706       public SelectionOptions build() {
707         return new SelectionOptions(
708             locales,
709             detectedTextLanguageTags,
710             annotationUsecase,
711             userLocationLat,
712             userLocationLng,
713             userLocationAccuracyMeters,
714             usePodNer,
715             useVocabAnnotator);
716       }
717     }
718 
builder()719     public static Builder builder() {
720       return new Builder();
721     }
722 
723     @Nullable
getLocales()724     public String getLocales() {
725       return locales;
726     }
727 
728     /** Returns a comma separated list of BCP 47 language tags. */
729     @Nullable
getDetectedTextLanguageTags()730     public String getDetectedTextLanguageTags() {
731       return detectedTextLanguageTags;
732     }
733 
getAnnotationUsecase()734     public int getAnnotationUsecase() {
735       return annotationUsecase;
736     }
737 
getUserLocationLat()738     public double getUserLocationLat() {
739       return userLocationLat;
740     }
741 
getUserLocationLng()742     public double getUserLocationLng() {
743       return userLocationLng;
744     }
745 
getUserLocationAccuracyMeters()746     public float getUserLocationAccuracyMeters() {
747       return userLocationAccuracyMeters;
748     }
749 
getUsePodNer()750     public boolean getUsePodNer() {
751       return usePodNer;
752     }
753 
getUseVocabAnnotator()754     public boolean getUseVocabAnnotator() {
755       return useVocabAnnotator;
756     }
757   }
758 
759   /** Represents options for the classifyText call. */
760   public static final class ClassificationOptions {
761     private final long referenceTimeMsUtc;
762     private final String referenceTimezone;
763     @Nullable private final String locales;
764     @Nullable private final String detectedTextLanguageTags;
765     private final int annotationUsecase;
766     private final double userLocationLat;
767     private final double userLocationLng;
768     private final float userLocationAccuracyMeters;
769     private final String userFamiliarLanguageTags;
770     private final boolean usePodNer;
771     private final boolean triggerDictionaryOnBeginnerWords;
772     private final boolean useVocabAnnotator;
773     private final boolean enableAddContactIntent;
774     private final boolean enableSearchIntent;
775 
ClassificationOptions( long referenceTimeMsUtc, String referenceTimezone, @Nullable String locales, @Nullable String detectedTextLanguageTags, int annotationUsecase, double userLocationLat, double userLocationLng, float userLocationAccuracyMeters, String userFamiliarLanguageTags, boolean usePodNer, boolean triggerDictionaryOnBeginnerWords, boolean useVocabAnnotator, boolean enableAddContactIntent, boolean enableSearchIntent)776     private ClassificationOptions(
777         long referenceTimeMsUtc,
778         String referenceTimezone,
779         @Nullable String locales,
780         @Nullable String detectedTextLanguageTags,
781         int annotationUsecase,
782         double userLocationLat,
783         double userLocationLng,
784         float userLocationAccuracyMeters,
785         String userFamiliarLanguageTags,
786         boolean usePodNer,
787         boolean triggerDictionaryOnBeginnerWords,
788         boolean useVocabAnnotator,
789         boolean enableAddContactIntent,
790         boolean enableSearchIntent) {
791       this.referenceTimeMsUtc = referenceTimeMsUtc;
792       this.referenceTimezone = referenceTimezone;
793       this.locales = locales;
794       this.detectedTextLanguageTags = detectedTextLanguageTags;
795       this.annotationUsecase = annotationUsecase;
796       this.userLocationLat = userLocationLat;
797       this.userLocationLng = userLocationLng;
798       this.userLocationAccuracyMeters = userLocationAccuracyMeters;
799       this.userFamiliarLanguageTags = userFamiliarLanguageTags;
800       this.usePodNer = usePodNer;
801       this.triggerDictionaryOnBeginnerWords = triggerDictionaryOnBeginnerWords;
802       this.useVocabAnnotator = useVocabAnnotator;
803       this.enableAddContactIntent = enableAddContactIntent;
804       this.enableSearchIntent = enableSearchIntent;
805     }
806 
807     /** Can be used to build a ClassificationOptions instance. */
808     public static class Builder {
809       private long referenceTimeMsUtc;
810       @Nullable private String referenceTimezone;
811       @Nullable private String locales;
812       @Nullable private String detectedTextLanguageTags;
813       private int annotationUsecase = AnnotationUsecase.SMART.getValue();
814       private double userLocationLat = INVALID_LATITUDE;
815       private double userLocationLng = INVALID_LONGITUDE;
816       private float userLocationAccuracyMeters = INVALID_LOCATION_ACCURACY_METERS;
817       private String userFamiliarLanguageTags = "";
818       private boolean usePodNer = true;
819       private boolean triggerDictionaryOnBeginnerWords = false;
820       private boolean useVocabAnnotator = true;
821       private boolean enableAddContactIntent = false;
822       private boolean enableSearchIntent = false;
823 
824       @CanIgnoreReturnValue
setReferenceTimeMsUtc(long referenceTimeMsUtc)825       public Builder setReferenceTimeMsUtc(long referenceTimeMsUtc) {
826         this.referenceTimeMsUtc = referenceTimeMsUtc;
827         return this;
828       }
829 
830       @CanIgnoreReturnValue
setReferenceTimezone(String referenceTimezone)831       public Builder setReferenceTimezone(String referenceTimezone) {
832         this.referenceTimezone = referenceTimezone;
833         return this;
834       }
835 
836       @CanIgnoreReturnValue
setLocales(@ullable String locales)837       public Builder setLocales(@Nullable String locales) {
838         this.locales = locales;
839         return this;
840       }
841 
842       @CanIgnoreReturnValue
setDetectedTextLanguageTags(@ullable String detectedTextLanguageTags)843       public Builder setDetectedTextLanguageTags(@Nullable String detectedTextLanguageTags) {
844         this.detectedTextLanguageTags = detectedTextLanguageTags;
845         return this;
846       }
847 
848       @CanIgnoreReturnValue
setAnnotationUsecase(int annotationUsecase)849       public Builder setAnnotationUsecase(int annotationUsecase) {
850         this.annotationUsecase = annotationUsecase;
851         return this;
852       }
853 
854       @CanIgnoreReturnValue
setUserLocationLat(double userLocationLat)855       public Builder setUserLocationLat(double userLocationLat) {
856         this.userLocationLat = userLocationLat;
857         return this;
858       }
859 
860       @CanIgnoreReturnValue
setUserLocationLng(double userLocationLng)861       public Builder setUserLocationLng(double userLocationLng) {
862         this.userLocationLng = userLocationLng;
863         return this;
864       }
865 
866       @CanIgnoreReturnValue
setUserLocationAccuracyMeters(float userLocationAccuracyMeters)867       public Builder setUserLocationAccuracyMeters(float userLocationAccuracyMeters) {
868         this.userLocationAccuracyMeters = userLocationAccuracyMeters;
869         return this;
870       }
871 
872       @CanIgnoreReturnValue
setUserFamiliarLanguageTags(String userFamiliarLanguageTags)873       public Builder setUserFamiliarLanguageTags(String userFamiliarLanguageTags) {
874         this.userFamiliarLanguageTags = userFamiliarLanguageTags;
875         return this;
876       }
877 
878       @CanIgnoreReturnValue
setUsePodNer(boolean usePodNer)879       public Builder setUsePodNer(boolean usePodNer) {
880         this.usePodNer = usePodNer;
881         return this;
882       }
883 
884       @CanIgnoreReturnValue
setTrigerringDictionaryOnBeginnerWords( boolean triggerDictionaryOnBeginnerWords)885       public Builder setTrigerringDictionaryOnBeginnerWords(
886           boolean triggerDictionaryOnBeginnerWords) {
887         this.triggerDictionaryOnBeginnerWords = triggerDictionaryOnBeginnerWords;
888         return this;
889       }
890 
891       @CanIgnoreReturnValue
setUseVocabAnnotator(boolean useVocabAnnotator)892       public Builder setUseVocabAnnotator(boolean useVocabAnnotator) {
893         this.useVocabAnnotator = useVocabAnnotator;
894         return this;
895       }
896 
897       @CanIgnoreReturnValue
setEnableAddContactIntent(boolean enableAddContactIntent)898       public Builder setEnableAddContactIntent(boolean enableAddContactIntent) {
899         this.enableAddContactIntent = enableAddContactIntent;
900         return this;
901       }
902 
903       @CanIgnoreReturnValue
setEnableSearchIntent(boolean enableSearchIntent)904       public Builder setEnableSearchIntent(boolean enableSearchIntent) {
905         this.enableSearchIntent = enableSearchIntent;
906         return this;
907       }
908 
build()909       public ClassificationOptions build() {
910         return new ClassificationOptions(
911             referenceTimeMsUtc,
912             referenceTimezone,
913             locales,
914             detectedTextLanguageTags,
915             annotationUsecase,
916             userLocationLat,
917             userLocationLng,
918             userLocationAccuracyMeters,
919             userFamiliarLanguageTags,
920             usePodNer,
921             triggerDictionaryOnBeginnerWords,
922             useVocabAnnotator,
923             enableAddContactIntent,
924             enableSearchIntent);
925       }
926     }
927 
builder()928     public static Builder builder() {
929       return new Builder();
930     }
931 
getReferenceTimeMsUtc()932     public long getReferenceTimeMsUtc() {
933       return referenceTimeMsUtc;
934     }
935 
getReferenceTimezone()936     public String getReferenceTimezone() {
937       return referenceTimezone;
938     }
939 
940     @Nullable
getLocale()941     public String getLocale() {
942       return locales;
943     }
944 
945     /** Returns a comma separated list of BCP 47 language tags. */
946     @Nullable
getDetectedTextLanguageTags()947     public String getDetectedTextLanguageTags() {
948       return detectedTextLanguageTags;
949     }
950 
getAnnotationUsecase()951     public int getAnnotationUsecase() {
952       return annotationUsecase;
953     }
954 
getUserLocationLat()955     public double getUserLocationLat() {
956       return userLocationLat;
957     }
958 
getUserLocationLng()959     public double getUserLocationLng() {
960       return userLocationLng;
961     }
962 
getUserLocationAccuracyMeters()963     public float getUserLocationAccuracyMeters() {
964       return userLocationAccuracyMeters;
965     }
966 
getUserFamiliarLanguageTags()967     public String getUserFamiliarLanguageTags() {
968       return userFamiliarLanguageTags;
969     }
970 
getUsePodNer()971     public boolean getUsePodNer() {
972       return usePodNer;
973     }
974 
getTriggerDictionaryOnBeginnerWords()975     public boolean getTriggerDictionaryOnBeginnerWords() {
976       return triggerDictionaryOnBeginnerWords;
977     }
978 
getUseVocabAnnotator()979     public boolean getUseVocabAnnotator() {
980       return useVocabAnnotator;
981     }
982 
getEnableAddContactIntent()983     public boolean getEnableAddContactIntent() {
984       return enableAddContactIntent;
985     }
986 
getEnableSearchIntent()987     public boolean getEnableSearchIntent() {
988       return enableSearchIntent;
989     }
990   }
991 
992   /** Represents options for the annotate call. */
993   public static final class AnnotationOptions {
994     private final long referenceTimeMsUtc;
995     private final String referenceTimezone;
996     @Nullable private final String locales;
997     @Nullable private final String detectedTextLanguageTags;
998     private final String[] entityTypes;
999     private final int annotateMode;
1000     private final int annotationUsecase;
1001     private final boolean hasLocationPermission;
1002     private final boolean hasPersonalizationPermission;
1003     private final boolean isSerializedEntityDataEnabled;
1004     private final double userLocationLat;
1005     private final double userLocationLng;
1006     private final float userLocationAccuracyMeters;
1007     private final boolean usePodNer;
1008     private final boolean triggerDictionaryOnBeginnerWords;
1009     private final boolean useVocabAnnotator;
1010 
AnnotationOptions( long referenceTimeMsUtc, String referenceTimezone, @Nullable String locales, @Nullable String detectedTextLanguageTags, @Nullable Collection<String> entityTypes, int annotateMode, int annotationUsecase, boolean hasLocationPermission, boolean hasPersonalizationPermission, boolean isSerializedEntityDataEnabled, double userLocationLat, double userLocationLng, float userLocationAccuracyMeters, boolean usePodNer, boolean triggerDictionaryOnBeginnerWords, boolean useVocabAnnotator)1011     private AnnotationOptions(
1012         long referenceTimeMsUtc,
1013         String referenceTimezone,
1014         @Nullable String locales,
1015         @Nullable String detectedTextLanguageTags,
1016         @Nullable Collection<String> entityTypes,
1017         int annotateMode,
1018         int annotationUsecase,
1019         boolean hasLocationPermission,
1020         boolean hasPersonalizationPermission,
1021         boolean isSerializedEntityDataEnabled,
1022         double userLocationLat,
1023         double userLocationLng,
1024         float userLocationAccuracyMeters,
1025         boolean usePodNer,
1026         boolean triggerDictionaryOnBeginnerWords,
1027         boolean useVocabAnnotator) {
1028       this.referenceTimeMsUtc = referenceTimeMsUtc;
1029       this.referenceTimezone = referenceTimezone;
1030       this.locales = locales;
1031       this.detectedTextLanguageTags = detectedTextLanguageTags;
1032       this.entityTypes = entityTypes == null ? new String[0] : entityTypes.toArray(new String[0]);
1033       this.annotateMode = annotateMode;
1034       this.annotationUsecase = annotationUsecase;
1035       this.isSerializedEntityDataEnabled = isSerializedEntityDataEnabled;
1036       this.userLocationLat = userLocationLat;
1037       this.userLocationLng = userLocationLng;
1038       this.userLocationAccuracyMeters = userLocationAccuracyMeters;
1039       this.hasLocationPermission = hasLocationPermission;
1040       this.hasPersonalizationPermission = hasPersonalizationPermission;
1041       this.usePodNer = usePodNer;
1042       this.triggerDictionaryOnBeginnerWords = triggerDictionaryOnBeginnerWords;
1043       this.useVocabAnnotator = useVocabAnnotator;
1044     }
1045 
1046     /** Can be used to build an AnnotationOptions instance. */
1047     public static class Builder {
1048       private long referenceTimeMsUtc;
1049       @Nullable private String referenceTimezone;
1050       @Nullable private String locales;
1051       @Nullable private String detectedTextLanguageTags;
1052       @Nullable private Collection<String> entityTypes;
1053       private int annotateMode = AnnotateMode.ENTITY_ANNOTATION.getValue();
1054       private int annotationUsecase = AnnotationUsecase.SMART.getValue();
1055       private boolean hasLocationPermission = true;
1056       private boolean hasPersonalizationPermission = true;
1057       private boolean isSerializedEntityDataEnabled = false;
1058       private double userLocationLat = INVALID_LATITUDE;
1059       private double userLocationLng = INVALID_LONGITUDE;
1060       private float userLocationAccuracyMeters = INVALID_LOCATION_ACCURACY_METERS;
1061       private boolean usePodNer = true;
1062       private boolean triggerDictionaryOnBeginnerWords = false;
1063       private boolean useVocabAnnotator = true;
1064 
1065       @CanIgnoreReturnValue
setReferenceTimeMsUtc(long referenceTimeMsUtc)1066       public Builder setReferenceTimeMsUtc(long referenceTimeMsUtc) {
1067         this.referenceTimeMsUtc = referenceTimeMsUtc;
1068         return this;
1069       }
1070 
1071       @CanIgnoreReturnValue
setReferenceTimezone(String referenceTimezone)1072       public Builder setReferenceTimezone(String referenceTimezone) {
1073         this.referenceTimezone = referenceTimezone;
1074         return this;
1075       }
1076 
1077       @CanIgnoreReturnValue
setLocales(@ullable String locales)1078       public Builder setLocales(@Nullable String locales) {
1079         this.locales = locales;
1080         return this;
1081       }
1082 
1083       @CanIgnoreReturnValue
setDetectedTextLanguageTags(@ullable String detectedTextLanguageTags)1084       public Builder setDetectedTextLanguageTags(@Nullable String detectedTextLanguageTags) {
1085         this.detectedTextLanguageTags = detectedTextLanguageTags;
1086         return this;
1087       }
1088 
1089       @CanIgnoreReturnValue
setEntityTypes(Collection<String> entityTypes)1090       public Builder setEntityTypes(Collection<String> entityTypes) {
1091         this.entityTypes = entityTypes;
1092         return this;
1093       }
1094 
1095       @CanIgnoreReturnValue
setAnnotateMode(int annotateMode)1096       public Builder setAnnotateMode(int annotateMode) {
1097         this.annotateMode = annotateMode;
1098         return this;
1099       }
1100 
1101       @CanIgnoreReturnValue
setAnnotationUsecase(int annotationUsecase)1102       public Builder setAnnotationUsecase(int annotationUsecase) {
1103         this.annotationUsecase = annotationUsecase;
1104         return this;
1105       }
1106 
1107       @CanIgnoreReturnValue
setHasLocationPermission(boolean hasLocationPermission)1108       public Builder setHasLocationPermission(boolean hasLocationPermission) {
1109         this.hasLocationPermission = hasLocationPermission;
1110         return this;
1111       }
1112 
1113       @CanIgnoreReturnValue
setHasPersonalizationPermission(boolean hasPersonalizationPermission)1114       public Builder setHasPersonalizationPermission(boolean hasPersonalizationPermission) {
1115         this.hasPersonalizationPermission = hasPersonalizationPermission;
1116         return this;
1117       }
1118 
1119       @CanIgnoreReturnValue
setIsSerializedEntityDataEnabled(boolean isSerializedEntityDataEnabled)1120       public Builder setIsSerializedEntityDataEnabled(boolean isSerializedEntityDataEnabled) {
1121         this.isSerializedEntityDataEnabled = isSerializedEntityDataEnabled;
1122         return this;
1123       }
1124 
1125       @CanIgnoreReturnValue
setUserLocationLat(double userLocationLat)1126       public Builder setUserLocationLat(double userLocationLat) {
1127         this.userLocationLat = userLocationLat;
1128         return this;
1129       }
1130 
1131       @CanIgnoreReturnValue
setUserLocationLng(double userLocationLng)1132       public Builder setUserLocationLng(double userLocationLng) {
1133         this.userLocationLng = userLocationLng;
1134         return this;
1135       }
1136 
1137       @CanIgnoreReturnValue
setUserLocationAccuracyMeters(float userLocationAccuracyMeters)1138       public Builder setUserLocationAccuracyMeters(float userLocationAccuracyMeters) {
1139         this.userLocationAccuracyMeters = userLocationAccuracyMeters;
1140         return this;
1141       }
1142 
1143       @CanIgnoreReturnValue
setUsePodNer(boolean usePodNer)1144       public Builder setUsePodNer(boolean usePodNer) {
1145         this.usePodNer = usePodNer;
1146         return this;
1147       }
1148 
1149       @CanIgnoreReturnValue
setTriggerDictionaryOnBeginnerWords(boolean triggerDictionaryOnBeginnerWords)1150       public Builder setTriggerDictionaryOnBeginnerWords(boolean triggerDictionaryOnBeginnerWords) {
1151         this.triggerDictionaryOnBeginnerWords = triggerDictionaryOnBeginnerWords;
1152         return this;
1153       }
1154 
1155       @CanIgnoreReturnValue
setUseVocabAnnotator(boolean useVocabAnnotator)1156       public Builder setUseVocabAnnotator(boolean useVocabAnnotator) {
1157         this.useVocabAnnotator = useVocabAnnotator;
1158         return this;
1159       }
1160 
build()1161       public AnnotationOptions build() {
1162         return new AnnotationOptions(
1163             referenceTimeMsUtc,
1164             referenceTimezone,
1165             locales,
1166             detectedTextLanguageTags,
1167             entityTypes,
1168             annotateMode,
1169             annotationUsecase,
1170             hasLocationPermission,
1171             hasPersonalizationPermission,
1172             isSerializedEntityDataEnabled,
1173             userLocationLat,
1174             userLocationLng,
1175             userLocationAccuracyMeters,
1176             usePodNer,
1177             triggerDictionaryOnBeginnerWords,
1178             useVocabAnnotator);
1179       }
1180     }
1181 
builder()1182     public static Builder builder() {
1183       return new Builder();
1184     }
1185 
getReferenceTimeMsUtc()1186     public long getReferenceTimeMsUtc() {
1187       return referenceTimeMsUtc;
1188     }
1189 
getReferenceTimezone()1190     public String getReferenceTimezone() {
1191       return referenceTimezone;
1192     }
1193 
1194     @Nullable
getLocale()1195     public String getLocale() {
1196       return locales;
1197     }
1198 
1199     /** Returns a comma separated list of BCP 47 language tags. */
1200     @Nullable
getDetectedTextLanguageTags()1201     public String getDetectedTextLanguageTags() {
1202       return detectedTextLanguageTags;
1203     }
1204 
getEntityTypes()1205     public String[] getEntityTypes() {
1206       return entityTypes;
1207     }
1208 
getAnnotateMode()1209     public int getAnnotateMode() {
1210       return annotateMode;
1211     }
1212 
getAnnotationUsecase()1213     public int getAnnotationUsecase() {
1214       return annotationUsecase;
1215     }
1216 
isSerializedEntityDataEnabled()1217     public boolean isSerializedEntityDataEnabled() {
1218       return isSerializedEntityDataEnabled;
1219     }
1220 
getUserLocationLat()1221     public double getUserLocationLat() {
1222       return userLocationLat;
1223     }
1224 
getUserLocationLng()1225     public double getUserLocationLng() {
1226       return userLocationLng;
1227     }
1228 
getUserLocationAccuracyMeters()1229     public float getUserLocationAccuracyMeters() {
1230       return userLocationAccuracyMeters;
1231     }
1232 
hasLocationPermission()1233     public boolean hasLocationPermission() {
1234       return hasLocationPermission;
1235     }
1236 
hasPersonalizationPermission()1237     public boolean hasPersonalizationPermission() {
1238       return hasPersonalizationPermission;
1239     }
1240 
getUsePodNer()1241     public boolean getUsePodNer() {
1242       return usePodNer;
1243     }
1244 
getTriggerDictionaryOnBeginnerWords()1245     public boolean getTriggerDictionaryOnBeginnerWords() {
1246       return triggerDictionaryOnBeginnerWords;
1247     }
1248 
getUseVocabAnnotator()1249     public boolean getUseVocabAnnotator() {
1250       return useVocabAnnotator;
1251     }
1252   }
1253 
1254   /**
1255    * Retrieves the pointer to the native object. Note: Need to keep the AnnotatorModel alive as long
1256    * as the pointer is used.
1257    */
getNativeAnnotatorPointer()1258   long getNativeAnnotatorPointer() {
1259     return nativeGetNativeModelPtr(annotatorPtr);
1260   }
1261 
nativeNewAnnotator(int fd)1262   private static native long nativeNewAnnotator(int fd);
1263 
nativeNewAnnotatorFromPath(String path)1264   private static native long nativeNewAnnotatorFromPath(String path);
1265 
nativeNewAnnotatorWithOffset(int fd, long offset, long size)1266   private static native long nativeNewAnnotatorWithOffset(int fd, long offset, long size);
1267 
nativeGetLocales(int fd)1268   private static native String nativeGetLocales(int fd);
1269 
nativeGetLocalesWithOffset(int fd, long offset, long size)1270   private static native String nativeGetLocalesWithOffset(int fd, long offset, long size);
1271 
nativeGetVersion(int fd)1272   private static native int nativeGetVersion(int fd);
1273 
nativeGetVersionWithOffset(int fd, long offset, long size)1274   private static native int nativeGetVersionWithOffset(int fd, long offset, long size);
1275 
nativeGetName(int fd)1276   private static native String nativeGetName(int fd);
1277 
nativeGetNameWithOffset(int fd, long offset, long size)1278   private static native String nativeGetNameWithOffset(int fd, long offset, long size);
1279 
nativeGetNativeModelPtr(long context)1280   private native long nativeGetNativeModelPtr(long context);
1281 
nativeInitializeKnowledgeEngine(long context, byte[] serializedConfig)1282   private native boolean nativeInitializeKnowledgeEngine(long context, byte[] serializedConfig);
1283 
nativeInitializeContactEngine(long context, byte[] serializedConfig)1284   private native boolean nativeInitializeContactEngine(long context, byte[] serializedConfig);
1285 
nativeInitializeInstalledAppEngine(long context, byte[] serializedConfig)1286   private native boolean nativeInitializeInstalledAppEngine(long context, byte[] serializedConfig);
1287 
nativeInitializePersonNameEngine( long context, int fd, long offset, long size)1288   private native boolean nativeInitializePersonNameEngine(
1289       long context, int fd, long offset, long size);
1290 
nativeSetLangId(long annotatorPtr, long langIdPtr)1291   private native void nativeSetLangId(long annotatorPtr, long langIdPtr);
1292 
nativeSuggestSelection( long context, String text, int selectionBegin, int selectionEnd, SelectionOptions options)1293   private native int[] nativeSuggestSelection(
1294       long context, String text, int selectionBegin, int selectionEnd, SelectionOptions options);
1295 
nativeClassifyText( long context, String text, int selectionBegin, int selectionEnd, ClassificationOptions options, Object appContext, String resourceLocales)1296   private native ClassificationResult[] nativeClassifyText(
1297       long context,
1298       String text,
1299       int selectionBegin,
1300       int selectionEnd,
1301       ClassificationOptions options,
1302       Object appContext,
1303       String resourceLocales);
1304 
nativeAnnotate( long context, String text, AnnotationOptions options)1305   private native AnnotatedSpan[] nativeAnnotate(
1306       long context, String text, AnnotationOptions options);
1307 
nativeAnnotateStructuredInput( long context, InputFragment[] inputFragments, AnnotationOptions options)1308   private native Annotations nativeAnnotateStructuredInput(
1309       long context, InputFragment[] inputFragments, AnnotationOptions options);
1310 
nativeLookUpKnowledgeEntity(long context, String id)1311   private native byte[] nativeLookUpKnowledgeEntity(long context, String id);
1312 
nativeCloseAnnotator(long context)1313   private native void nativeCloseAnnotator(long context);
1314 }
1315