This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
53 lines (48 loc) · 1.62 KB
/
test.java
File metadata and controls
53 lines (48 loc) · 1.62 KB
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
import org.chasen.mecab.MeCab;
import org.chasen.mecab.Tagger;
import org.chasen.mecab.Model;
import org.chasen.mecab.Lattice;
import org.chasen.mecab.Node;
public class test {
static {
try {
System.loadLibrary("MeCab");
} catch (UnsatisfiedLinkError e) {
System.err.println("Cannot load the example native code.\nMake sure your LD_LIBRARY_PATH contains \'.\'\n" + e);
System.exit(1);
}
}
public static void main(String[] argv) {
System.out.println(MeCab.VERSION);
Tagger tagger = new Tagger();
String str = "무궁화꽃이피었습니다.";
System.out.println(tagger.parse(str));
Node node = tagger.parseToNode(str);
for (;node != null; node = node.getNext()) {
System.out.println(node.getSurface() + "\t" + node.getFeature());
}
System.out.println ("EOS\n");
Model model = new Model();
Tagger tagger2 = model.createTagger();
System.out.println (tagger2.parse(str));
Lattice lattice = model.createLattice();
System.out.println(str);
lattice.set_sentence(str);
if (tagger2.parse(lattice)) {
System.out.println(lattice.toString());
for (node = lattice.bos_node(); node != null; node = node.getNext()) {
System.out.println(node.getSurface() + "\t" + node.getFeature());
}
System.out.println("EOS\n");
}
lattice.add_request_type(MeCab.MECAB_NBEST);
lattice.set_sentence(str);
tagger2.parse(lattice);
for (int i = 0; i < 10; ++i) {
if (lattice.next()) {
System.out.println("nbest:" + i + "\n" +
lattice.toString());
}
}
}
}