-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.cpp
83 lines (73 loc) · 2.36 KB
/
App.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* App.cpp
* (C) 2018 by Damir Cavar <[email protected]>
*
* Date: 08/03/2018
* Version: 0.1
*
* This is the C++ interface between JNI and the FomaWrapper class and library.
*
* The morphological analyzer Foma takes a string and returns n strings. Since it is
* using a bidirectional model here, the input can be a token and the output a
* list of analyzes, or the other way around, it could be an analysis string and
* the final surface form of a morpheme.
*/
#include "include/foma_App.h"
#include "FomaWrapper.h"
/*
* Class: foma_App
* Method: getFST
* Signature: (Ljava/lang/String;)J
*/
JNIEXPORT jlong JNICALL Java_foma_App_getFST(JNIEnv *env, jobject obj, jstring inJNIStr) {
if (!inJNIStr) return NULL;
jboolean isCopy;
string fname = (env)->GetStringUTFChars(inJNIStr, &isCopy);
FomaWrapper *fw = new FomaWrapper(fname);
return (jlong) fw;
}
/*
* Class: foma_App
* Method: destroyFST
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_foma_App_destroyFST(JNIEnv *env, jobject obj, jlong ptr_) {
FomaWrapper* cls = (FomaWrapper*)ptr_;
delete cls;
}
/*
* Class: foma_App
* Method: applyUp
* Signature: (JLjava/lang/String;)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_foma_App_applyUp(JNIEnv *env, jclass obj, jlong ptr_, jstring inJNIStr) {
FomaWrapper* cls = (FomaWrapper*) ptr_;
jobjectArray ret;
string inCStr = (env)->GetStringUTFChars(inJNIStr, NULL);
vector<string> res = cls->applyUp(inCStr);
long l = res.size();
ret = (jobjectArray) env->NewObjectArray(l, env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int i = 0; i < l; i++) {
string r = res.at(i);
env->SetObjectArrayElement(ret, i, env->NewStringUTF(r.c_str()));
}
return (ret);
}
/*
* Class: foma_App
* Method: applyDown
* Signature: (JLjava/lang/String;)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_foma_App_applyDown(JNIEnv *env, jclass obj, jlong ptr_, jstring inJNIStr) {
FomaWrapper* cls = (FomaWrapper*) ptr_;
jobjectArray ret;
string inCStr = (env)->GetStringUTFChars(inJNIStr, NULL);
vector<string> res = cls->applyDown(inCStr);
int l = res.size();
ret = (jobjectArray) env->NewObjectArray(l, env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int i = 0; i < l; i++) {
string r = res.at(i);
env->SetObjectArrayElement(ret, i, env->NewStringUTF(r.c_str()));
}
return (ret);
}