Package nltk_lite :: Module featurestructure :: Class FeatureBindings
[hide private]
[frames] | no frames]

Class FeatureBindings

source code

object --+
         |
        FeatureBindings

A partial mapping from feature variables to values. Simple variables can be either bound (i.e., assigned a value), or unbound (i.e., left unspecified). Aliased variables can additionally be inconsistant (i.e., assigned multiple incompatible values).

Instance Methods [hide private]
 
__init__(self, initial_bindings=None)
Construct a new set of bindings.
source code
list of FeatureVariable
bound_variables(self)
Returns: A list of all simple variables that have been assigned values.
source code
bool
is_bound(self, variable)
Returns: True if the given variable is bound.
source code
 
lookup(self, variable, update_aliased_bindings=True)
Returns: The value that it assigned to the given variable, if it's bound; or the variable itself if it's unbound.
source code
 
bind(self, variable, value)
Assign a value to a variable.
source code
 
copy(self)
Returns: a copy of this set of bindings.
source code
 
__repr__(self)
Returns: a string representation of this set of bindings.
source code
 
__cmp__(self, other) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Instance Variables [hide private]
  _bindings
A dictionary mapping from bound variables to their values.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, initial_bindings=None)
(Constructor)

source code 

Construct a new set of bindings.

Parameters:
  • initial_bindings - A dictionary from variables to values, specifying the initial assignments for the bound variables.
Overrides: object.__init__

bound_variables(self)

source code 
Returns: list of FeatureVariable
A list of all simple variables that have been assigned values.

is_bound(self, variable)

source code 
Returns: bool
True if the given variable is bound. A simple variable is bound if it has been assigned a value. An aliased variable is bound if at least one of its aliases is bound and all of its bound aliases are assigned the same value.

lookup(self, variable, update_aliased_bindings=True)

source code 
Parameters:
  • update_aliased_bindings - If true, then looking up a bound aliased variable will cause any unbound aliases it has to be bound to its value. E.g., if ?x is bound to 1 and ?y is unbound, then looking up ?x=y will cause ?y to be bound to 1.
Returns:
The value that it assigned to the given variable, if it's bound; or the variable itself if it's unbound. The value assigned to an aliased variable is defined as the value that's assigned to its bound aliases.
Raises:
  • ValueError - If variable is an aliased variable with an inconsistant value (i.e., if two or more of its bound aliases are assigned different values).

bind(self, variable, value)

source code 

Assign a value to a variable. If variable is an aliased variable, then the value is assigned to all of its aliases. Variables can only be bound to values; they may not be bound to other variables.

Raises:
  • ValueError - If value is a variable.

copy(self)

source code 
Returns:
a copy of this set of bindings.

__repr__(self)
(Representation operator)

source code 

repr(x)

Returns:
a string representation of this set of bindings.
Overrides: object.__repr__