我是OpenNLP的新手,并且遵循了NameFinder的文档。我已经下载了OpenNLP版本1.7.2并从OpenNLP项目网页下载了en-ner-person.bin模型。这是我的示例类:
public class OpenNLPExamples {
public static void main(String args[]) {
String inputFileName = "en-ner-person.bin";
String[] inputString = new String[]{"mike", "and", "smiths", "are", "good", "friends."};
NameFinderME model=null;
InputStream modelFile=null;
TokenNameFinderModel modelStream=null;
try {
modelFile = new FileInputStream("/Users/saurabh/Desktop/en-ner-person.bin");
modelStream = new TokenNameFinderModel(modelFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
modelFile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
model = new NameFinderME(modelStream);
Span spans[] = model.find(inputString);
System.out.println("span length: " + spans.length);
for(Span span: spans) {
System.out.println(span.toString());
}
}
}
给定代码的输出为空。我也打印了长度,它是零。我也使用命令行工具,但没有好运。任何人都可以告诉我,我在这里犯了什么错误,或者问题是训练有素的模特吗?