• 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 #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 clazz, jint fd);
33 
34 TC3_JNI_METHOD(jlong, TC3_ANNOTATOR_CLASS_NAME, nativeNewAnnotatorFromPath)
35 (JNIEnv* env, jobject clazz, jstring path);
36 
37 TC3_JNI_METHOD(jlong, TC3_ANNOTATOR_CLASS_NAME, nativeNewAnnotatorWithOffset)
38 (JNIEnv* env, jobject clazz, jint fd, jlong offset, jlong size);
39 
40 TC3_JNI_METHOD(jboolean, TC3_ANNOTATOR_CLASS_NAME,
41                nativeInitializeKnowledgeEngine)
42 (JNIEnv* env, jobject thiz, jlong ptr, jbyteArray serialized_config);
43 
44 TC3_JNI_METHOD(jboolean, TC3_ANNOTATOR_CLASS_NAME,
45                nativeInitializeContactEngine)
46 (JNIEnv* env, jobject thiz, jlong ptr, jbyteArray serialized_config);
47 
48 TC3_JNI_METHOD(jboolean, TC3_ANNOTATOR_CLASS_NAME,
49                nativeInitializeInstalledAppEngine)
50 (JNIEnv* env, jobject thiz, jlong ptr, jbyteArray serialized_config);
51 
52 TC3_JNI_METHOD(jboolean, TC3_ANNOTATOR_CLASS_NAME,
53                nativeInitializePersonNameEngine)
54 (JNIEnv* env, jobject thiz, jlong ptr, jint fd, jlong offset, jlong size);
55 
56 TC3_JNI_METHOD(void, TC3_ANNOTATOR_CLASS_NAME, nativeSetLangId)
57 (JNIEnv* env, jobject thiz, jlong annotator_ptr, jlong lang_id_ptr);
58 
59 TC3_JNI_METHOD(jlong, TC3_ANNOTATOR_CLASS_NAME, nativeGetNativeModelPtr)
60 (JNIEnv* env, jobject thiz, jlong ptr);
61 
62 TC3_JNI_METHOD(jintArray, TC3_ANNOTATOR_CLASS_NAME, nativeSuggestSelection)
63 (JNIEnv* env, jobject thiz, jlong ptr, jstring context, jint selection_begin,
64  jint selection_end, jobject options);
65 
66 TC3_JNI_METHOD(jobjectArray, TC3_ANNOTATOR_CLASS_NAME, nativeClassifyText)
67 (JNIEnv* env, jobject thiz, jlong ptr, jstring context, jint selection_begin,
68  jint selection_end, jobject options, jobject app_context,
69  jstring device_locales);
70 
71 TC3_JNI_METHOD(jobject, TC3_ANNOTATOR_CLASS_NAME, nativeAnnotateStructuredInput)
72 (JNIEnv* env, jobject thiz, jlong ptr, jobjectArray jinput_fragments,
73  jobject options);
74 
75 TC3_JNI_METHOD(jobjectArray, TC3_ANNOTATOR_CLASS_NAME, nativeAnnotate)
76 (JNIEnv* env, jobject thiz, jlong ptr, jstring context, jobject options);
77 
78 TC3_JNI_METHOD(jbyteArray, TC3_ANNOTATOR_CLASS_NAME,
79                nativeLookUpKnowledgeEntity)
80 (JNIEnv* env, jobject thiz, jlong ptr, jstring id);
81 
82 TC3_JNI_METHOD(void, TC3_ANNOTATOR_CLASS_NAME, nativeCloseAnnotator)
83 (JNIEnv* env, jobject thiz, jlong ptr);
84 
85 // DEPRECATED. Use nativeGetLocales instead.
86 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetLanguage)
87 (JNIEnv* env, jobject clazz, jint fd);
88 
89 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetLocales)
90 (JNIEnv* env, jobject clazz, jint fd);
91 
92 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetLocalesWithOffset)
93 (JNIEnv* env, jobject clazz, jint fd, jlong offset, jlong size);
94 
95 TC3_JNI_METHOD(jint, TC3_ANNOTATOR_CLASS_NAME, nativeGetVersion)
96 (JNIEnv* env, jobject clazz, jint fd);
97 
98 TC3_JNI_METHOD(jint, TC3_ANNOTATOR_CLASS_NAME, nativeGetVersionWithOffset)
99 (JNIEnv* env, jobject clazz, jint fd, jlong offset, jlong size);
100 
101 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetName)
102 (JNIEnv* env, jobject clazz, jint fd);
103 
104 TC3_JNI_METHOD(jstring, TC3_ANNOTATOR_CLASS_NAME, nativeGetNameWithOffset)
105 (JNIEnv* env, jobject clazz, jint fd, jlong offset, jlong size);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 namespace libtextclassifier3 {
112 
113 // Given a utf8 string and a span expressed in Java BMP (basic multilingual
114 // plane) codepoints, converts it to a span expressed in utf8 codepoints.
115 libtextclassifier3::CodepointSpan ConvertIndicesBMPToUTF8(
116     const std::string& utf8_str, const std::pair<int, int>& bmp_indices);
117 
118 // Given a utf8 string and a span expressed in utf8 codepoints, converts it to a
119 // span expressed in Java BMP (basic multilingual plane) codepoints.
120 std::pair<int, int> ConvertIndicesUTF8ToBMP(
121     const std::string& utf8_str,
122     const libtextclassifier3::CodepointSpan& utf8_indices);
123 
124 }  // namespace libtextclassifier3
125 
126 #endif  // LIBTEXTCLASSIFIER_ANNOTATOR_ANNOTATOR_JNI_H_
127