nltk.featstruct.unify¶
- nltk.featstruct.unify(fstruct1, fstruct2, bindings=None, trace=False, fail=None, rename_vars=True, fs_class='default')[source]¶
Unify
fstruct1withfstruct2, and return the resulting feature structure. This unified feature structure is the minimal feature structure that contains all feature value assignments from bothfstruct1andfstruct2, and that preserves all reentrancies.If no such feature structure exists (because
fstruct1andfstruct2specify incompatible values for some feature), then unification fails, andunifyreturns None.Bound variables are replaced by their values. Aliased variables are replaced by their representative variable (if unbound) or the value of their representative variable (if bound). I.e., if variable v is in
bindings, then v is replaced bybindings[v]. This will be repeated until the variable is replaced by an unbound variable or a non-variable value.Unbound variables are bound when they are unified with values; and aliased when they are unified with variables. I.e., if variable v is not in
bindings, and is unified with a variable or value x, thenbindings[v]is set to x.If
bindingsis unspecified, then all variables are assumed to be unbound. I.e.,bindingsdefaults to an empty dict.>>> from nltk.featstruct import FeatStruct >>> FeatStruct('[a=?x]').unify(FeatStruct('[b=?x]')) [a=?x, b=?x2]
- Parameters
bindings (dict(Variable -> any)) – A set of variable bindings to be used and updated during unification.
trace (bool) – If true, generate trace output.
rename_vars (bool) – If True, then rename any variables in
fstruct2that are also used infstruct1, in order to avoid collisions on variable names.