diff options
author | Tony Mak <tonymak@google.com> | 2020-10-30 17:12:44 +0000 |
---|---|---|
committer | Tony Mak <tonymak@google.com> | 2020-11-03 18:13:57 +0000 |
commit | e8a3541b9ef9cd80cff5cf82e7bf97018b5b0219 (patch) | |
tree | db3ce5c0f255bce5c5fd9f1daa86e5ba5678652a /jni | |
parent | 8d20fb2242144d051d2f184d1de692c0119ad528 (diff) | |
download | libtextclassifier-e8a3541b9ef9cd80cff5cf82e7bf97018b5b0219.tar.gz |
Export libtextclassifier
Export libtextclassifier from the HEAD for a fix for the new
PendingIntent requirement. (b/169718669).
Fixes: 169718669
Test: atest -p external/libtextclassifier --all-abi
Change-Id: Ieeeeded32d05e10c2e5af4af87d010de92c7f5a3
Diffstat (limited to 'jni')
-rw-r--r-- | jni/com/google/android/textclassifier/AnnotatorModel.java | 54 | ||||
-rw-r--r-- | jni/com/google/android/textclassifier/LangIdModel.java | 10 |
2 files changed, 58 insertions, 6 deletions
diff --git a/jni/com/google/android/textclassifier/AnnotatorModel.java b/jni/com/google/android/textclassifier/AnnotatorModel.java index d2001ed..4c4610b 100644 --- a/jni/com/google/android/textclassifier/AnnotatorModel.java +++ b/jni/com/google/android/textclassifier/AnnotatorModel.java @@ -588,6 +588,7 @@ public final class AnnotatorModel implements AutoCloseable { private final double userLocationLng; private final float userLocationAccuracyMeters; private final boolean usePodNer; + private final boolean useVocabAnnotator; private SelectionOptions( @Nullable String locales, @@ -596,7 +597,8 @@ public final class AnnotatorModel implements AutoCloseable { double userLocationLat, double userLocationLng, float userLocationAccuracyMeters, - boolean usePodNer) { + boolean usePodNer, + boolean useVocabAnnotator) { this.locales = locales; this.detectedTextLanguageTags = detectedTextLanguageTags; this.annotationUsecase = annotationUsecase; @@ -604,6 +606,7 @@ public final class AnnotatorModel implements AutoCloseable { this.userLocationLng = userLocationLng; this.userLocationAccuracyMeters = userLocationAccuracyMeters; this.usePodNer = usePodNer; + this.useVocabAnnotator = useVocabAnnotator; } /** Can be used to build a SelectionsOptions instance. */ @@ -615,6 +618,7 @@ public final class AnnotatorModel implements AutoCloseable { private double userLocationLng = INVALID_LONGITUDE; private float userLocationAccuracyMeters = INVALID_LOCATION_ACCURACY_METERS; private boolean usePodNer = true; + private boolean useVocabAnnotator; public Builder setLocales(@Nullable String locales) { this.locales = locales; @@ -651,6 +655,11 @@ public final class AnnotatorModel implements AutoCloseable { return this; } + public Builder setUseVocabAnnotator(boolean useVocabAnnotator) { + this.useVocabAnnotator = useVocabAnnotator; + return this; + } + public SelectionOptions build() { return new SelectionOptions( locales, @@ -659,7 +668,8 @@ public final class AnnotatorModel implements AutoCloseable { userLocationLat, userLocationLng, userLocationAccuracyMeters, - usePodNer); + usePodNer, + useVocabAnnotator); } } @@ -697,6 +707,10 @@ public final class AnnotatorModel implements AutoCloseable { public boolean getUsePodNer() { return usePodNer; } + + public boolean getUseVocabAnnotator() { + return useVocabAnnotator; + } } /** Represents options for the classifyText call. */ @@ -712,6 +726,7 @@ public final class AnnotatorModel implements AutoCloseable { private final String userFamiliarLanguageTags; private final boolean usePodNer; private final boolean triggerDictionaryOnBeginnerWords; + private final boolean useVocabAnnotator; private ClassificationOptions( long referenceTimeMsUtc, @@ -724,7 +739,8 @@ public final class AnnotatorModel implements AutoCloseable { float userLocationAccuracyMeters, String userFamiliarLanguageTags, boolean usePodNer, - boolean triggerDictionaryOnBeginnerWords) { + boolean triggerDictionaryOnBeginnerWords, + boolean useVocabAnnotator) { this.referenceTimeMsUtc = referenceTimeMsUtc; this.referenceTimezone = referenceTimezone; this.locales = locales; @@ -736,6 +752,7 @@ public final class AnnotatorModel implements AutoCloseable { this.userFamiliarLanguageTags = userFamiliarLanguageTags; this.usePodNer = usePodNer; this.triggerDictionaryOnBeginnerWords = triggerDictionaryOnBeginnerWords; + this.useVocabAnnotator = useVocabAnnotator; } /** Can be used to build a ClassificationOptions instance. */ @@ -751,6 +768,7 @@ public final class AnnotatorModel implements AutoCloseable { private String userFamiliarLanguageTags = ""; private boolean usePodNer = true; private boolean triggerDictionaryOnBeginnerWords = false; + private boolean useVocabAnnotator = false; public Builder setReferenceTimeMsUtc(long referenceTimeMsUtc) { this.referenceTimeMsUtc = referenceTimeMsUtc; @@ -808,6 +826,11 @@ public final class AnnotatorModel implements AutoCloseable { return this; } + public Builder setUseVocabAnnotator(boolean useVocabAnnotator) { + this.useVocabAnnotator = useVocabAnnotator; + return this; + } + public ClassificationOptions build() { return new ClassificationOptions( referenceTimeMsUtc, @@ -820,7 +843,8 @@ public final class AnnotatorModel implements AutoCloseable { userLocationAccuracyMeters, userFamiliarLanguageTags, usePodNer, - triggerDictionaryOnBeginnerWords); + triggerDictionaryOnBeginnerWords, + useVocabAnnotator); } } @@ -874,6 +898,10 @@ public final class AnnotatorModel implements AutoCloseable { public boolean getTriggerDictionaryOnBeginnerWords() { return triggerDictionaryOnBeginnerWords; } + + public boolean getUseVocabAnnotator() { + return useVocabAnnotator; + } } /** Represents options for the annotate call. */ @@ -893,6 +921,7 @@ public final class AnnotatorModel implements AutoCloseable { private final float userLocationAccuracyMeters; private final boolean usePodNer; private final boolean triggerDictionaryOnBeginnerWords; + private final boolean useVocabAnnotator; private AnnotationOptions( long referenceTimeMsUtc, @@ -909,7 +938,8 @@ public final class AnnotatorModel implements AutoCloseable { double userLocationLng, float userLocationAccuracyMeters, boolean usePodNer, - boolean triggerDictionaryOnBeginnerWords) { + boolean triggerDictionaryOnBeginnerWords, + boolean useVocabAnnotator) { this.referenceTimeMsUtc = referenceTimeMsUtc; this.referenceTimezone = referenceTimezone; this.locales = locales; @@ -925,6 +955,7 @@ public final class AnnotatorModel implements AutoCloseable { this.hasPersonalizationPermission = hasPersonalizationPermission; this.usePodNer = usePodNer; this.triggerDictionaryOnBeginnerWords = triggerDictionaryOnBeginnerWords; + this.useVocabAnnotator = useVocabAnnotator; } /** Can be used to build an AnnotationOptions instance. */ @@ -944,6 +975,7 @@ public final class AnnotatorModel implements AutoCloseable { private float userLocationAccuracyMeters = INVALID_LOCATION_ACCURACY_METERS; private boolean usePodNer = true; private boolean triggerDictionaryOnBeginnerWords = false; + private boolean useVocabAnnotator; public Builder setReferenceTimeMsUtc(long referenceTimeMsUtc) { this.referenceTimeMsUtc = referenceTimeMsUtc; @@ -1020,6 +1052,11 @@ public final class AnnotatorModel implements AutoCloseable { return this; } + public Builder setUseVocabAnnotator(boolean useVocabAnnotator) { + this.useVocabAnnotator = useVocabAnnotator; + return this; + } + public AnnotationOptions build() { return new AnnotationOptions( referenceTimeMsUtc, @@ -1036,7 +1073,8 @@ public final class AnnotatorModel implements AutoCloseable { userLocationLng, userLocationAccuracyMeters, usePodNer, - triggerDictionaryOnBeginnerWords); + triggerDictionaryOnBeginnerWords, + useVocabAnnotator); } } @@ -1106,6 +1144,10 @@ public final class AnnotatorModel implements AutoCloseable { public boolean getTriggerDictionaryOnBeginnerWords() { return triggerDictionaryOnBeginnerWords; } + + public boolean getUseVocabAnnotator() { + return useVocabAnnotator; + } } /** diff --git a/jni/com/google/android/textclassifier/LangIdModel.java b/jni/com/google/android/textclassifier/LangIdModel.java index 0015826..15f352b 100644 --- a/jni/com/google/android/textclassifier/LangIdModel.java +++ b/jni/com/google/android/textclassifier/LangIdModel.java @@ -48,6 +48,14 @@ public final class LangIdModel implements AutoCloseable { } } + /** Creates a new instance of LangId predictor, using the provided model image. */ + public LangIdModel(int fd, long offset, long size) { + modelPtr = nativeNewWithOffset(fd, offset, size); + if (modelPtr == 0L) { + throw new IllegalArgumentException("Couldn't initialize LangId from given file descriptor."); + } + } + /** Detects the languages for given text. */ public LanguageResult[] detectLanguages(String text) { return nativeDetectLanguages(modelPtr, text); @@ -130,6 +138,8 @@ public final class LangIdModel implements AutoCloseable { private static native long nativeNewFromPath(String path); + private static native long nativeNewWithOffset(int fd, long offset, long size); + private native LanguageResult[] nativeDetectLanguages(long nativePtr, String text); private native void nativeClose(long nativePtr); |