【发布时间】:2012-05-22 10:59:18
【问题描述】:
我正在尝试将 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!” (source of class throwing error),这意味着我无法打开模型的 InputStream。其他花絮:
- 我已验证模型文件存在于
sentenceModelPath所指的位置。 - 我为 opennlp-maxent:3.0.2-incubating、opennlp-tools:1.5.2-incubating 和 opennlp-uima:1.5.2-incubating 添加了 Maven 依赖项。
- Hadoop 只是在我的本地计算机上运行。
其中大部分是来自OpenNLP documentation 的样板。在 Hadoop 端或 OpenNLP 端有什么我遗漏的东西会导致我无法从模型中读取吗?
【问题讨论】:
-
sentenceModelPath的值是多少(记录器信息语句打印什么?)。此路径是在本地文件系统、作业 jar 中还是 HDFS 中的某个地方? -
@ChrisWhite 我已将它设置为 HDFS 中的路径 (
/sandbox/corpus-analysis/nlp/en-sent.bin),并使用本地文件系统上的路径对其进行了测试 (a la/home/cyranix/path/to/en-sent.bin)。两者都没有骰子。