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

COMPSCI 752

Big data management

Assignment 1 / Semester 1, 2023

Semi-structured Data Modelling and Access

Model Answers

Application domain. Consider the tree in Figure 1. Element nodes are labelled by E. The tag of a node is either c or d. The context node for Question 1(b) is marked in pink.

Fig. 1. XML Tree for Question 1

1. XPath.

(a) For each node of the tree, write down the corresponding pre- and post-identifier. [5 marks]

Solution:

(b) With respect to the given context node, marked in pink, evaluate the following axes on the tree. List the pre-identifier of each node that each axis returns.

i. preceding::d

ii. descendant-or-self::c

iii. following-sibling::*                                                                            [5 marks]

Solution:

i. nodes 2, 4, 5, 7, 8

ii. nodes 10, 13

iii. no node

(c) Convert each of the following queries into the corresponding XPath expression, and evaluate it on the tree by listing the pre-identifier of the nodes returned.

i. Return the first of the c-element nodes that are children of the second of the d-element nodes that are children of some element node.

Solution:

//d[2]/c[1] or //*/d[2]/c[1]

node 10

ii. Return every element node whose number of ancestor-nodes is the same as its number of descendant-nodes.

Solution:

//*[count(ancestor::*)=count(descendant::*)]

nodes 3, 6, 10, 13

iii. Return every node that has only leaves as children.                               [5 marks]

Solution:

//*[*[count(*)=0]]

nodes 3, 6, 10, 13

Application domain. For Question 2, consider the following XML document.

< artist name= ‘ ‘ Vinnie Van Voov”>

Impression

2000

10

37

< artist name= ‘ ‘ Henri Heroic”>

Expression

900

9

85

< artist name= ‘ ‘ Pic ante Public”>

Expression

50000

10

92

2. XQuery.

Write down the following English language queries in XQuery, and show the result of evaluating the XQuery query on the given XML document.

(a) For each distinct period p, for which no artist in that period p has a rating lower than 10, return an element node that lists the period and, for each artist of that period, an attribute child artist that lists the name of the artist. [5 marks]

Solution:

for   $p   in   distinct −values ( / / period )

where  every   $ r   in   // artist [ period=$p ] / rating   satisfies   ( $r >=10) return

{ for   $a   in   // artist [ period=$p ]

return  {$a /@name}}

< artist name=”Vinnie Van Voov”/>

(b) For each pair of artists, where each of the two artists has produced at least  1000 pieces, return an element node pair with two element children artist that contain the name of the artist as a string, respectively. For full marks, a pair cannot contain the same artist twice, and there must not be any pairs where the order of the artists is simply swapped.                                                                                           [5 marks]

Solution:

for   $a1   in   // artist

for   $a2  in   // artist [ preceding −sibling : : artist=$a1 ]

where   $a1 / pieces   >=1000  and  $a2 / pieces   >=1000

return

{ string ( $a1 /@name)}

{ string ( $a2 /@name)}

Vinnie  Van  Voov

Pic ante  Public 

(c) For every distinct rating, return an element node rating with an attribute child called value that lists the rating and an element child average age that contains the average age of artists with that rating.  [5 marks]

Solution:

for   $ r   in   distinct −values ( / / rating )

let   $c := avg ( / / artist [ rating=$ r ] / age )

return

age >{$c} age >

age >64.5 age >

age >85 age >