120 likes | 402 Views
Unification algorithm. We have seen examples of the use of unification. Now we will see, in detail, one way to implement a unification algorithm which implements structure sharing. A data structure to support unification.
E N D
Unification algorithm • We have seen examples of the use of unification. • Now we will see, in detail, one way to implement a unification algorithm which implements structure sharing
A data structure to support unification • We need a special data structure to allow structure sharing during unification: • each feature structure is represented using two components, a content component and a pointer component. • the representation forms a Directed Acyclic Graph (DAG)
CONTENT POINTER Example 1 • The DAG representation for a simple feature structure: [Number SG, Person 3] • Expand first to: [Content [Number [Content SG, Pointer NULL], Person [Content 3, Pointer NULL]], Pointer NULL] SG CONTENT NULL NUMBER POINTER PERSON CONTENT 3 POINTER NULL NULL
CONTENT POINTER Example 2 • The DAG representation for a simple feature structure: [Number SG] SG CONTENT NULL NUMBER POINTER NULL
CONTENT POINTER Example 3 • The DAG representation for a simple feature structure: [Person 3] 3 CONTENT NULL PERSON POINTER NULL
Algorithm (pg. 423 of text) function Unify(f1, f2) returns fs or failure f1.real real contents of f1, *(f1.ptr) if ptr != null f2.real real contents of f2, *(f2.ptr) if ptr != null if (f1.real is null) { f1.ptr f2; return f2 } else if (f2.real is null) { f2.ptr f1; return f1 } else if (f1.real == f2.real) {f1.ptr f2; return f2 } else if (f1.real is complex and f2.real is complex) { f2.ptr f1 foreach ftr2 in f2.real { ftr1 find/create feature ftr2 in f1.real if Unify(ftr2.value,ftr1.value) fails {return failure} return f1 else return failure
CONTENT CONTENT POINTER POINTER Example 4, initial state • [Number SG] [Person 3] SG CONTENT NULL NUMBER POINTER f1: NULL CONTENT 3 PERSON POINTER NULL f2: NULL
Example 4, part 2 • [Number SG] [Person 3] (note sharing!) SG CONTENT NULL NUMBER POINTER CONTENT POINTER NULL CONTENT 3 PERSON POINTER POINTER NULL CONTENT
Example 4, part 3 • [Number SG] [Person 3] (note sharing!) SG CONTENT NULL NUMBER POINTER CONTENT PERSON CONTENT NULL POINTER POINTER NULL CONTENT 3 PERSON POINTER POINTER NULL CONTENT
Another example? • We can work through example on page 424 of text if you’d like.