基本的な文の分割から始めて、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は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側のいずれかで、モデルから読み取ることができなくなるような何かが欠けていますか?