我是这个领域的新手。我有这种形式的依赖关系:
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绘制“依赖树”。我无法理解如何将这种依赖关系传递给toDotFormat()函数的edu.stanford.nlp.semgraph.SemanticGraph。当我给出这个字符串‘amod(清晰度-2,声音-1)’作为toDotFormat()的输入时,将以这种形式获得有向图amod(清晰度-2,声音-1){ }的输出。我正在尝试这里给出的解决方案,how to get a dependency tree with Stanford NLP parser
发布于 2015-02-15 16:54:58
您需要在整个依赖树上调用toDotFormat。首先,您是如何生成这些依赖树的?
如果您使用的是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());
}https://stackoverflow.com/questions/28494188
复制相似问题