Parsing 将Stanford依赖关系转换为点格式

Parsing 将Stanford依赖关系转换为点格式,parsing,stanford-nlp,Parsing,Stanford Nlp,我是这个领域的新手。我在此表格中有依赖关系: amod(clarity-2, sound-1) nsubj(good-6, clarity-2) cop(good-6, is-3) advmod(good-6, also-4) neg(good-6, not-5) root(ROOT-0, good-6) nsubj(ok-10, camera-8) cop(ok-10, is-9) ccomp(good-6, ok-10) 如链接中所述,我们必须将此依赖关系转换为点格式,然后使用Graphv

我是这个领域的新手。我在此表格中有依赖关系:

amod(clarity-2, sound-1)
nsubj(good-6, clarity-2)
cop(good-6, is-3)
advmod(good-6, also-4)
neg(good-6, not-5)
root(ROOT-0, good-6)
nsubj(ok-10, camera-8)
cop(ok-10, is-9)
ccomp(good-6, ok-10)
如链接中所述,我们必须将此依赖关系转换为点格式,然后使用Graphviz绘制“依赖树”。我无法理解如何将此依赖关系传递给edu.stanford.nlp.semgraph.SemanticGraph的toDotFormat()函数。当我把这个字符串“amod(clearity-2,sound-1)”作为toDotFormat()的输入时,我得到的输出是有向图amod(clearity-2,sound-1){}。 我正在尝试这里给出的解决方案

您需要调用整个依赖关系树。首先,您是如何生成这些依赖关系树的

如果您使用的是StanfordCoreNLP管道,那么添加
toDotFormat
调用很容易:

Properties properties = new Properties();
props.put("annotators", "tokenize, ssplit, pos, depparse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

String text = "This is a sentence I want to parse.";
Annotation document = new Annotation(text);

pipeline.annotate(document);

// these are all the sentences in this document
// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
List<CoreMap> sentences = document.get(SentencesAnnotation.class);

for (CoreMap sentence : sentences) {
  // this is the Stanford dependency graph of the current sentence
  SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
  System.out.println(dependencies.toDotFormat());
}
Properties属性=新属性();
props.put(“注释器”、“标记化、ssplit、pos、depparse”);
StanfordCoreNLP管道=新的StanfordCoreNLP(道具);
String text=“这是我要分析的句子。”;
注释文档=新注释(文本);
管道注释(文件);
//这些是本文件中的所有句子
//CoreMap本质上是一个使用类对象作为键并具有自定义类型值的映射
列出句子=document.get(SentencesAnnotation.class);
for(CoreMap句子:句子){
//这是当前句子的斯坦福依存关系图
SemanticGraph dependencies=句子.get(CollapsedCCProcessedDependenciesAnnotation.class);
System.out.println(dependencies.toDotFormat());
}

谢谢您的回复@Jon Gauthier!是的,我只使用斯坦福解析器,链接这里。请您澄清一下这里的“字符串文本”是什么,它是包含我上面提到的依赖关系的文件名吗?我目前正在为edu.stanford.nlp.semgraph.SemanticGraph类使用stanford-tregex.jat文件。我收到错误:找不到符号批注文档=新批注(文本);你能帮我做这个吗!使用示例
text
值更新-这是您想要解析的任何句子内容。为此,您应该使用Stanford CoreNLP或Stanford解析器。您可以从Hurray下载CoreNLP软件包!现在我可以生成点格式的文件。非常感谢@Jon Gauthier!:)很高兴它起作用了,@VenkataAnusha!如果这解决了您的问题,请您将此答案标记为已接受?(左侧投票按钮下方的绿色复选标记)