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

Class FeatureVariable

source code

SubstituteBindingsI --+
                      |
                     FeatureVariable
Known Subclasses:
AliasedFeatureVariable

A variable that can stand for a single feature value in a feature structure. Each variable is defined by a unique identifier, which can be either a case-sensitive string (for named variables) or an integer (for numbered variables).

Named variables are created by calling the FeatureVariable constructor with a string identifier. If multiple named variables objects are created with the same identifier, then they represent the same variable. Numbered variables are created by calling the FeatureVariable constructor with no arguments; a new identifier will be automatically generated. Each new numbered variable object is guaranteed to have a unique identifier.

Variables do not directly contain values; instead, the mapping from variables to values is encoded externally as a set of bindings, using FeatureBindings. If a set of bindings assigns a value to a variable, then that variable is said to be bound with respect to those bindings; otherwise, it is said to be unbound.


See Also: FeatureStructure

Instance Methods [hide private]
 
__init__(self, identifier=None)
Construct a new feature structure variable.
source code
string
identifier(self)
Returns: This variable's unique identifier.
source code
 
__repr__(self)
Returns: A string representation of this feature structure variable.
source code
 
__cmp__(self, other) source code
 
__hash__(self) source code
AliasedFeatureVariable
alias(self, variable)
Return an aliased variable that constrains this variable to be equal to variable.
source code
(any)
substitute_bindings(self, bindings)
Returns: The value that is bound to this variable if it appears in @bindings otherwise just return self.
source code
Static Methods [hide private]
 
parse(s)
Given a string that encodes a feature variable, return that variable.
source code
Class Variables [hide private]
  _next_numbered_id = 1
Method Details [hide private]

__init__(self, identifier=None)
(Constructor)

source code 

Construct a new feature structure variable.

Parameters:
  • identifier (string) - A unique identifier for this variable. Any two FeatureVariable objects with the same identifier are treated as the same variable.

identifier(self)

source code 
Returns: string
This variable's unique identifier.

__repr__(self)
(Representation operator)

source code 
Returns:
A string representation of this feature structure variable. A feature structure variable with identifier x is represented as '?x'.

substitute_bindings(self, bindings)

source code 
Returns: (any)
The value that is bound to this variable if it appears in @bindings otherwise just return self.
Overrides: SubstituteBindingsI.substitute_bindings

parse(s)
Static Method

source code 

Given a string that encodes a feature variable, return that variable. This method can be used to parse both FeatureVariables and AliasedFeatureVariables. However, this method can not be used to parse numbered variables, since doing so could violate the guarantee that each numbered variable object has a unique identifier.