Document Sample

Midterm Fall 2000 solutions Question 1 • From sentence to class dictionary abstraction • In this case like from object graph to class graph abstraction because in XML the sentences look like object graphs. • sentences: – <xyz:PurchaseOrder> – <PurchaseOrder> • Need an optional part Question 1 • sentences: – <xyz:PurchaseOrder> – <PurchaseOrder> • Class dictionary: – “<“ [<first> ObjectId “:”] “PurchaseOrder>” … – ObjectId = Ident. – “<“ [“xyz:”] “PurchaseOrder>” … does not work because absent part not represented in object. Question 1 • sentence: – <CustomerName> “Henry Ford” </CustomerName> • class dictionary: – “<CustomerName>” String “</CustomerName>” Question 1 • sentence: Price is optional in <Order> class dictionary: <Product> “Apple” </Product> Order = “<Order>” <Price> 1.50 </Price> Product <Order> [Price] “</Order>”. <Order> <Product> “Peach” </Product> // no Price <Order> Question 2: • Where should we stop the traversal? • Where can we find out whether an order has a price? At an Order-object. • The traversal strategy: • from PurchaseOrders to Order Question 2: • Would the following traversal strategy work? – from PurchaseOrders to * • Yes, but it would be inefficient. • We should not traverse beyond Order-objects because visitor will not be interested in any of those objects. Only before method of visitor will be at Order. Rule to follow Traverse only to please the visitors and not just for fun. Question 3 • Meaning of strategies Strategy: From C1 to T o1:C1 o2:C2 declared type of o2 is C3=>C2 e go down e iff C1 <=.C C3 (=> C2 (<=.C.=>)*.<=) T go down e iff C1 EI* EC C3 (EA* C2 (EI* EC EA*)* EI*) T if flat: go down e iff C1 EC C3 (EA* C2 (EC EA*)* EI*) T if flat and single inheritance: go down e iff C1 EC C3 (EA* C2 (EC EA*)* EI*) T go down e iff C1 <=.C C3 (=>.<=.C.=>)*.<=) T strategy: {A -> B Object graph Example 1 B -> C} Strategy s t :A A B C x1:X class graph e1:Empty S :R R A x2:X Empty B x x c c1:C b X c2:C BOpt c c3:C C So far: Remarks about traversals • Traversals are opportunistic: As long as there is a possibility for success (i.e., getting to the target), the branch is taken. • Traversals do not look ahead. Visitors must delay action appropriately. A simple view of traversals • When a traversal reaches a target node in the object graph, the path traversed from the source, with suitable substitution of subclasses by superclasses, must be an expansion of an s-t path in the strategy graph. s is the source and t is the target of the strategy. Special case • strategy: {A -> B B -> C} • class graph: A : B. B : C. C = . • object graph: C • Follow rule: each edge in the strategy graph corresponds to at least one edge in the object graph. A simple view of traversals • When a traversal reaches a final node in the object graph without being at a target, the path traversed from the source, with suitable substitution of subclasses by superclasses, must be a prefix of an expansion of an s-t path in the strategy graph. The prefix is the longest prefix such that there is still a possibility of success as determined by the class graph. Assume class graph is flat: subclass and construction edges only. Definition • POSS(Class c1, Class t, Object o1) = those edges e outgoing from o1 s.t. there is an object graph O (consistent with the class graph C), containing the object o1 of class c1, an object o2 of a class that is a subclass of t, and a path in O from o1 to o2 such that the first edge in the path is e. • POSS: possibility of success Back to the Class Graph • POSS(Class c1, Class t) = – { c3 | c1 <=.C c3 (=>.(<=C=>)*.<=) t} • POSS: possibility of success A1 (=>.(<=C=>)*.<=) E2 c1 B2 D1 E2 A1 B1 D2 E1 A2 K2 K1 A1 (=>.(<=C=>)*.<=) E2 single inheritance E2 A1 c1 A2 E1 K2 K1 A1 (=>.(<=C=>)*.<=) E2 single inheritance flat E2 A1 c1 A2 E1 K2 K1 Definition: Class Graph • A class graph is a directed graph with a partial order on the nodes. We write c1 -> c2 for the edges (construction edges) and c1 <= c2 for the order (inheritance edges -- c1 is a subclass of c2). • We write => for the inverse of <= Relations • We think of directed graphs as relations. • Write C(c1,c2) or c1 C c2 for edge from c1 to c2 in C. • Composition of relations by . E.g., x (R.S) z iff there is a y such that xRy and ySz. • R* is the reflective transitive closure of a relation R. Object Graph Slice • The object graph slice starting with o1 is the slice built by following the edges POSS(Class(o1), t, o1) starting at o1 and continuing until every path terminates (at an object of type t or it terminates prematurely). class dictionary A = [“x” X] [“r” R]. strategy B = [“b” B] D. R = S. A -> T S = [“t” T] C Example T -> D C = D. X = B. 0..1 T = R. D = . 0..1 X B A D C 0..1 :C :D R S T :A class 0..1 object graph :R :S graph “r” class dictionary A = [“x” X] [“r” R]. strategy B = [“b” B] D. R = S. A -> T S = [“t” T] C Example T -> D C = D. X = B. POSS(A,T,a1) = 1 edge 0..1 T = R. POSS(R,T,r1) = 1 edge D = . 0..1 X B POSS(S,T,s1) = 0 edges before visitor A D C 0..1 object graph slice :C :D R S T a1:A class 0..1 object graph r1:R s1:S graph “r” answer: R S POSS(A,T,a1) = 1 edge strategy POSS(R,T,r1) = 1 edge A -> T POSS(S,T,s1) = 1 edge POSS(T,D,t1) = 1 edge Example T -> D POSS(R,D,r2) = 1 edge a1:A 0..1 :D 0..1 r1:R X B c1:C before visitor s1:S A D C t1:T s2:S 0..1 object graph “r t” r2:R R S T 0..1 c2:C class answer: R S T R S C d2:D graph POSS(A,T,a1) = 0 edges not needed for answer strategy A -> T Example T -> D a1:A 0..1 0..1 x:X X B b1:B A D C b2:B 0..1 d1:D R S T 0..1 d2:D class object graph “x b” graph class dictionary A = [“x” X] [“r” R]. equivalent strategies B = [“b” B] D. A -> T bypassing T R = S. S = [“t” T] C Example from A to-stop T C = D. X = B. POSS(A,T,a1) = 1 edge 0..1 T = R. POSS(R,T,r1) = 1 edge D = . 0..1 X B POSS(S,T,s1) = 0 edges before visitor A D C 0..1 object graph slice :C :D R S T a1:A class 0..1 object graph r1:R s1:S graph “r” answer: R S POSS(A,T,a1) = 1 edge equivalent strategies POSS(R,T,r1) = 1 edge A -> T bypassing T POSS(S,T,s1) = 1 edge POSS(T,T,t1) = 0 edges Example from A to-stop T a1:A 0..1 :D 0..1 r1:R X B c1:C s1:S A D C t1:T s2:S 0..1 object graph “r t” r2:R R S T 0..1 c2:C answer: R S T class d2:D graph class dictionary A = [“x” X] [“r” R]. strategy B = [“b” B] D. R = S. A -> B S = [“t” T] C Example B -> D C = D. A -> C X = B. C -> D 0..1 T = R. D = . 0..1 X B A D C 0..1 Path set regular expression ARS(TRS)*CD| R S T 0..1 AXBB*D = class A(RS(TRS)*CD|XBB*D) graph From Regular Expression to Class Dictionary Path set regular expression A(RS(TRS)*CD|XBB*D) RegExp = A E1. E1 : E2 | E3. E2 = R S List(E4) C D. E3 = X B List(B) D. E4 = T R S. List(S) ~ {S}. A = “A”. R = “R”. S = “S”. T = “T”. etc. Strategy: From C1 to T o1:C1 o2:C2 declared type of o2 is C3=>C2 e go down e iff C1 <=.C C3 =>.(<=.C.=>)*.<=) T z Strategy x X1 Y1 Z1 S -> T y S X2 Y2 Z2 T t X3 Y3 Z3 x y z t s1:S x31:X3 y31:Y3 z31:Z3 t1:T go down e iff S <=.C C3 =>.(<=.C.=>)*.<=) T z Strategy x X1 Y1 Z1 S -> T y S X2 Y2 Z2 T t X3 Y3 Z3 x y z t s1:S x31:X3 y31:Y3 z31:Z3 t1:T go down e iff S <=.C X1 =>.(<=.C.=>)*.<=) T z Strategy x X1 Y1 Z1 S -> T y S X2 Y2 Z2 T t X3 Y3 Z3 x y z t s1:S x31:X3 y31:Y3 z31:Z3 t1:T <=,=> go down e iff S <=.C X1 =>.(<=.C.=><=.C.=><=.C=>).<=) T not used

DOCUMENT INFO

Shared By:

Categories:

Tags:

Stats:

views: | 21 |

posted: | 9/22/2012 |

language: | English |

pages: | 35 |

OTHER DOCS BY ajizai

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.