nltk.ccg.CCGChart

class nltk.ccg.CCGChart[source]

Bases: Chart

__init__(tokens)[source]

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

Parameters

tokens (list) – The sentence that this chart will be used to parse.

child_pointer_lists(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.

Return type

list(list(EdgeI))

dot_digraph()[source]
edges()[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.

Return type

list(EdgeI)

See

iteredges, select

initialize()[source]

Clear the chart.

insert(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 (EdgeI) – The 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.

Return type

bool

insert_with_backpointer(new_edge, previous_edge, child_edge)[source]

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

iteredges()[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.

Return type

iter(EdgeI)

See

edges, select

leaf(index)[source]

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

Return type

str

leaves()[source]

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

Return type

list(str)

num_edges()[source]

Return the number of edges contained in this chart.

Return type

int

num_leaves()[source]

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

Return type

int

parses(root, tree_class=<class 'nltk.tree.tree.Tree'>)[source]

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

pretty_format(width=None)[source]

Return a pretty-printed string representation of this chart.

Parameters

width – The number of characters allotted to each index in the sentence.

Return type

str

pretty_format_edge(edge, width=None)[source]

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

Return type

str

Parameters

width – The number of characters allotted to each index in the sentence.

pretty_format_leaves(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.

select(**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
  • 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

  • nextsym – Only generate edges e where e.nextsym()==nextsym

  • 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

Return type

iter(EdgeI)

trees(edge, tree_class=<class 'nltk.tree.tree.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.

Return type

list(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.