我正在尝试将 OpenNLP 集成到 Hadoop 上的 map-reduce 作业中,从一些基本的句子拆分开始。在 map 函数中,运行以下代码:
public AnalysisFile analyze(String content) {
InputStream modelIn = null;
String[] sentences = null;
// references an absolute path to en-sent.bin
logger.info("sentenceModelPath: " + sentenceModelPath);
try {
modelIn = getClass().getResourceAsStream(sentenceModelPath);
SentenceModel model = new SentenceModel(modelIn);
SentenceDetectorME sentenceBreaker = new SentenceDetectorME(model);
sentences = sentenceBreaker.sentDetect(content);
} catch (FileNotFoundException e) {
logger.error("Unable to locate sentence model.");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (modelIn != null) {
try {
modelIn.close();
} catch (IOException e) {
}
}
}
logger.info("number of sentences: " + sentences.length);
<snip>
}
当我运行我的工作时,我在日志中收到一条错误消息,提示“in must not be null!” (类抛出错误的来源),这意味着我无法以某种方式打开模型的 InputStream。其他花絮:
- 我已经验证模型文件存在于
sentenceModelPath
所指的位置。 - 我为 opennlp-maxent:3.0.2-incubating、opennlp-tools:1.5.2-incubating 和 opennlp-uima:1.5.2-incubating 添加了 Maven 依赖项。
- Hadoop 只是在我的本地机器上运行。
其中大部分是来自OpenNLP 文档的样板。在 Hadoop 端或 OpenNLP 端有什么我遗漏的东西会导致我无法从模型中读取吗?