class documentation

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 __init__ Construct a new chart. The chart is initialized with the leaf edges corresponding to the terminal leaves.
Method child_pointer_lists Return 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.
Method dot_digraph Undocumented
Method edges Return 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.
Method initialize Clear the chart.
Method insert Add a new edge to the chart, and return 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_lists...
Method insert_with_backpointer Add a new edge to the chart, using a pointer to the previous edge.
Method iteredges Return an iterator over the edges in this chart. It is not guaranteed that new edges which are added to the chart before the iterator is exhausted will also be generated.
Method leaf Return the leaf value of the word at the given index.
Method leaves Return a list of the leaf values of each word in the chart's sentence.
Method num_edges Return the number of edges contained in this chart.
Method num_leaves Return the number of words in this chart's sentence.
Method parses Return an iterator of the complete tree structures that span the entire chart, and whose root node is root.
Method pretty_format Return a pretty-printed string representation of this chart.
Method pretty_format_edge Return a pretty-printed string representation of a given edge in this chart.
Method pretty_format_leaves Return a pretty-printed string representation of this chart's leaves. This string can be used as a header for calls to pretty_format_edge.
Method select Return 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.
Method trees Return an iterator of the tree structures that are associated with edge.
Method _add_index A helper function for select, which creates a new index for a given set of attributes (aka restriction keys).
Method _append_edge Undocumented
Method _register_with_indexes A helper function for insert, which registers the new edge with all existing indexes.
Method _trees A helper function for trees.
Instance Variable _edge_to_cpls A dictionary mapping each edge to a set of child pointer lists that are associated with that edge.
Instance Variable _edges A list of the edges in the chart
Instance Variable _indexes A dictionary mapping tuples of edge attributes to indices, where each index maps the corresponding edge attribute values to lists of edges.
Instance Variable _num_leaves The number of tokens.
Instance Variable _tokens The sentence that the chart covers.
def __init__(self, tokens): (source)

Construct a new chart. The chart is initialized with the leaf edges corresponding to the terminal leaves.

Parameters
tokens:listThe sentence that this chart will be used to parse.
def child_pointer_lists(self, edge): (source)

Return 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.

Returns
list(list(EdgeI))Undocumented
def dot_digraph(self): (source)

Undocumented

def edges(self): (source)

Return 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.

Returns
list(EdgeI)Undocumented
See Also
iteredges, select
def insert(self, edge, *child_pointer_lists): (source)

Add a new edge to the chart, and return 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_lists with edge.

Parameters
edge:EdgeIThe new edge
*child_pointer_lists:sequence of tuple(EdgeI)A sequence of lists 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.
Returns
boolUndocumented
def insert_with_backpointer(self, new_edge, previous_edge, child_edge): (source)

Add a new edge to the chart, using a pointer to the previous edge.

def iteredges(self): (source)

Return an iterator over the edges in this chart. It is not guaranteed that new edges which are added to the chart before the iterator is exhausted will also be generated.

Returns
iter(EdgeI)Undocumented
See Also
edges, select
def leaf(self, index): (source)

Return the leaf value of the word at the given index.

Returns
strUndocumented
def leaves(self): (source)

Return a list of the leaf values of each word in the chart's sentence.

Returns
list(str)Undocumented
def num_edges(self): (source)

Return the number of edges contained in this chart.

Returns
intUndocumented
def num_leaves(self): (source)

Return the number of words in this chart's sentence.

Returns
intUndocumented
def parses(self, root, tree_class=Tree): (source)

Return an iterator of the complete tree structures that span the entire chart, and whose root node is root.

def pretty_format(self, width=None): (source)

Return a pretty-printed string representation of this chart.

Parameters
widthThe number of characters allotted to each index in the sentence.
Returns
strUndocumented
def pretty_format_edge(self, edge, width=None): (source)

Return a pretty-printed string representation of a given edge in this chart.

Parameters
edgeUndocumented
widthThe number of characters allotted to each index in the sentence.
Returns
strUndocumented
def pretty_format_leaves(self, width=None): (source)

Return a pretty-printed string representation of this chart's leaves. This string can be used as a header for calls to pretty_format_edge.

def select(self, **restrictions): (source)

Return 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.

Parameters
spanOnly generate edges e where e.span()==span
startOnly generate edges e where e.start()==start
endOnly generate edges e where e.end()==end
lengthOnly generate edges e where e.length()==length
lhsOnly generate edges e where e.lhs()==lhs
rhsOnly generate edges e where e.rhs()==rhs
nextsymOnly generate edges e where e.nextsym()==nextsym
dotOnly generate edges e where e.dot()==dot
is_completeOnly generate edges e where e.is_complete()==is_complete
is_incompleteOnly generate edges e where e.is_incomplete()==is_incomplete
**restrictionsUndocumented
Returns
iter(EdgeI)Undocumented
def trees(self, edge, tree_class=Tree, complete=False): (source)

Return an iterator 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.

Returns
list(Tree)Undocumented
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.
def _add_index(self, restr_keys): (source)

A helper function for select, which creates a new index for a given set of attributes (aka restriction keys).

def _append_edge(self, edge): (source)

Undocumented

def _register_with_indexes(self, edge): (source)

A helper function for insert, which registers the new edge with all existing indexes.

def _trees(self, edge, complete, memo, tree_class): (source)

A helper function for trees.

Parameters
edgeUndocumented
completeUndocumented
memoA dictionary used to record the trees that we've generated for each edge, so that when we see an edge more than once, we can reuse the same trees.
tree_classUndocumented
_edge_to_cpls: dict = (source)

A dictionary mapping each edge to a set of child pointer lists that are associated with that edge.

_edges: list = (source)

A list of the edges in the chart

_indexes: dict = (source)

A dictionary mapping tuples of edge attributes to indices, where each index maps the corresponding edge attribute values to lists of edges.

_num_leaves = (source)

The number of tokens.

The sentence that the chart covers.