単一の文字列に対するOpenNLPSentenceDetectorAPIのコードは次のとおりです。
package opennlp;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;
public class SentenceDetector {
public static void main(String[] args) throws FileNotFoundException {
InputStream modelIn = new FileInputStream("en-sent.zip");
SentenceModel model = null;
try {
model = new SentenceModel(modelIn);
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (modelIn != null) {
try {
modelIn.close();
}
catch (IOException e) {
}
}
}
SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);
String sentences[] = sentenceDetector.sentDetect(" First sentence. Second sentence.");
for(String str : sentences)
System.out.println(str);
}
}
今私の質問は、テキストファイル全体を渡して、単一の文字列の代わりに文の検出を実行するにはどうすればよいですか?