来自在线演示Stanford CoreNLP的示例句子“可以在隔离中测试的最小软件项目”,它给出了CC处理的折叠依赖关系,如下所示:
root ( ROOT-0 , item-4 )
det ( item-4 , A-1 )
amod ( item-4 , minimal-2 )
nn ( item-4 , software-3 )
nsubjpass ( tested-8 , that-5 )
aux ( tested-8 , can-6 )
auxpass ( tested-8 , be-7 )
rcmod ( item-4 , tested-8 )
prep_in ( tested-8 , isolation-10 )从我的Java类中,除了root(...)之外,我得到了相同的结果。我正在运行的代码如下:
public static void main(String[] args)
{
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation(args[0]);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
SemanticGraph dependencies = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);
System.out.println(dependencies.toList());
}
}所以问题是为什么我的Java代码不能输出root`s!?我是不是遗漏了什么?
发布于 2013-05-01 13:17:30
这是一个很好的问题,因为它暴露了当前代码中的一个缺点。目前,根节点和来自它的边没有存储在图中。*相反,它们必须作为图的根/根列表单独访问,存储为单独的列表。下面是两个可行的方法:(1)在System.out.println上添加以下代码
IndexedWord root = dependencies.getFirstRoot();
System.out.printf("ROOT(root-0, %s-%d)%n", root.word(), root.index());(2)用当前行代替当前行:
System.out.println(dependencies.toString("readable"));与其他toList()或toString()方法不同,它确实打印根目录。
*这是有历史原因的:我们过去没有任何显式的根。但在这一点上,这种行为是笨拙和功能失调的,应该改变。这可能会在未来的版本中发生。
https://stackoverflow.com/questions/16300056
复制相似问题