-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFasttextWrapper.java
63 lines (44 loc) · 1.6 KB
/
FasttextWrapper.java
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
package wrapper;
import java.io.File;
import javax.management.modelmbean.ModelMBean;
public class FasttextWrapper {
private native void train(String[] params);
private native long loadModel(String modelPath);
private native void unloadModel(long ftAddr);
private native String predict(long ftAddr, String text, int k, boolean prob);
static
{
String relaPath = "./dlls/MyFasttext.dll";
File file = new File(relaPath);
String absPath = file.getAbsolutePath();
System.load(absPath);
}
public static void main(String[] args) {
FasttextWrapper wrapper = new FasttextWrapper();
System.out.println("fasttext process started!");
// String[] arr = new String[]
// {"fasttext","skipgram","-input","data.txt","-output","model"};
// String[] arr = new String[]
// {"fasttext","supervised","-input","./data/labeled_data.txt","-output","./data/model"};
// String[] arr = new String[]
// {"fasttext","predict","./data/model.bin","./data/test.txt","1"};
// wrapper.train(arr);
String modelPath = "./data/model.bin";
//long ftAddr = wrapper.loadModel(modelPath);
String text = "football\r\nsoccer";
for(int i=0;i<20;i++)
{
long ftAddr = wrapper.loadModel(modelPath);
System.out.println(ftAddr);
//String str = wrapper.predict(ftAddr, text, 1, true);
//System.out.println(str);
//wrapper.unloadModel(ftAddr);
// System.out.println("unload finished");
//System.out.println(str);
//wrapper.unloadModel(ftAddr);
//String str1 = wrapper.predict(ftAddr, text, 1, true);
//System.out.println(str1);
}
System.out.println("fasttext process ended!");
}
}