0

我正在使用斯坦福解析器。使用提供的 GUI 工具,它会从句子中输出 grafic 树 -就像这样,但是在保存输出时,它只会给出这样的括号格式(ROOT (NP (NP (DT The) (NN capability))...。是否可以使用命令行获得相同的输出(SVG)?如果没有,也许还有其他工具可以做到这一点?也许先获取 DOT 文件,最后使用 Graphviz 获取 SVG!?

4

2 回答 2

0

最后,我编写了自己的脚本来获取 DOT 格式,并进一步将其与 Graphviz 一起使用以获取 SVG 输出。

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.toDotFormat());
            }
        }
于 2013-04-18T11:29:48.083 回答
0

您可能想尝试 d3.js。这是一个树的例子:http: //mbostock.github.io/d3/talk/20111018/tree.html。其他示例在这里:https ://github.com/mbostock/d3/wiki/Gallery 。如果您想从命令行使用 d3 进行渲染,请尝试与 PhantomJS ( http://phantomjs.org/ ) 结合使用。PhantomJS 还允许您以 PNG 或 SVG 格式打印结果。这就是我作为网络人的处理方式。这样做的一个优点是您将能够在浏览器中运行它,并且将来可能会添加一些交互性。当然取决于你的应用...

于 2013-04-14T09:36:39.020 回答