2012-11-20 169 views

回答

8

这些曲线图是使用GraphViz,一个开源图表绘图包,从AT & T研究所最初生产。您可以在edu.stanford.nlp.trees.semgraph.SemanticGraph中找到一种方法toDotFormat(),该方法会将SemanticGraph转换为dot输入语言格式,该格式可由dot/GraphViz呈现。目前,没有提供此功能的命令行工具,但使用该方法非常简单。

2

我正在处理类似的事情。这不是一个理想的解决方案,但它可能会有所帮助。如上面的答案中所述,使用toDotFormat()以点语言获得解析树。然后使用众多工具之一(我使用python-graph)读取这些数据并将其渲染为图片。有这个链接的例子http://code.google.com/p/python-graph/wiki/Example

1

我也非常需要它;现在很高兴看到我们也有在线工具。使用此:http://graphs.grevian.org/graph(这里提到:http://graphs.grevian.org/

的步骤是:

  1. 解析了一句:

    sent = 'What is the step by step guide to invest in share market in india?' 
    p = dep_parser.raw_parse(sent) 
    for e in p: 
        p = e 
        break 
    
  2. 打印.to_dot()格式为:

    print(p.to_dot()) 
    
  3. 复制粘贴输出到http://graphs.grevian.org/graph并按下Generate按钮。

您应该看到所需的图形。

+0

谢谢克里斯托弗。真的很高兴你。 – user1953366

1

这里是你会怎么做究竟

是(在Python)安装所有需要的依赖关系(OS X):

# assuming you have java installed and available in PATH 
# and homebrew installed 

brew install stanford-parser 
brew install graphviz 
pip install nltk 
pip install graphviz 

代码:

import os 
from nltk.parse.stanford import StanfordDependencyParser 
from graphviz import Source 

# make sure nltk can find stanford-parser 
# please check your stanford-parser version from brew output (in my case 3.6.0) 
os.environ['CLASSPATH'] = r'/usr/local/Cellar/stanford-parser/3.6.0/libexec' 

sentence = 'The brown fox is quick and he is jumping over the lazy dog' 

sdp = StanfordDependencyParser() 
result = list(sdp.raw_parse(sentence)) 

dep_tree_dot_repr = [parse for parse in result][0].to_dot() 
source = Source(dep_tree_dot_repr, filename="dep_tree", format="png") 
source.view() 

其结果是:

CH3,好读,如果您需要了解基于依赖性分析的详细信息,请参考:

enter image description here

我读书时Text Analytics With Python用这个。

相关问题