【发布时间】:2016-01-19 05:01:47
【问题描述】:
我下载了最新版本的 StanfordCoreNLP(2015-12-09 版本 3.6.0)。我在 Eclipse 中创建了一个项目并编写了一个简单的类来测试这些工具。我确保将所有 jar 文件添加到类路径中。
这是我正在测试的简单演示代码。
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.*;
import edu.stanford.nlp.trees.TreeCoreAnnotations.*;
import edu.stanford.nlp.dcoref.CorefChain;
import edu.stanford.nlp.dcoref.CorefCoreAnnotations;
public class second_test
{
public static void main(String[] args) throws IOException, ClassNotFoundException
{
PrintWriter xmlOut = new PrintWriter("xmlOutput.xml");
Properties props = new Properties();
props.setProperty("annotators","tokenize, ssplit, pos, lemma, ner, parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation annotation = new Annotation("Demo sentence for testing.");
pipeline.annotate(annotation);
pipeline.xmlPrint(annotation, xmlOut);
// An Annotation is a Map and you can get and use the
// various analyses individually. For instance, this
// gets the parse tree of the 1st sentence in the text.
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
if (sentences != null && sentences.size() > 0)
{
CoreMap sentence = sentences.get(0);
Tree tree = (Tree)sentence.get(TreeAnnotation.class);
PrintWriter out = new PrintWriter(System.out);
out.println("The first sentence parsed is:");
tree.pennPrint(out);
}
}
}
当我运行这段代码时,我可以在控制台中看到一些错误。
1) 声明对象“管道”时出现第一个错误:StanfordCoreNLP 无法解析为类型。
2) 声明对象 "sentences" 时发生第二个错误:语法错误,参数化类型仅在源级别为 1.5 或更高版本时可用 edu.stanford.nlp.util.ArrayCoreMap 类型无法解析。它是从所需的 .class 文件中间接引用的 方法 get(Class) 未为 Annotation 类型定义
任何解决此错误的想法将不胜感激。
【问题讨论】:
-
好的。检查eclipse使用的是哪个版本的编译器?
-
更新了 eclipse 并更改了合规性设置以解决这些问题。
标签: java eclipse stanford-nlp