Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMPSCI 752

Big data management

Assignment 2 / Semester 1, 2023

Graph Databases

Model Answers

Graph databases

Consider a simple application where direct ights between two cities are stored as a property graph. Nodes and edges may have properties.

  

Fig. 1. Property Graph

Questions:

1. Write down the formal property graph model  (V, E, n, A, u) for the property graph in Figure 1.                         [6 marks]

Solution:

 V = {1, 2, 3}

 E = {10, 11}

 n:

. 10 →l (1, 2), 11 →l (2, 3)

 A:

. 1 → {city}, 2 → {city}, 3 → {city},

. 10 → {flight}, 11 → {flight}

 u:

. (1, name) → “Papeete”, (1, country) → “France”

. (2, name) → “Los Angeles”, (2, country) → “USA”,

. (3, name) → “Paris”, (3, country) → “France”,

. (10, airline) → “Air Tahiti”, (10, no) → “TN 8”,

. (11, airline) → “Air Tahiti”, (11, no) → “TN 8”,

2. Write the following English language query in regular property graph logic

Return all city nodes that can be reached from the city of Papeete with a sequence of connecting ights with at most two stop-overs.                                                    [4 marks]

Solution:

result(3) - :flight(y, 3), y.name = “Papeete”

result(3) - :flight(y, z1), :flight(z1, 3), y.name = “Papeete”

result(3) - :flight(y, z1), :flight(z1, z2), :flight(z2, 3), y.name = “Papeete”

3. Write the following English language query in regular property graph logic

Return all city nodes that can be reached from the city of Papeete with a sequence of connecting ights that have an unlimited number of stop-overs.                        [4 marks]

Solution:

result(·) - :flight(y, 3), :flight* (3, ·), y.name = “Papeete”

4. Write the following English language query in regular property graph logic

Return all city nodes in France, with a name different from Papeete, that can be reached from the city of Papeete with a sequence of connecting ights that have an unlimited number of stop-overs, where each ight is international and operated by the airline Air Tahiti” .                                   [4 marks]

Solution:

reach(3, ·) - :flight(3, ·) as k, k .airline = “Air Tahiti”, 3 .country  · .country

result(·) - :reach(y, 3), :reach* (3, ·), y.name = “Papeete” ,

· .country = “France” , · .name  Papeete”

5. Write down the queries from Questions 2., 3., and 4. in regular property graph algebra.

Solution:

(b)

Bat(0)rg1  (Ba (:flight)n Ba (:flight, :flight)n Ba (:flight, :flight, :flight))

② 1  : src1.name = “Papeete”

②2  : ② 1 A trg1 = src2

②3  : ②2 A trg2 = src3

(c)

Bas(0)rc1  Batr(②)g2 ,trg2  (:flight, :flight* )

② : src1.name = “Papeete” A trg1 = src2

(d)

Bas(0)rc1  Batr(v)g2 ,trg2  flight, Bascr1(②) ,trg1  (:flight)、*、、

② : edge.airline = “Air Tahiti”A src1.country  trg1.country

w : src1.name = “Papeete” A trg1 = src2A

edge1.airline = “Air Tahiti” A src1.country  trg1.countryA trg2.country = “France” A trg2.name  Papeete”

[12 marks]