Package jazzparser :: Package parsers :: Package cky :: Module chart :: Class Chart
[hide private]
[frames] | no frames]

Class Chart

source code

object --+
         |
        Chart
Known Subclasses:

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.

Nested Classes [hide private]
  HASH_SET_IMPL
Based on the basic hash set implementation.
Instance Methods [hide private]
 
__init__(self, grammar, signs, derivations=False, hash_set_kwargs={}, allow_complex=False)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__len__(self) source code
 
_get_parses(self) 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(self, rule, sign_pair)
Internal method to apply a given binary rule to a given pair of signs.
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
 
apply_binary_rule(self, rule, start, middle, end)
Apply a given binary rule to particular arcs in the chart.
source code
 
__str__(self)
str(x)
source code
 
to_string(self, rows=None, cols=None) source code
 
_sign_string(self, sign) source code
 
_get_summary(self)
Returns a multi-line string that presents a brief summary of the chart as it currently stands.
source code
 
launch_inspector(self, input=None, block=False)
Starts up a graphical chart inspector to inspect this chart.
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__

Properties [hide private]
  size
  parses
  summary
Returns a multi-line string that presents a brief summary of the chart as it currently stands.

Inherited from object: __class__

Method Details [hide private]

__init__(self, grammar, signs, derivations=False, hash_set_kwargs={}, allow_complex=False)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

add_word_signs(self, signs, start_node, word, end_node=None)

source code 

Adds a single-word categories in list "signs" to the chart for the word starting at node start_node. This may span more than one node, in which case end_node should be given as well. By default, end_node will be assumed to be start_node+1.

apply_unary_rules(self, start, end, *args, **kwargs)

source code 

Adds to the chart all signs resulting from possible applications of unary rules to existing signs between nodes start and end.

Additional args/kwargs get passed on to apply_unary_rule.

Returns:
True if signs were added as a result of rule application, False otherwise

apply_unary_rule(self, rule, start, end, result_modifier=None)

source code 

Applies a given unary rule to particular arcs and adds the results to the chart.

Parameters:
  • result_modifier (2-arg function) - function to be applied to each result, taking the result sign as the first argument and the input sign as the second.

_apply_binary_rule(self, rule, sign_pair)

source code 

Internal method to apply a given binary rule to a given pair of signs. Note that the supported interface method is apply_binary_rule(), which applies a single rule to all sign pairs between given nodes.

This is used internally by apply_binary_rule and apply_binary_rules.

apply_binary_rules(self, start, middle, end)

source code 

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

Returns:
True if signs were added as a result of rule application, False otherwise

apply_binary_rule(self, rule, start, middle, end)

source code 

Apply a given binary rule to particular arcs in the chart.

Note that this method is not used by apply_binary_rules for efficiency reasons, but apply_binary_rules simply does the same thing for all possible binary rules.

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

_get_summary(self)

source code 

Returns a multi-line string that presents a brief summary of the chart as it currently stands. This does not show all of the signs in the chart, but just a summary of how many signs there are in each cell.

launch_inspector(self, input=None, block=False)

source code 

Starts up a graphical chart inspector to inspect this chart. The inspector will run in a separate thread. Subclasses of Chart should override this if they have their own version of the chart inspector and instantiate that instead.

Parameters:
  • input (list of strings) - a string representation of the input to pass to the inspector so it can display it.

Property Details [hide private]

size

Get Method:
__len__(self)

parses

Get Method:
_get_parses(self)

summary

Returns a multi-line string that presents a brief summary of the chart as it currently stands. This does not show all of the signs in the chart, but just a summary of how many signs there are in each cell.

Get Method:
_get_summary(self) - Returns a multi-line string that presents a brief summary of the chart as it currently stands.