exercise 11 graph databases and path queries
play

Exercise 11: Graph Databases and Path Queries Database Theory - PowerPoint PPT Presentation

Exercise 11: Graph Databases and Path Queries Database Theory 2020-07-06 Maximilian Marx, David Carral 1 / 49 Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we


  1. Exercise 11: Graph Databases and Path Queries Database Theory 2020-07-06 Maximilian Marx, David Carral 1 / 49

  2. Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we encode arbitrary hypergraphs (relational databases) in RDF? RDF can be considered as a synonym for “labelled directed graph” here – the technical details of the RDF standard are not important for this exercise. 2 / 49

  3. Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we encode arbitrary hypergraphs (relational databases) in RDF? RDF can be considered as a synonym for “labelled directed graph” here – the technical details of the RDF standard are not important for this exercise. Solution. 3 / 49

  4. Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we encode arbitrary hypergraphs (relational databases) in RDF? RDF can be considered as a synonym for “labelled directed graph” here – the technical details of the RDF standard are not important for this exercise. Solution. ◮ Let G be some labelled hypergraph. 4 / 49

  5. Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we encode arbitrary hypergraphs (relational databases) in RDF? RDF can be considered as a synonym for “labelled directed graph” here – the technical details of the RDF standard are not important for this exercise. Solution. ◮ Let G be some labelled hypergraph. ◮ We construct G RDF by reifying hyperedges: for every p -labelled hyperedge ϕ = p ( t 1 , t 2 , . . . , t ℓ ) in G , 5 / 49

  6. Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we encode arbitrary hypergraphs (relational databases) in RDF? RDF can be considered as a synonym for “labelled directed graph” here – the technical details of the RDF standard are not important for this exercise. Solution. ◮ Let G be some labelled hypergraph. ◮ We construct G RDF by reifying hyperedges: for every p -labelled hyperedge ϕ = p ( t 1 , t 2 , . . . , t ℓ ) in G , ◮ we add labels p 1 , p 2 , . . . , p ℓ ; 6 / 49

  7. Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we encode arbitrary hypergraphs (relational databases) in RDF? RDF can be considered as a synonym for “labelled directed graph” here – the technical details of the RDF standard are not important for this exercise. Solution. ◮ Let G be some labelled hypergraph. ◮ We construct G RDF by reifying hyperedges: for every p -labelled hyperedge ϕ = p ( t 1 , t 2 , . . . , t ℓ ) in G , ◮ we add labels p 1 , p 2 , . . . , p ℓ ; ◮ a vertex v ϕ ; and 7 / 49

  8. Exercise 1 Exercise. It was explained in the lecture that RDF and Property Graph can encode the same graph structures. How could we encode arbitrary hypergraphs (relational databases) in RDF? RDF can be considered as a synonym for “labelled directed graph” here – the technical details of the RDF standard are not important for this exercise. Solution. ◮ Let G be some labelled hypergraph. ◮ We construct G RDF by reifying hyperedges: for every p -labelled hyperedge ϕ = p ( t 1 , t 2 , . . . , t ℓ ) in G , ◮ we add labels p 1 , p 2 , . . . , p ℓ ; ◮ a vertex v ϕ ; and ◮ edges p 1 ( c ϕ , t 1 ) , p 2 ( c ϕ , t 2 ) , . . . , p ℓ ( c ϕ , t ℓ ) to G RDF . 8 / 49

  9. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 1. The “Same generation” Datalog program from the lecture: S ( x , x ) ← human ( x ) S ( x , y ) ← parent ( x , w ) ∧ S ( v , w ) ∧ parent ( y , v ) 9 / 49

  10. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 1. The “Same generation” Datalog program from the lecture: S ( x , x ) ← human ( x ) S ( x , y ) ← parent ( x , w ) ∧ S ( v , w ) ∧ parent ( y , v ) Solution. 10 / 49

  11. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 1. The “Same generation” Datalog program from the lecture: S ( x , x ) ← human ( x ) S ( x , y ) ← parent ( x , w ) ∧ S ( v , w ) ∧ parent ( y , v ) Solution. ◮ S matches paths of the form parent n ◦ human ◦ parent n , with n ≥ 0. 1. 11 / 49

  12. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 1. The “Same generation” Datalog program from the lecture: S ( x , x ) ← human ( x ) S ( x , y ) ← parent ( x , w ) ∧ S ( v , w ) ∧ parent ( y , v ) Solution. ◮ S matches paths of the form parent n ◦ human ◦ parent n , with n ≥ 0. 1. ◮ This is not a regular language, and hence cannot be expressed as a 2RPQ. 12 / 49

  13. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 1. The “Same generation” Datalog program from the lecture: S ( x , x ) ← human ( x ) S ( x , y ) ← parent ( x , w ) ∧ S ( v , w ) ∧ parent ( y , v ) Solution. ◮ S matches paths of the form parent n ◦ human ◦ parent n , with n ≥ 0. 1. ◮ This is not a regular language, and hence cannot be expressed as a 2RPQ. ◮ Since the length of a matched path is not accessible in a C2RPQ, this can also not be expressed as a C2RPQ. 13 / 49

  14. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 2. Ancestors born in the same city: AncCity ( x , y , x ′ , y ′ ) ← parent ( x , x ′ ) ∧ bornIn ( x , y ) ∧ bornIn ( x ′ , y ′ ) AncCity ( x , y , x ′′ , y ′′ ) ← AncCity ( x , y , x ′ , y ′ ) ∧ AncCity ( x ′ , y ′ , x ′′ , y ′′ ) Query ( x , x ′ , y ) ← AncCity ( x , y , x ′ , y ) Solution. ◮ S matches paths of the form parent n ◦ human ◦ parent n , with n ≥ 0. 1. ◮ This is not a regular language, and hence cannot be expressed as a 2RPQ. ◮ Since the length of a matched path is not accessible in a C2RPQ, this can also not be expressed as a C2RPQ. 2. 14 / 49

  15. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 2. Ancestors born in the same city: AncCity ( x , y , x ′ , y ′ ) ← parent ( x , x ′ ) ∧ bornIn ( x , y ) ∧ bornIn ( x ′ , y ′ ) AncCity ( x , y , x ′′ , y ′′ ) ← AncCity ( x , y , x ′ , y ′ ) ∧ AncCity ( x ′ , y ′ , x ′′ , y ′′ ) Query ( x , x ′ , y ) ← AncCity ( x , y , x ′ , y ) Solution. ◮ S matches paths of the form parent n ◦ human ◦ parent n , with n ≥ 0. 1. ◮ This is not a regular language, and hence cannot be expressed as a 2RPQ. ◮ Since the length of a matched path is not accessible in a C2RPQ, this can also not be expressed as a C2RPQ. 2. The following C2RPQ expresses Query: ( parent ◦ parent ∗ )( x , x ′ ) ∧ bornIn ( x , y ) ∧ bornIn ( x ′ , y ) 15 / 49

  16. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 3. Ancestors of Dresden-based family lines: DDAnc ( x , y ) ← parent ( x , y ) ∧ bornIn ( x , dresden ) ∧ bornIn ( y , dresden ) DDAnc ( x , z ) ← DDAnc ( x , y ) ∧ parent ( y , z ) ∧ bornIn ( z , dresden ) Solution. ◮ S matches paths of the form parent n ◦ human ◦ parent n , with n ≥ 0. 1. ◮ This is not a regular language, and hence cannot be expressed as a 2RPQ. ◮ Since the length of a matched path is not accessible in a C2RPQ, this can also not be expressed as a C2RPQ. 2. The following C2RPQ expresses Query: ( parent ◦ parent ∗ )( x , x ′ ) ∧ bornIn ( x , y ) ∧ bornIn ( x ′ , y ) 3. 16 / 49

  17. Exercise 2. Exercise. Can the following Datalog programs be encoded using a C2RPQ? In each case, give a suitable C2RPQ or explain why there is none. 3. Ancestors of Dresden-based family lines: DDAnc ( x , y ) ← parent ( x , y ) ∧ bornIn ( x , dresden ) ∧ bornIn ( y , dresden ) DDAnc ( x , z ) ← DDAnc ( x , y ) ∧ parent ( y , z ) ∧ bornIn ( z , dresden ) Solution. ◮ S matches paths of the form parent n ◦ human ◦ parent n , with n ≥ 0. 1. ◮ This is not a regular language, and hence cannot be expressed as a 2RPQ. ◮ Since the length of a matched path is not accessible in a C2RPQ, this can also not be expressed as a C2RPQ. 2. The following C2RPQ expresses Query: ( parent ◦ parent ∗ )( x , x ′ ) ∧ bornIn ( x , y ) ∧ bornIn ( x ′ , y ) 3. ◮ DDAnc matches paths where every node has a bornIn-connection to dresden. 17 / 49

Recommend


More recommend