Package nltk_lite :: Package parse :: Module chart :: Class Chart
[show private | hide private]
[frames | no frames]

Type Chart

object --+
         |
        Chart


A blackboard for hypotheses about the syntactic constituents of a sentence. A chart contains a set of edges, and each edge encodes a single hypothesis about the structure of some portion of the sentence.

The select method can be used to select a specific collection of edges. For example chart.select(is_complete=True, start=0) yields all complete edges whose start indices are 0. To ensure the efficiency of these selection operations, Chart dynamically creates and maintains an index for each set of attributes that have been selected on.

In order to reconstruct the trees that are represented by an edge, the chart associates each edge with a set of child pointer lists. A child pointer list is a list of the edges that license an edge's right-hand side.
Method Summary
  __init__(self, tokens)
Construct a new empty chart.
iter of EdgeI __iter__(self)
Return an iterator over the edges in this chart.
list of list of Edge child_pointer_lists(self, edge)
Return the set of child pointer lists for the given edge.
  dot_digraph(self)
list of EdgeI edges(self)
Return a list of all edges in this chart.
bool insert(self, edge, child_pointer_list)
Add a new edge to the chart.
iter of EdgeI iteredges(self)
Return an iterator over the edges in this chart.
string leaf(self, index)
Return the leaf value of the word at the given index.
list of string leaves(self)
Return a list of the leaf values of each word in the chart's sentence.
int num_edges(self)
Return the number of edges contained in this chart.
int num_leaves(self)
Return the number of words in this chart's sentence.
  parses(self, root, tree_class)
Return a list of the complete tree structures that span the entire chart, and whose root node is root.
string pp(self, width)
Return a pretty-printed string representation of this chart.
string pp_edge(self, edge, width)
Return a pretty-printed string representation of a given edge in this chart.
  pp_leaves(self, width)
Return a pretty-printed string representation of this chart's leaves.
iter of EdgeI select(self, **restrictions)
Return an iterator over the edges in this chart.
list of Tree trees(self, edge, tree_class, complete)
Return a list of the tree structures that are associated with edge.
Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Method Details

__init__(self, tokens)
(Constructor)

Construct a new empty chart.
Parameters:
tokens - The sentence that this chart will be used to parse.
           (type=list)
Overrides:
__builtin__.object.__init__

__iter__(self)

Returns:
An iterator over the edges in this chart. Any new edges that are added to the chart before the iterator is exahusted will also be generated.
           (type=iter of EdgeI)

See Also: edges, select

child_pointer_lists(self, edge)

Returns:
The set of child pointer lists for the given edge. Each child pointer list is a list of edges that have been used to form this edge.
           (type=list of list of Edge)

edges(self)

Returns:
A list of all edges in this chart. New edges that are added to the chart after the call to edges() will not be contained in this list.
           (type=list of EdgeI)

See Also: iteredges, select

insert(self, edge, child_pointer_list)

Add a new edge to the chart.
Parameters:
edge - The new edge
           (type=Edge)
child_pointer_list - A list of the edges that were used to form this edge. This list is used to reconstruct the trees (or partial trees) that are associated with edge.
           (type=tuple of Edge)
Returns:
True if this operation modified the chart. In particular, return true iff the chart did not already contain edge, or if it did not already associate child_pointer_list with edge.
           (type=bool)

iteredges(self)

Returns:
An iterator over the edges in this chart. Any new edges that are added to the chart before the iterator is exahusted will also be generated.
           (type=iter of EdgeI)

See Also: edges, select

leaf(self, index)

Returns:
The leaf value of the word at the given index.
           (type=string)

leaves(self)

Returns:
A list of the leaf values of each word in the chart's sentence.
           (type=list of string)

num_edges(self)

Returns:
The number of edges contained in this chart.
           (type=int)

num_leaves(self)

Returns:
The number of words in this chart's sentence.
           (type=int)

parses(self, root, tree_class=<class 'nltk_lite.parse.tree.Tree'>)

Returns:
A list of the complete tree structures that span the entire chart, and whose root node is root.

pp(self, width=None)

Parameters:
width - The number of characters allotted to each index in the sentence.
Returns:
A pretty-printed string representation of this chart.
           (type=string)

pp_edge(self, edge, width=None)

Parameters:
width - The number of characters allotted to each index in the sentence.
Returns:
A pretty-printed string representation of a given edge in this chart.
           (type=string)

pp_leaves(self, width=None)

Returns:
A pretty-printed string representation of this chart's leaves. This string can be used as a header for calls to pp_edge.

select(self, **restrictions)

Keyword Parameters:
span - Only generate edges e where e.span()==span
start - Only generate edges e where e.start()==start
end - Only generate edges e where e.end()==end
length - Only generate edges e where e.length()==length
lhs - Only generate edges e where e.lhs()==lhs
rhs - Only generate edges e where e.rhs()==rhs
next - Only generate edges e where e.next()==next
dot - Only generate edges e where e.dot()==dot
is_complete - Only generate edges e where e.is_complete()==is_complete
is_incomplete - Only generate edges e where e.is_incomplete()==is_incomplete
Returns:
An iterator over the edges in this chart. Any new edges that are added to the chart before the iterator is exahusted will also be generated. restrictions can be used to restrict the set of edges that will be generated.
           (type=iter of EdgeI)

trees(self, edge, tree_class=<class 'nltk_lite.parse.tree.Tree'>, complete=False)

Returns:

A list of the tree structures that are associated with edge.

If edge is incomplete, then the unexpanded children will be encoded as childless subtrees, whose node value is the corresponding terminal or nonterminal.
           (type=list of Tree)

Note: If two trees share a common subtree, then the same Tree may be used to encode that subtree in both trees. If you need to eliminate this subtree sharing, then create a deep copy of each tree.


Generated by Epydoc 2.1 on Tue Sep 5 09:37:21 2006 http://epydoc.sf.net