• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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_TEXTCLASSIFIER_JNI_H_
18 #define LIBTEXTCLASSIFIER_TEXTCLASSIFIER_JNI_H_
19 
20 #include <jni.h>
21 #include <string>
22 
23 #include "smartselect/types.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 // SmartSelection.
30 JNIEXPORT jlong JNICALL
31 Java_android_view_textclassifier_SmartSelection_nativeNew(JNIEnv* env,
32                                                           jobject thiz,
33                                                           jint fd);
34 
35 JNIEXPORT jintArray JNICALL
36 Java_android_view_textclassifier_SmartSelection_nativeSuggest(
37     JNIEnv* env, jobject thiz, jlong ptr, jstring context, jint selection_begin,
38     jint selection_end);
39 
40 JNIEXPORT jobjectArray JNICALL
41 Java_android_view_textclassifier_SmartSelection_nativeClassifyText(
42     JNIEnv* env, jobject thiz, jlong ptr, jstring context, jint selection_begin,
43     jint selection_end, jint input_flags);
44 
45 JNIEXPORT void JNICALL
46 Java_android_view_textclassifier_SmartSelection_nativeClose(JNIEnv* env,
47                                                             jobject thiz,
48                                                             jlong ptr);
49 
50 JNIEXPORT jstring JNICALL
51 Java_android_view_textclassifier_SmartSelection_nativeGetLanguage(JNIEnv* env,
52                                                                   jobject clazz,
53                                                                   jint fd);
54 
55 JNIEXPORT jint JNICALL
56 Java_android_view_textclassifier_SmartSelection_nativeGetVersion(JNIEnv* env,
57                                                                  jobject clazz,
58                                                                  jint fd);
59 
60 // LangId.
61 JNIEXPORT jlong JNICALL Java_android_view_textclassifier_LangId_nativeNew(
62     JNIEnv* env, jobject thiz, jint fd);
63 
64 JNIEXPORT jobjectArray JNICALL
65 Java_android_view_textclassifier_LangId_nativeFindLanguages(JNIEnv* env,
66                                                             jobject thiz,
67                                                             jlong ptr,
68                                                             jstring text);
69 
70 JNIEXPORT void JNICALL Java_android_view_textclassifier_LangId_nativeClose(
71     JNIEnv* env, jobject thiz, jlong ptr);
72 
73 JNIEXPORT int JNICALL Java_android_view_textclassifier_LangId_nativeGetVersion(
74     JNIEnv* env, jobject clazz, jint fd);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 namespace libtextclassifier {
81 
82 // Given a utf8 string and a span expressed in Java BMP (basic multilingual
83 // plane) codepoints, converts it to a span expressed in utf8 codepoints.
84 libtextclassifier::CodepointSpan ConvertIndicesBMPToUTF8(
85     const std::string& utf8_str, libtextclassifier::CodepointSpan bmp_indices);
86 
87 // Given a utf8 string and a span expressed in utf8 codepoints, converts it to a
88 // span expressed in Java BMP (basic multilingual plane) codepoints.
89 libtextclassifier::CodepointSpan ConvertIndicesUTF8ToBMP(
90     const std::string& utf8_str, libtextclassifier::CodepointSpan utf8_indices);
91 
92 }  // namespace libtextclassifier
93 
94 #endif  // LIBTEXTCLASSIFIER_TEXTCLASSIFIER_JNI_H_
95