我训练了OpenNLP NER-Model来检测新的实体,但是当我使用这个模型时,我遇到了以下异常:
Exception in thread "main" java.lang.IllegalArgumentException:
opennlp.tools.util.InvalidFormatException:
Model version 1.6.0 is not supported by this (1.5.3) version of OpenNLP!
我正在使用OpenNLP版本1.6.0,我的源代码是这样的:
String [] sentences = Fragmentation.getSentences(Document);
InputStream modelIn = new FileInputStream("Models/en-ner-cvskill.bin");
TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
NameFinderME nameFinder = new NameFinderME(model);
String[] tokens = null;
Span nameSpans[] = null;
int i=0;
for (String sentence : sentences) {
tokens = null;
nameSpans = null;
System.out.println("Sentences: "+(++i)+"\n" + sentence);
tokens = Fragmentation.getTokens(sentence);
for(String token: tokens){
System.out.println("Token:-------------------: "+token);
}
nameSpans = nameFinder.find(tokens);
String SkillName = Arrays.toString(Span.spansToStrings(nameSpans, tokens));
for(Span name:nameSpans){
System.out.println("Skills: "+ name.toString());
}
System.out.println("Names-------------------:"+SkillName);
}
nameFinder.clearAdaptiveData();
任何人都可以帮我解决这个问题..
答案 0 :(得分:0)
我已经找到了问题.. 实际上我正在训练opennlp 1.6.0的namefinder并使用相同的版本,这是opennlp当前版本(1.6.0)无法实现的。 现在我训练了opennlp 1.5.3的模型并且正在使用opennlp 1.6.0,它运行正常!