Skip to content

Commit e31d6ff

Browse files
authored
Merge pull request dipanjanS#4 from ambientlight/patch-1
Graphviz code for Fig 3-4 generation
2 parents 84f0529 + 754ccd9 commit e31d6ff

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Chapter-3/dependency_parsing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@
4141
dep_tree = [parse.tree() for parse in result][0]
4242
print dep_tree
4343
dep_tree.draw()
44-
45-
44+
45+
# generation of annotated dependency tree shown in Figure 3-4
46+
from graphviz import Source
47+
dep_tree_dot_repr = [parse for parse in result][0].to_dot()
48+
source = Source(dep_tree_dot_repr, filename="dep_tree", format="png")
49+
source.view()
50+
4651
import nltk
4752
tokens = nltk.word_tokenize(sentence)
4853

@@ -61,4 +66,4 @@
6166
tree = res[0]
6267
print tree
6368

64-
tree.draw()
69+
tree.draw()

0 commit comments

Comments
 (0)