In [1]:
import networkx as nx
# install with: sudo pip install git+http://github.com/chebee7i/nxpd/#egg=nxpd
from nxpd import draw
from discoursekernels.dependency_graph import (
common_dependency_targets, dependency_children, count_common_subgraphs,
get_dependency_rules, includes_all_subgraph_rules, is_dependency_subgraph,
get_dependency_subgraphs, generate_all_unique_dependency_subgraphs)
from discoursekernels.test_dependency_graph import the_man_saw_the_woman_with_the_telescope, the_man, with_the_telescope
from discoursekernels.util import label_nodes, label_edges, draw_multiple_graphs, memoize, print_source
In [2]:
draw(the_man_saw_the_woman_with_the_telescope, show='ipynb')
Out[2]:
In [3]:
draw(the_man, show='ipynb')
Out[3]:
In [4]:
draw(with_the_telescope, show='ipynb')
Out[4]:
$word(w)$: word at node $w$
edges signal a dependency from a head-word to a modifier
In [5]:
print_source(dependency_children)
Out[5]:
In [6]:
dependency_children(the_man_saw_the_woman_with_the_telescope, 2)
Out[6]:
In [7]:
print_source(common_dependency_targets)
Out[7]:
In [8]:
print_source(count_common_subgraphs)
Out[8]:
In [9]:
count_common_subgraphs(the_man_saw_the_woman_with_the_telescope, the_man_saw_the_woman_with_the_telescope, 1, 1)
Out[9]:
In [10]:
count_common_subgraphs(the_man, the_man, 1, 1)
Out[10]:
In [11]:
count_common_subgraphs(with_the_telescope, with_the_telescope, 1, 1)
Out[11]:
In [12]:
from discoursekernels.tree import get_subtrees
In [13]:
len(list(get_subtrees(the_man_saw_the_woman_with_the_telescope)))
Out[13]:
In [14]:
len(list(get_subtrees(the_man)))
Out[14]:
In [15]:
len(list(get_subtrees(with_the_telescope)))
Out[15]:
In [16]:
for st in get_subtrees(with_the_telescope):
# draw(st)
pass
In [17]:
print_source(get_dependency_rules)
Out[17]:
In [18]:
print_source(includes_all_subgraph_rules)
Out[18]:
In [19]:
print_source(is_dependency_subgraph)
Out[19]:
In [20]:
print_source(get_dependency_subgraphs)
Out[20]:
In [21]:
print_source(generate_all_unique_dependency_subgraphs)
Out[21]:
In [22]:
len(generate_all_unique_dependency_subgraphs([the_man_saw_the_woman_with_the_telescope]))
Out[22]:
In [23]:
draw_multiple_graphs(generate_all_unique_dependency_subgraphs([with_the_telescope]))
In [23]: