首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将斯坦福依赖关系转换为点格式

将斯坦福依赖关系转换为点格式
EN

Stack Overflow用户
提问于 2015-02-13 07:02:34
回答 1查看 656关注 0票数 1

我是这个领域的新手。我有这种形式的依赖关系:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-15 16:54:58

您需要在整个依赖树上调用toDotFormat。首先,您是如何生成这些依赖树的?

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

代码语言:javascript
复制
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());
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28494188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档