Merging information from two feature structures is called unification and is supported by the unify() method.
>>> fs1 = nltk.FeatStruct(NUMBER=74, STREET='rue Pascal') >>> fs2 = nltk.FeatStruct(ciTY='Paris') >>> print fs1.unify(fs2) [ CITY = 'Paris' ]
Unification is formally defined as a binary operation: FSo U FS1. Unification is symmetric, so FSo U FS1 = FS1 U FSo. The same is true in Python:
>>> print fs2.unify(fsl) [ CITY = 'Paris' ]
If we unify two feature structures that stand in the subsumption relationship, then the result of unification is the most specific of the two:
For example, the result of unifying (25b) with (25c) is (25c).
Unification between FSo and FS1 will fail if the two feature structures share a path n where the value of n in FSo is a distinct atom from the value of n in FS1. This is implemented by setting the result of unification to be None.
>>> fso = nltk.FeatStruct(A='a') >>> fs1 = nltk.FeatStruct(A='b') >>> fs2 = fso.unify(fsl) >>> print fs2 None
Now, if we look at how unification interacts with structure-sharing, things become really interesting. First, let's define (23) in Python:
STREET='rue Pascal'], SPOUSE= [NAME=Kim,
What happens when we augment Kim's address with a specification for CITY? Notice that fs1 needs to include the whole path from the root of the feature structure down to CITY.
>>> fs1 = nltk.FeatStruct("[SPOUSE = [ADDRESS = [CITY >>> print fsl.unify(fso)
By contrast, the result is very different if fsl is unified with the structure sharing version fs2 (also shown earlier as the graph (24)):
>>> fs2 = nltk.FeatStruct( [NAME=Lee, ADDRESS=(l)[NUMBER=74, STREET='rue Pascal'],
>>> print fsl.unify(fs2) [ [ CITY = 'Paris' ] ]
Rather than just updating what was in effect Kim's "copy" of Lee's address, we have now updated both their addresses at the same time. More generally, if a unification involves specializing the value of some path n, that unification simultaneously specializes the value of any path that is equivalent to n.
As we have already seen, structure sharing can also be stated using variables such as ?x.
>>> fsl = nltk.FeatStruct("[ADDRESSl=[NUMBER=74, STREET='rue Pascal']]")
>>> fs2 = nltk.FeatStruct("[ADDRESSl=?x, ADDRESS2=?x]")
Was this article helpful?