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 #ifndef LIBTEXTCLASSIFIER_ANNOTATOR_ANNOTATOR_JNI_H_ 18 #define LIBTEXTCLASSIFIER_ANNOTATOR_ANNOTATOR_JNI_H_ 19 20 #include <jni.h> 21 #include <string> 22 #include "annotator/annotator_jni_common.h" 23 #include "annotator/types.h" 24 #include "utils/java/jni-base.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 // SmartSelection. 31 TC3_JNI_METHOD(jlong, TC3_ANNOTATOR_CLASS_NAME, nativeNewAnnotator) 32 (JNIEnv* env, jobject thiz, jint fd); 33 34 TC3_JNI_METHOD(jlong, TC3_ANNOTATOR_CLASS_NAME, nativeNewAnnotatorFromPath) 35 (JNIEnv* env, jobject thiz, jstring path); 36 37 TC3_JNI_METHOD(jlong, TC3_ANNOTATOR_CLASS_NAME, 38 nativeNewAnnotatorFromAssetFileDescriptor) 39 (JNIEnv* env, jobject thiz, jobject afd, jlong offset, jlong size); 40 41 TC3_JNI_METHOD(jboolean, TC3_ANNOTATOR_CLASS_NAME, 42 nativeInitializeKnowledgeEngine) 43 (JNIEnv* env, jobject thiz, jlong ptr, jbyteArray serialized_config); 44 45 TC3_JNI_METHOD(jboolean, TC3_ANNOTATOR_CLASS_NAME, 46 nativeInitializeContactEngine) 47 (JNIEnv* env, jobject thiz, jlong ptr, jbyteArray serialized_config); 48 49 TC3_JNI_METHOD(jboolean, TC3_ANNOTATOR_CLASS_NAME, 50 nativeInitializeInstalledAppEngine) 51 (JNIEnv* env, jobject thiz, jlong ptr, jbyteArray serialized_config); 52 53 TC3_JNI_METHOD(jlong, TC3_ANNOTATOR_CLASS_NAME, nativeGetNativeModelPtr) 54 (JNIEnv* env, jobject thiz, jlong ptr); 55 56 TC3_JNI_METHOD(jintArray, TC3_ANNOTATOR_CLASS_NAME, nativeSuggestSelection) 57 (JNIEnv* env, jobject thiz, jlong ptr, jstring context, jint selection_begin, 58 jint selection_end, jobject options); 59 60 TC3_JNI_METHOD(jobjectArray, TC3_ANNOTATOR_CLASS_NAME, nativeClassifyText) 61 (JNIEnv* env, jobject thiz, jlong ptr, jstring context, jint selection_begin, 62 jint selection_end, jobject options, jobject app_context, 63 jstring device_locales); 64 65 TC3_JNI_METHOD(jobjectArray, TC3_ANNOTATOR_CLASS_NAME, nativeAnnotate) 66 (JNIEnv* env, jobject thiz, jlong ptr, jstring context, jobject options); 67 68 TC3_JNI_METHOD(jbyteArray, TC3_ANNOTATOR_CLASS_NAME, 69 nativeLookUpKnowledgeEntity) 70 (JNIEnv* env, jobject thiz, jlong ptr, jstring id); 71 72 TC3_JNI_METHOD(void, TC3_ANNOTATOR_CLASS_NAME, nativeCloseAnnotator) 73 (JNIEnv* env, jobject thiz, jlong ptr); 74 75 // DEPRECATED. Use nativeGetLocales instead. 76 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetLanguage) 77 (JNIEnv* env, jobject clazz, jint fd); 78 79 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetLocales) 80 (JNIEnv* env, jobject clazz, jint fd); 81 82 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, 83 nativeGetLocalesFromAssetFileDescriptor) 84 (JNIEnv* env, jobject thiz, jobject afd, jlong offset, jlong size); 85 86 TC3_JNI_METHOD(jint, TC3_ANNOTATOR_CLASS_NAME, nativeGetVersion) 87 (JNIEnv* env, jobject clazz, jint fd); 88 89 TC3_JNI_METHOD(jint, TC3_ANNOTATOR_CLASS_NAME, 90 nativeGetVersionFromAssetFileDescriptor) 91 (JNIEnv* env, jobject thiz, jobject afd, jlong offset, jlong size); 92 93 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetName) 94 (JNIEnv* env, jobject clazz, jint fd); 95 96 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, 97 nativeGetNameFromAssetFileDescriptor) 98 (JNIEnv* env, jobject thiz, jobject afd, jlong offset, jlong size); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 namespace libtextclassifier3 { 105 106 // Given a utf8 string and a span expressed in Java BMP (basic multilingual 107 // plane) codepoints, converts it to a span expressed in utf8 codepoints. 108 libtextclassifier3::CodepointSpan ConvertIndicesBMPToUTF8( 109 const std::string& utf8_str, libtextclassifier3::CodepointSpan bmp_indices); 110 111 // Given a utf8 string and a span expressed in utf8 codepoints, converts it to a 112 // span expressed in Java BMP (basic multilingual plane) codepoints. 113 libtextclassifier3::CodepointSpan ConvertIndicesUTF8ToBMP( 114 const std::string& utf8_str, 115 libtextclassifier3::CodepointSpan utf8_indices); 116 117 } // namespace libtextclassifier3 118 119 #endif // LIBTEXTCLASSIFIER_ANNOTATOR_ANNOTATOR_JNI_H_ 120