Package nltk_lite :: Package contrib :: Module hole :: Class HoleSemantics
[hide private]
[frames] | no frames]

Class HoleSemantics

source code

This class holds the broken-down components of a hole semantics, i.e. it extracts the holes, labels, logic formula fragments and constraints out of a big conjunction of such as produced by the hole semantics grammar. It then provides some operations on the semantics dealing with holes, labels and finding legal ways to plug holes with labels.

Instance Methods [hide private]
 
__init__(self, usr)
Constructor.
source code
 
is_label(self, x)
Return true if x is a label in this semantic representation.
source code
 
is_hole(self, x)
Return true if x is a hole in this semantic representation.
source code
 
is_node(self, x)
Return true if x is a node (label or hole) in this semantic representation.
source code
 
_break_down(self, usr)
Extract holes, labels, formula fragments and constraints from the hole semantics underspecified representation (USR).
source code
 
_find_top_most_labels(self)
Return the set of labels which are not referenced directly as part of another formula fragment.
source code
 
_find_top_hole(self)
Return the hole that will be the top of the formula tree.
source code
 
pluggings(self)
Calculate and return all the legal pluggings (mappings of labels to holes) of this semantics given the constraints.
source code
 
_plug_nodes(self, queue, potential_labels, plug_acc, record)
Plug the nodes in `queue' with the labels in `potential_labels'.
source code
 
_plug_hole(self, hole, ancestors0, queue, potential_labels0, plug_acc0, record)
Try all possible ways of plugging a single hole.
source code
 
_violates_constraints(self, label, ancestors)
Return True if the `label' cannot be placed underneath the holes given by the set `ancestors' because it would violate the constraints imposed on it.
source code
 
_sanity_check_plugging(self, plugging, node, ancestors)
Make sure that a given plugging is legal.
source code
 
formula_tree(self, plugging)
Return the first-order logic formula tree for this underspecified representation using the plugging given.
source code
 
_formula_tree(self, plugging, node) source code
Method Details [hide private]

__init__(self, usr)
(Constructor)

source code 

Constructor. `usr' is a tree of nodes that can take the forms: (and t t'), (hole v), (label v), (: v phi), (leq v v) where t, t' are subtrees, v is a variable, and phi is a formula fragment.

_find_top_most_labels(self)

source code 

Return the set of labels which are not referenced directly as part of another formula fragment. These will be the top-most labels for the subtree that they are part of.

_plug_nodes(self, queue, potential_labels, plug_acc, record)

source code 

Plug the nodes in `queue' with the labels in `potential_labels'.

Each element of `queue' is a tuple of the node to plug and the list of ancestor holes from the root of the graph to that node.

`potential_labels' is a set of the labels which are still available for plugging.

`plug_acc' is the incomplete mapping of holes to labels made on the current branch of the search tree so far.

`record' is a list of all the complete pluggings that we have found in total so far. It is the only parameter that is destructively updated.

_plug_hole(self, hole, ancestors0, queue, potential_labels0, plug_acc0, record)

source code 

Try all possible ways of plugging a single hole. See _plug_nodes for the meanings of the parameters.

_sanity_check_plugging(self, plugging, node, ancestors)

source code 

Make sure that a given plugging is legal. We recursively go through each node and make sure that no constraints are violated. We also check that all holes have been filled.