How can I get the dependency tree as Figure below. I can get the dependency relation as pure text, and also the dependency graph with the help of dependencysee tool. But how
Here is how you would do exactly that (in python)
Installing all needed dependencies (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
code:
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()
which results in:
I used this when reading Text Analytics With Python: CH3, good read, please reference if you need more info about dependency-based parsing.