Represents a chart for use in CKY chart parsing. A Chart stores a
table of signs between node pairs. It keeps a list of all the rules that
can be applied.
There are no edges (i,i) and all edges are directed forward (i.e.
(i,j) where j>i). Internally, the table only stores edges from each i
to each j>i.
In the interface, however, edges are always referred to by the nodes
they go from and to.
Functions are contained in Chart for applying unary and binary
rules.
You may instantiate a chart with no signs. You must still provide a
signs list, which will define the size of the chart, so you should fill
it with empty lists.
By default, chart.parses will only return atomic results, since only
these represent full parses. If you want all signs that span the whole
input, use chart.get_signs(0, end). If you decide that complex results
represent real parses, instantiate the chart with allow_complex=True.
|
|
__init__(self,
grammar,
signs,
derivations=False,
hash_set_kwargs={},
allow_complex=False)
x.__init__(...) initializes x; see help(type(x)) for signature |
source code
|
|
|
|
|
|
|
|
|
|
get_signs(self,
start,
end)
Gets a list of the signs in the chart between nodes start and end. |
source code
|
|
|
|
get_grouped_signs(self,
start,
end)
Like get_signs, but return a list of lists of signs, such
that every sign in a sublist has the same syntactic category. |
source code
|
|
|
|
get_sign(self,
start,
end,
index)
Returns the sign between start and end with the given index. |
source code
|
|
|
|
get_sign_pairs(self,
start,
middle,
end)
Gets a list of pairs (first,second) such that first starts at start
and ends at middle and second starts at middle and ends at end. |
source code
|
|
|
|
get_grouped_sign_pairs(self,
start,
middle,
end)
Like get_sign_pairs, but instead of returning pairs of
signs, returns pairs of sign groups, where all the signs in the group
have the same syntactic category. |
source code
|
|
|
|
add_word_signs(self,
signs,
start_node,
word,
end_node=None)
Adds a single-word categories in list "signs" to the chart
for the word starting at node start_node. |
source code
|
|
|
|
apply_unary_rules(self,
start,
end,
*args,
**kwargs)
Adds to the chart all signs resulting from possible applications of
unary rules to existing signs between nodes start and end. |
source code
|
|
|
|
apply_unary_rule(self,
rule,
start,
end,
result_modifier=None)
Applies a given unary rule to particular arcs and adds the results to
the chart. |
source code
|
|
|
|
|
|
|
_apply_binary_rule_semantics(self,
rule,
sign_pair,
category)
Like _apply_binary_rule, but uses the
apply_rule_semantics() of the rule instead of
apply_rule() and returns a list of signs built by
copying the category and combining it in a sign with the semantics of
the result. |
source code
|
|
|
|
apply_binary_rules(self,
start,
middle,
end)
Add to the chart all signs resulting from possible applications of
binary rules to pairs of signs between node pairs (start,middle) and
(middle,end), producing entries in (start,end). |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_get_summary(self)
Returns a multi-line string that presents a brief summary of the
chart as it currently stands. |
source code
|
|
|
|
|
|
|
kill_inspector(self)
Kills a currently-running inspector for this chart if one exists. |
source code
|
|
|
Inherited from object:
__delattr__,
__format__,
__getattribute__,
__hash__,
__new__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__sizeof__,
__subclasshook__
|