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: <Order>
<Product> “Apple” </Product>
<Price> 1.50 </Price>
<Order>
<Order>
<Product> “Peach” </Product>
// no Price
<Order>
Price is optional inclass dictionary:Order = “<Order>” Product [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.
Strategy: From C1 to T
o1:C1 o2:C2e
go down e iff C1 <=.C C3 (=> C2 (<=.C.=>)*.<=) Tgo down e iff C1 EI* EC C3 (EA* C2 (EI* EC EA*)* EI*) Tif flat:go down e iff C1 EC C3 (EA* C2 (EC EA*)* EI*) Tif flat and single inheritance:go down e iff C1 EC C3 (EA* C2 (EC EA*)* EI*) T
declared type of o2 is C3=>C2
Example 1strategy:{A -> B B -> C}
A
B
C
X
xx
b
c
class graph
A B C
Strategy s t
c
BOpt
Empty
Object graph
:A
c2:C
x1:X
:R
x2:X
c1:C
c3:C
e1:Empty SR
go down e iff C1 <=.C C3 (=>.<=.C.=>)*.<=) T
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
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).
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A -> TT -> D
A = [“x” X] [“r” R].B = [“b” B] D.R = S.S = [“t” T] CC = D.X = B.T = R.D = .
:A
:R :S
:C :D
classgraph
strategyclass dictionary
object graph “r”
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A -> TT -> D
A = [“x” X] [“r” R].B = [“b” B] D.R = S.S = [“t” T] CC = D.X = B.T = R.D = .
a1:A
r1:R s1:S
:C :D
classgraph
strategyclass dictionary
object graph “r”
POSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 0 edges
answer: R S
before visitor
object graph slice
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A -> TT -> D
a1:A
r1:R
s1:Sc1:C
:D
classgraph
strategyPOSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 1 edgePOSS(T,D,t1) = 1 edgePOSS(R,D,r2) = 1 edge
t1:T
r2:R
c2:C
d2:D
s2:S
answer: R S T R S C
object graph “r t”
before visitor
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A -> TT -> D
a1:A
x:X
b1:B
classgraph
strategyPOSS(A,T,a1) = 0 edges
b2:B
d1:D
d2:D
object graph “x b”
not needed for answer
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A = [“x” X] [“r” R].B = [“b” B] D.R = S.S = [“t” T] CC = D.X = B.T = R.D = .
a1:A
r1:R s1:S
:C :D
classgraph
class dictionary
object graph “r”
POSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 0 edges
answer: R S
before visitor
object graph slice
equivalent strategies
A -> T bypassing Tfrom A to-stop T
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
a1:A
r1:R
s1:Sc1:C
:D
classgraph
equivalent strategiesPOSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 1 edgePOSS(T,T,t1) = 0 edges
t1:T
r2:R
c2:C
d2:D
s2:S
answer: R S T
object graph “r t”
A -> T bypassing Tfrom A to-stop T
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A -> BB -> DA -> CC -> D
A = [“x” X] [“r” R].B = [“b” B] D.R = S.S = [“t” T] CC = D.X = B.T = R.D = .
classgraph
strategyclass dictionary
Path set regular expressionARS(TRS)*CD|AXBB*D =A(RS(TRS)*CD|XBB*D)
From Regular Expression toClass Dictionary
Path set regular expressionA(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:C2e
go down e iff C1 <=.C C3 =>.(<=.C.=>)*.<=) T
declared type of o2 is C3=>C2
X2
X1
X3
S Y2
Y1
Y3
Z2
Z1
Z3
T
x
y
z
t
x31:X3 y31:Y3 z31:Z3 t1:Ts1:Sx y z t
go down e iff S <=.C C3 =>.(<=.C.=>)*.<=) T
StrategyS -> T
X2
X1
X3
S Y2
Y1
Y3
Z2
Z1
Z3
T
x
y
z
t
x31:X3 y31:Y3 z31:Z3 t1:Ts1:Sx y z t
go down e iff S <=.C X1 =>.(<=.C.=>)*.<=) T
StrategyS -> T
Top Related