0
我想嘗試OpenNLP手冊中的示例(第一次使用它)。OpenNLP模型版本1.5.0不受0.0.0-SNAPSHOT的支持
出於某種原因,這一點:
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 Main {
/**
* @param args
*/
public static void main(String[] args) {
//-------------------------------------------------------------Check for input text file.
if(args == null){
System.out.print("hello");
}
//------------------------------------------------------------------Main algorithm
else {
InputStream modelIn = null;
SentenceModel model = null;
try {
modelIn = new FileInputStream("./src/train/en-sent.bin");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
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. ");
System.out.print(sentences[0]);
}
}
}
獲取一個錯誤:
opennlp.tools.util.InvalidFormatException: Model version 1.5.0 is not supported by this (0.0.0-SNAPSHOT) version of OpenNLP!
at opennlp.tools.util.model.BaseModel.validateArtifactMap(BaseModel.java:235)
at opennlp.tools.sentdetect.SentenceModel.validateArtifactMap(SentenceModel.java:78)
at opennlp.tools.util.model.BaseModel.<init>(BaseModel.java:142)
at opennlp.tools.sentdetect.SentenceModel.<init>(SentenceModel.java:73)
at Main.main(Main.java:34)
我沒有絲毫的想法,爲什麼這是發生...... 它說here是0.0.0- SNAPSHOT版本的OpenNLP應永不加載任何模型。
到目前爲止,我還沒能找到關於此錯誤的任何其他信息。這可能是我對進口產品做的事情?或我正在使用的模型(我從OpenNLP網站下載---找不到任何其他版本)?無論如何,我不知道有什麼問題...
任何想法或幫助,將不勝感激。
附加信息:我在Ubuntu 12.04上使用OpenNLP 1.5.2孵化和1.5模型(項目網站表示它應該完全兼容)。 我不確定這是否有任何意義,但我使用Eclipse Indigo。