* Class: LAC * Method: run * Signature: (Ljava/lang/String;Ljava/lang/ArrayList;Ljava/lang/ArrayList)Jint */
| 92 | * Signature: (Ljava/lang/String;Ljava/lang/ArrayList;Ljava/lang/ArrayList)Jint |
| 93 | */ |
| 94 | JNIEXPORT jint JNICALL Java_com_baidu_nlp_LAC_run |
| 95 | (JNIEnv *env, jobject thisObj, jstring sentence, jobject words, jobject tags) |
| 96 | { |
| 97 | jclass list_jcs = env->FindClass("java/util/ArrayList"); |
| 98 | if (list_jcs == NULL) { |
| 99 | std::cerr<<"JNICALL Java_com_baidu_nlp_LAC_run: ArrayList Not Found"<<std::endl; |
| 100 | return -1; |
| 101 | } |
| 102 | |
| 103 | //获取ArrayList构造函数id,用于Return使用 |
| 104 | // jmethodID list_init = env->GetMethodID(list_jcs, "<init>", "()V"); |
| 105 | //创建一个ArrayList对象 |
| 106 | // jobject list_obj = env->NewObject(list_jcs, list_init, ""); |
| 107 | |
| 108 | //获取ArrayList对象的add()的methodID |
| 109 | jmethodID list_add = env->GetMethodID(list_jcs, "add", |
| 110 | "(Ljava/lang/Object;)Z"); |
| 111 | |
| 112 | //获取ArrayList对象的clear()的methodID |
| 113 | jmethodID list_clear = env->GetMethodID(list_jcs, "clear", "()V"); |
| 114 | env->CallVoidMethod(words, list_clear); |
| 115 | env->CallVoidMethod(tags, list_clear); |
| 116 | |
| 117 | LAC *self = _get_self(env, thisObj); |
| 118 | std::string input = env->GetStringUTFChars(sentence, 0); |
| 119 | auto result = self->run(input); |
| 120 | |
| 121 | for (size_t i = 0; i < result.size(); i++) |
| 122 | { |
| 123 | env->CallBooleanMethod(words, list_add, env->NewStringUTF(result[i].word.c_str())); |
| 124 | env->CallBooleanMethod(tags, list_add, env->NewStringUTF(result[i].tag.c_str())); |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | |
| 129 | } |
| 130 | |
| 131 | #ifdef __cplusplus |
| 132 | } |