我需要通过Stanford NLP管道处理一批文本文件,并将语义图作为输出。我找到了in this SO question的管道示例。我只是更改了班级名称,推出了" dcoref"来自.props,并将其填充为Eclipse中Core NLP项目的新类。这是代码:
import java.io.*;
import java.util.*;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.util.*;
public class testpipeline {
public static void main(String[] args) throws IOException {
PrintWriter out;
if (args.length > 1) {
out = new PrintWriter(args[1]);
} else {
out = new PrintWriter(System.out);
}
PrintWriter xmlOut = null;
if (args.length > 2) {
xmlOut = new PrintWriter(args[2]);
}
StanfordCoreNLP pipeline = new StanfordCoreNLP();
Annotation annotation;
if (args.length > 0) {
annotation = new Annotation(IOUtils.slurpFileNoExceptions(args[0]));
} else {
annotation = new Annotation("He didn't get a reply.");
}
pipeline.annotate(annotation);
pipeline.prettyPrint(annotation, out);
if (xmlOut != null) {
pipeline.xmlPrint(annotation, xmlOut);
}
// An Annotation is a Map ...
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
if (sentences != null && sentences.size() > 0) {
CoreMap sentence = sentences.get(0);
Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
out.println();
out.println("The first sentence parsed is:");
tree.pennPrint(out);
}
}
}
但它不起作用。运行完整的管道,我通过控制台收到以下错误:
Reading the model of the lemmatizer
java.io.FileNotFoundException: models\lemmatizer.model (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at is2.lemmatizer.Lemmatizer.readModel(Lemmatizer.java:166)
at is2.lemmatizer.Lemmatizer.<init>(Lemmatizer.java:68)
at is2.lemmatizer.Lemmatizer.<init>(Lemmatizer.java:82)
at examples.FullPipeline.main(FullPipeline.java:56)
Applying the lemmatizer
Exception in thread "main" java.lang.NullPointerException
at is2.lemmatizer.Lemmatizer.lemmatize(Lemmatizer.java:447)
at is2.lemmatizer.Lemmatizer.apply(Lemmatizer.java:530)
at examples.FullPipeline.main(FullPipeline.java:59)
有人建议如何纠正这个问题吗?