Class Variable
source code
object --+
|
Variable
A Variable is an object that can be used in unification to hold an
initially unknown value. Two equivalent Variables, for example, can be
used to require that two features have the same value.
When a Variable is assigned a value, it will eventually be replaced by
that value. However, in order to make that value show up everywhere the
variable appears, the Variable temporarily stores its assigned value and
becomes a bound variable. Bound variables do not appear in the
results of unification.
Variables are distinguished by their name, and by the dictionary of
bindings that is being used to determine their values. Two
variables can have the same name but be associated with two different
binding dictionaries: those variables are not equal.
|
|
string
|
|
object
|
|
Variable
|
|
Variable
|
|
|
|
Variable
|
forwardTo(self,
other,
ourbindings,
otherbindings)
A unification wants this variable to be aliased to another variable. |
source code
|
|
|
|
|
__cmp__(self,
other)
Variables are equal if they are the same object or forward to the
same object. |
source code
|
|
|
|
Inherited from object :
__delattr__ ,
__getattribute__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__ ,
__str__
|
__init__(self,
name=None,
value=None)
(Constructor)
| source code
|
Construct a new feature structure variable.
The value should be left at its default of None; it is only used
internally to copy bound variables.
- Parameters:
name (string ) - An identifier for this variable. Two Variable
objects with the same name will be given the same value in a
given dictionary of bindings.
- Overrides:
object.__init__
|
- Returns:
string
- This variable's name.
|
If this varable is bound, find its value. If it is unbound or aliased
to an unbound variable, returns None.
- Returns:
object
- The value of this variable, if any.
|
- Returns:
Variable
- A copy of this variable.
|
Variables are aliased to other variables by one variable _forwarding_
to the other. The first variable simply has the second as its value, but
it acts like the second variable's _value_ is its value.
forwarded_self returns the final Variable object that actually stores
the value.
- Returns:
Variable
- The
Variable responsible for storing this variable's
value.
|
bindValue(self,
value,
ourbindings,
otherbindings)
| source code
|
Bind this variable to a value. ourbindings are the
bindings that accompany the feature structure this variable came from;
otherbindings are the bindings from the structure it's being
unified with.
- Parameters:
value (object ) - The value to be assigned.
ourbindings (dict ) - The bindings associated with this variable.
otherbindings (dict ) - The bindings associated with the value being assigned. (May be
identical to ourbindings .)
|
forwardTo(self,
other,
ourbindings,
otherbindings)
| source code
|
A unification wants this variable to be aliased to another variable.
Forward this variable to the other one, and return the other.
- Parameters:
other (Variable ) - The variable to replace this one.
ourbindings (dict ) - The bindings associated with this variable.
otherbindings (dict ) - The bindings associated with the other variable. (May be
identical to ourbindings .)
- Returns:
Variable
other
|
hash(x)
- Overrides:
object.__hash__
- (inherited documentation)
|
Variables are equal if they are the same object or forward to the same
object. Variables with the same name may still be unequal.
|
repr(x)
- Overrides:
object.__repr__
- (inherited documentation)
|