我已经成功使用了MeCab Java打电话Mecab从我的Java代码。 我使用以下语句来初始化标记器:
tagger = new Tagger("--node-format=%f[7]\\t --unk-format=%m\\t --eos-format=\\n --rcfile=" + filePath + "/mecabrc" + " --dicdir=" + filePath + "/ipadic");
现在我面临一个问题,filePath
实际上可能包含空白字符,例如:c:\folder name\
。当我尝试使用这样的路径时,我从 Mecab 收到一条错误消息:
java.lang.RuntimeException: C:\src\c\common\mecab\src\main\c\tagger.cpp(151) [load_dictionary_resource(param)] C:\src\c\common\mecab\src\main\c\param.cpp(71) [ifs] no such file or directory: c:/folder
这意味着 Mecab 没有正确识别空格。
知道如何指示 Mecab 接受 Windows 文件路径中的空白字符吗?
最佳答案
我阅读了 MeCab 源代码,没有办法让 MeCab 在不编辑源代码和编译自定义版本的情况下接受路径中的空白。您至少有三个解决方法:
- 将目录重命名为不带空格的名称
- 尽可能使用相对路径
- 使用 windows 8.3 文件名
Here is a link to showing more information on how to get 8.3 filenames in java.
关于java - MeCab 路径参数在 Windows 上不接受空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299807/