2013-04-13 46 views
0

我正在使用Stanford Parser。使用提供的GUI工具,它從句子like this輸出圖形樹,但是當保存輸出時,它只是給出了括號格式,如(ROOT (NP (NP (DT The) (NN capability))...。 是否可以使用命令行獲得相同的輸出(SVG)? 如果沒有,也許有一些其他工具呢?也許首先獲得DOT文件並使用Graphviz最終獲得SVG!斯坦福解析器輸出到SVG

回答

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()); 
      } 
     } 
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中打印結果。這就是我作爲一個網絡人物接近它的方式。這樣做的一個優點是您可以在瀏覽器中運行它,並且可能在將來添加一些交互功能。取決於你的應用程序...

+0

在這種情況下,它不是關於使用哪種圖形工具,而是如何使用Stanford Parser自動(半自動) – werd