Basic data classes for representing feature structures, and for
performing basic operations on those feature structures. A feature
structure is a mapping from feature identifiers to feature values,
where each feature value is either a basic value (such as a string or an
integer), or a nested feature structure. There are two types of feature
structure, implemented by two subclasses of FeatStruct:
Feature structures are typically used to represent partial information
about objects. A feature identifier that is not mapped to a value stands
for a feature whose value is unknown (not a feature without a
value). Two feature structures that represent (potentially overlapping)
information about the same object can be combined by unification. When
two inconsistent feature structures are unified, the unification fails
and returns None
.
In general, if your feature structures will contain any reentrances,
or if you plan to use them as dictionary keys, it is strongly
recommended that you use full-fledged FeatStruct objects.
|
_check_frozen(method,
indent='
' )
Given a method function, return a new method function that first
checks if self._frozen is true; and if so, raises
ValueError with an appropriate message. |
source code
|
|
|
substitute_bindings(fstruct,
bindings,
fs_class=' default ' )
Returns:
The feature structure that is obtained by replacing each variable
bound by bindings with its binding. |
source code
|
|
|
_substitute_bindings(fstruct,
bindings,
fs_class,
visited) |
source code
|
|
|
retract_bindings(fstruct,
bindings,
fs_class=' default ' )
Returns:
The feature structure that is obtained by replacing each feature
structure value that is bound by bindings with the
variable that binds it. |
source code
|
|
|
_retract_bindings(fstruct,
inv_bindings,
fs_class,
visited) |
source code
|
|
set of Variable
|
|
|
_variables(fstruct,
vars,
fs_class,
visited) |
source code
|
|
|
rename_variables(fstruct,
vars=None,
used_vars=( ) ,
new_vars=None,
fs_class=' default ' )
Returns:
The feature structure that is obtained by replacing any of this
feature structure's variables that are in vars with new
variables. |
source code
|
|
|
_rename_variables(fstruct,
vars,
used_vars,
new_vars,
fs_class,
visited) |
source code
|
|
|
|
FeatStruct
|
|
|
_remove_variables(fstruct,
fs_class,
visited) |
source code
|
|
|
unify(fstruct1,
fstruct2,
bindings=None,
trace=False,
fail=None,
rename_vars=True,
fs_class=' default ' )
Unify fstruct1 with fstruct2 , and return
the resulting feature structure. |
source code
|
|
|
_destructively_unify(fstruct1,
fstruct2,
bindings,
forward,
trace,
fail,
fs_class,
path)
Attempt to unify fstruct1 and fstruct2 by
modifying them in-place. |
source code
|
|
|
_unify_feature_values(fname,
fval1,
fval2,
bindings,
forward,
trace,
fail,
fs_class,
fpath)
Attempt to unify fval1 and and fval2 , and
return the resulting unified value. |
source code
|
|
|
_apply_forwards_to_bindings(forward,
bindings)
Replace any feature structure that has a forward pointer with the
target of its forward pointer (to preserve reentrancy). |
source code
|
|
|
_apply_forwards(fstruct,
forward,
fs_class,
visited)
Replace any feature structure that has a forward pointer with the
target of its forward pointer (to preserve reentrancy). |
source code
|
|
|
_resolve_aliases(bindings)
Replace any bound aliased vars with their binding; and replace any
unbound aliased vars with their representative var. |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list of tuple
|
conflicts(fstruct1,
fstruct2,
trace=0)
Returns:
A list of the feature paths of all features which are assigned
incompatible values by fstruct1 and
fstruct2 . |
source code
|
|
|
|
|
|
|
|
|
_flatten(lst,
cls)
Helper function -- return a copy of list, with all elements of type
cls spliced in rather than appended in. |
source code
|
|
|
|
|
|
|
|