Package nltk :: Package parse :: Module dependencygraph :: Class DependencyGraph
[hide private]
[frames] | no frames]

type DependencyGraph

source code

object --+
         |
        DependencyGraph

A container for the nodes and labelled edges of a dependency structure.

Instance Methods [hide private]
 
__init__(self, tree_str=None)
We place a dummy 'top' node in the first position in the nodelist, since the root node is often assigned '0' as its head.
source code
 
remove_by_address(self, address)
Removes the node with the given address.
source code
 
redirect_arcs(self, originals, redirect)
Redirects arcs to any of the nodes in the originals list to the redirect node address.
source code
 
add_arc(self, head_address, mod_address)
Adds an arc from the node specified by head_address to the node specified by the mod address.
source code
 
connect_graph(self)
Fully connects all non-root nodes.
source code
 
get_by_address(self, node_address)
Returns the node with the given address.
source code
 
contains_address(self, node_address)
Returns true if the graph contains a node with the given node address, false otherwise.
source code
 
__str__(self) source code
 
__repr__(self) source code
 
left_children(self, node_index)
Returns the number of left children under the node specified by the given address.
source code
 
right_children(self, node_index)
Returns the number of right children under the node specified by the given address.
source code
 
add_node(self, node) source code
 
_parse(self, input) source code
 
_word(self, node, filter=True) source code
 
_tree(self, i)
Recursive function for turning dependency graphs into NLTK trees.
source code
 
tree(self)
Starting with the root node, build a dependency tree using the NLTK Tree constructor.
source code
 
_hd(self, i) source code
 
_rel(self, i) source code
 
contains_cycle(self) source code
 
get_cycle_path(self, curr_node, goal_node_index) source code
str
to_conll(self, style)
The dependency graph in CoNLL format.
source code
Static Methods [hide private]
 
load(file) source code
 
_normalize(line)
Deal with lines in which spaces are used rather than tabs.
source code
Method Details [hide private]

__init__(self, tree_str=None)
(Constructor)

source code 

We place a dummy 'top' node in the first position in the nodelist, since the root node is often assigned '0' as its head. This also means that the indexing of the nodelist corresponds directly to the Malt-TAB format, which starts at 1.

Overrides: object.__init__

remove_by_address(self, address)

source code 

Removes the node with the given address. References to this node in others will still exist.

connect_graph(self)

source code 

Fully connects all non-root nodes. All nodes are set to be dependents of the root node.

__str__(self)
(Informal representation operator)

source code 
Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 
Overrides: object.__repr__
(inherited documentation)

load(file)
Static Method

source code 
Parameters:
  • file - a file in Malt-TAB format

_tree(self, i)

source code 

Recursive function for turning dependency graphs into NLTK trees.

Parameters:
  • i (int) - index of a node in nodelist
Returns:
either a word (if the indexed node is a leaf) or a Tree.

tree(self)

source code 

Starting with the root node, build a dependency tree using the NLTK Tree constructor. Dependency labels are omitted.

to_conll(self, style)

source code 

The dependency graph in CoNLL format.

Parameters:
  • style (int) - the style to use for the format (3, 4, 10 columns)
Returns: str