Docsity

XML Querying Exercise: Querying bib.xml and dblp.xml using XQuery, Assignments of Principles of Database Management

Toggle sidebar
bg1
CMPSCI 645 -- Homework 5
Due May 5, before class
Question 1. Querying XML documents [50 points]
In this exercise, you will write queries over an XML data set using the XQuery language. You
will execute your queries using the open-source Saxon system, which we have installed in the
class directory space on the EdLab machines:
/courses/cs400/cs445/cs445/saxon
In order to run Saxon to produce query results, take the following steps:
(i) Ba sic s etup
Go to your home directory, and set your $PATH and $CLASSPATH variables as follows:
elnux4>bash
bash$ export PATH=/exp/rcf/edlab/jdk1.5.0_01/bin/:$PATH
bash$ export CLASSPATH=/courses/cs400/cs445/cs445/saxon/saxon9.jar:
$CLASSPATH
bash$ export CLASSPATH=/courses/cs400/cs445/cs445/saxon/:$CLASSPATH
(ii) Data fi l es
The XML document “bib.xml” is placed on edlab machines under the following path:
/usr/net/ftp/pub/cs645/s2009/hw5
The DTD of this file, “bib.dtd”, is available in the same directory as the document. The DTD can
be very helpful to you in understanding the structure of the document and formulating your
queries. A visualized presentation of the dtd is provided in the subdirectory “livedtd-
bib/index.html”. You can navigate through the hyperlinks to familiarize yourself with the
elements and attributes in this DTD.
The second XML document “dblp-sigmod.xml,” its DTD “dblp.dtd,” and its visualized
presentation “livedtd-dblp” are available in the same directory.
Make a subdirectory “hw5” in your 645 directory. Copy both the XML documents and the DTDs
to the “hw5” subdirectory.
(iii) Q uer y fi l es
For each question below, compose an XQuery query. Use the doc() function in your query to
address the XML document. For example, the following query retrieves all book elements from
the “bib.xml” file.
doc(“bib.xml”)/bib/book
Store each query in a separate file. Follow the naming convention of Qi. xq for the ith query, e.g.,
“Q1.xq” for the first query, “Q2. xq” for the second, and so on.
pf3
pf4
pf5

Partial preview of the text

Download XML Querying Exercise: Querying bib.xml and dblp.xml using XQuery and more Assignments Principles of Database Management in PDF only on Docsity!

CMPSCI 645 -- Homework 5

Due May 5, before class

Question 1. Querying XML documents [50 points]

In this exercise, you will write queries over an XML data set using the XQuery language. You will execute your queries using the open-source Saxon system, which we have installed in the class directory space on the EdLab machines: /courses/cs400/cs445/cs445/saxon In order to run Saxon to produce query results, take the following steps: ( i ) Basic setup Go to your home directory, and set your $PATH and $CLASSPATH variables as follows: elnux4>bash bash$ export PATH=/exp/rcf/edlab/jdk1.5.0_01/bin/:$PATH bash$ export CLASSPATH=/courses/cs400/cs445/cs445/saxon/saxon9.jar: $CLASSPATH bash$ export CLASSPATH=/courses/cs400/cs445/cs445/saxon/:$CLASSPATH ( ii ) Data files The XML document “bib.xml” is placed on edlab machines under the following path: /usr/net/ftp/pub/cs645/s2009/hw The DTD of this file, “bib.dtd”, is available in the same directory as the document. The DTD can be very helpful to you in understanding the structure of the document and formulating your queries. A visualized presentation of the dtd is provided in the subdirectory “livedtd- bib/index.html”. You can navigate through the hyperlinks to familiarize yourself with the elements and attributes in this DTD. The second XML document “dblp-sigmod.xml,” its DTD “dblp.dtd,” and its visualized presentation “livedtd-dblp” are available in the same directory. Make a subdirectory “hw5” in your 645 directory. Copy both the XML documents and the DTDs to the “hw5” subdirectory. ( iii ) Query files For each question below, compose an XQuery query. Use the doc() function in your query to address the XML document. For example, the following query retrieves all book elements from the “bib.xml” file. doc(“bib.xml”)/bib/book Store each query in a separate file. Follow the naming convention of Qi.xq for the ith^ query, e.g., “Q1.xq” for the first query, “Q2.xq” for the second, and so on.

( iv ) Qu ery execution After a query is composed, run it using the following command: bash$ java net.sf.saxon.Query Q1.xq In this assignment, you are asked to store the result of each query in a separate file. To do so, type: bash$ java net.sf.saxon.Query Q1.xq > Q1.res ( v ) Submission After you finish this exercise, you should have the following files (Qi.xq, Qi.res), i = 1, 2, …, 8 in your “645/hw5” directory. We will evaluate your solution to this exercise directly from your “hw5” directory on the edlab machines. Note that you can setup Saxon on your own machine and try some queries there. But, make sure to generate the final query results on the EdLab machines, as Unix and Windows use different formats for text files. Q u eries over bib.xml The first XML data set you will be running queries over is a bibliography file. The DTD of this file, “bib.dtd”, is available in the same directory as the data. The DTD can be tremendously helpful to you in understanding the structure of the data and formulating your queries. A visualized presentation of the dtd is also provided in the data directory under the path “livedtd- bib/index.html”. You can navigate through the hyperlinks to familiarize yourself with the elements and attributes in this DTD.

  1. List books that were published after 1991 and cost less than $100. The output should look like: < book …>… < book …>… …
  2. List books that were published after 1991 and cost less than $100, including their year, title, and price. The output format should be: < cheap-book year="…"> < title >… < price >… </cheap-book> < cheap-book year="…"> < title >… < price >… </cheap-book> …
  3. Find books in which the name of some author contains the string "Stev". For each such book, return the title and the qualifying author.

Q u eries over dblp.xml The second XML data set is a DBLP file containing all the publications of ACM SIGMOD up to year 2000. The DTD of this file, “dblp.dtd”, is available in the same directory as the data. The dtd can also be visualized using “livedtd-dblp/index.html”. This DTD is more complex than the previous one. You may want to browse the DTD and the data file at the same time to get familiar with the elements and attributes used in the data. The dblp DTD uses entity declarations to define a set of element names that are used in multiple places in the DTD. Among the commonly used elements, the “proceedings” elements define the proceedings while the “inproceedings” elements refer to the papers included in the proceedings. Each inproceedings element contains a key attribute that uniquely identifies the paper across all SIGMOD publications. An inproceedings element can contain multiple “cite” elements, each referring to another inproceedings element by including in its text content the key value of the referenced element.

  1. Retrieve those inproceedings elements that are referenced more than 20 times and return them in descending order of the reference count. For each returned element, create a new element “paper” to contain the title, author(s), year, and reference count. The output format should be: < most-cited > < paper > < title >… < author >… < author >… … < year >… < reference-count >…</reference-count> … </most-cited>
  2. Return those authors that have more than 20 papers (i.e., inproceedings elements) in descending order of the paper count. For each qualifying author, create a new element “researcher” to contain his/her name, the paper count, and a list of papers in ascending order of the year of publication; each paper in the list has a “year” attribute and its text content is the paper title. The output format should be: < most-productive > < researcher > < name >… < paper-count >…</paper-count> < paper year =”…”> title goes here < paper year =”…”> title goes here … … </most-productive>
  1. Return those researchers who have co-authored papers with more than 20 people. List those researchers in descending order of the co-author count. For each of them, create a new element “researcher” to contain her name, the co-author count, and the list of co-authors sorted by their names (in ascending order). The output format should be: < most-collaborative > < researcher > < name > string value < count >… < co-author > string value </co-author> < co-author > string value </co-author> … … </most-collaborative>

Question 2. Aggregation over Data Streams [50 points]

The purpose of this programming exercise is to give you some experience of working

with a stream of data. The task is to evaluate aggregate operators on a stream of positive

integers, which are temperature readings collected from sensor nodes over years.

Typically this stream can be an infinite live stream. In this exercise, you are asked to

evaluate max and avg operators over sliding windows.

Input: A stream of numbers, window size W, window slide size K.

Output: Max and avg values over each window as the windows slides.

Focus: Optimize memory usage and processing time. This is the main focus of the

exercise. A naïve method that always scans every single element in a window would not

be considered as a satisfactory solution.

Source data file : The source data can be downloaded from the following path on Edlab:

/usr/net/ftp/pub/cs645/s2009/hw5/real_temperature200.txt

There are also smaller data sets in this directory. Feel free to use them when you are

debugging and testing your program. But we expect your program to finally run on the

above data set.

Java Program : You are given TestDriver.java which tests your code. The runtime

parameters are the following:

  • Window size,
  • Window slide size, //you can assume that window size is multiple of slide size.
  • Which aggregate operator, max or avg, to evaluate
  • A flag that controls the output (which is used in the code given to you).

stream_engine.Execute(); … }

Evaluation : We will evaluate your implementation in two ways. First, the program

should return correct output. Second, the program should be reasonably memory and time

efficient.

Submission. After you finish this exercise, please also leave your Java files in your “645/hw5” directory.