我正在尝试使用 MeCab (http://mecab.sourceforge.net/#download) 对日语句子进行分词,并按词性标记每个单词。我按照这些说明http://mecab.sourceforge.net/#install-unix安装了 MeCab 。由于我不想编写 shell 脚本来处理 150,000 个句子(因为我的 Mac OS X 终端无法显示日文字符),我正在使用现有的 Java 绑定:http: //sourceforge.net/projects/mecab/files /mecab-java/0.98pre3/。此时我正在尝试编译并运行给定的 test.java 文件:
import org.chasen.mecab.MeCab;
import org.chasen.mecab.Tagger;
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");
}
}
这是自述文件:
1. Build UTF-8 dictionary
2. How to use?
See test.java as sample program.
% java -classpath MeCab.jar test -d ../dic
我编译:javac test.java。然后我运行:java -classpath MeCab.jar test -d ../dic。结果是以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: //
Caused by: java.lang.ClassNotFoundException: ..
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
我不是很了解这个mecab-java-0.98pre3 目录的层次结构,所以看不到如何实际编译和运行这个test.java。有什么想法吗,伙计们?谢谢!