#!/bin/csh

# CSC 468
# Winter 2009
# Project Stage 3

# Test: queries from Lab 5.

#
#  please edit the lines of the script to make sure that your program will run
#
#  e.g., replace java XpathPlus with  java -cp .:neustore.jar  

#1. Food.Q1: Find all restaurant names
echo "document(\"Food\")/child::restaurant/child::name"
java XpathPlus RETURN document("Food")/child::restaurant/child::name


#2. Food. Q2: Find all dishes that cost exactly 2.99
echo "document(\"Food\")/descendant::item[descendant::price[text() ="2.99"]]/child::name"
java XpathPlus RETURN document("Food")/descendant::item[descendant::price[text() ="2.99"]]/child::name

#3. Food. Q3: Find all prices of "Hamburger"
echo "document(\"Food\")/descendant::item/child::name[text()=\"Hamburger\"]/following-sibling::price"
java XpathPlus RETURN document("Food")/descendant::item/child::name[text()="Hamburger"]/following-sibling::price

#4. Food Q4.(modified) Find all restaurants that sell a dish with the name "Hamburger"
echo "document(\"Food\")/descendant::item/child::name[text()="Hamburger"]/ancestor::restaurant/child::name"
java XpathPlus RETURN document("Food")/descendant::item/child::name[text()="Hamburger"]/ancestor::restaurant/child::name

#5. Food Q5. (modified) Find all breakfast items from Louisa's place that cost exactly 6.50
echo "document(\"Food\")/child::restaurant[child::name[text()=\"Louisa's Place\"]]/descendant::group[child::name[text()=\"Breakfast\"]]/child::item[child::price[text()="6.50"]]/child::name"
java XpathPlus RETURN document("Food")/child::restaurant[child::name[text()="Louisa's Place"]]/descendant::group[child::name[text()="Breakfast"]]/child::item[child::price[text()="6.50"]]/child::name

#6.  Money Q1. List all mints.
echo "document(\"Money\")/descendant::mint"
java XpathPlus RETURN document("Money")/descendant::mint


#7. Money Q2. list years for invalid coins
echo "document(\"Money\")/child::currency[child::form/child::coin][child::valid[text()=\"No\"]]/descendant::year"
java XpathPlus RETURN document("Money")/child::currency[child::form/child::coin][child::valid[text()="No"]]/descendant::year

#8. Money Q3. report denominations of all USA money
echo "document(\"Money\")/child::currency[descendant::country[text()=\"USA\"]]/descendant::denom"
java XpathPlus RETURN document("Money")/child::currency[descendant::country[text()="USA"]]/descendant::denom

#9. Money Q4.  Find the mint of the 5 Euro coin
echo "document(\"Money\")/child::currency[child::amount[child::denom[text()=\"5\"]][child::unit[text()=\"Euro\"]]/descendant::mint"
java XpathPlus RETURN document("Money")/child::currency[child::amount[child::denom[text()="5"]][child::unit[text()="Euro"]]/descendant::mint

#10. Money Q5. (modified) report names, denominations of all bank notes released in 2002
echo "document(\"Money\")/descendant::year[text()=\"2002\"]/parent::node()/parent::node()/following-sibling::amount"
java XpathPlus RETURN document("Money")/descendant::year[text()="2002"]/parent::node()/parent::node()/following-sibling::amount

#11. Movies Q1.
echo "document(\"Movies\")/child::movie/child::title"
java XpathPlus RETURN document("Movies")/child::movie/child::title

#12. Movies Q2. Find titles of all Eureka episodes that follow "Duck Duck Goose".
echo "document(\"Movies\")/child::tv[child::title[text()=\"Eureka\"]]/child::episodes/child::episode[child::title[text()=\"Duck Duck Goose\"]]/following-sibling::episode/child::title"
java XpathPlus RETURN document("Movies")/child::tv[child::title[text()="Eureka"]]/child::episodes/child::episode[child::title[text()="Duck Duck Goose"]]/following-sibling::episode/child::title

#13. Movies Q3. List the first three stars of Memento
echo "document(\"Movies\")/child::movie[child::title[text()=\"Memento\"]]/child::actors/child::name[position() <= 3]"
java XpathPlus RETURN document("Movies")/child::movie[child::title[text()="Memento"]]/child::actors/child::name[position() <= 3]

#14. Movies Q4.  List titles of all R-rated movies.
echo "document(\"Movies\")/descendant::rating[text()=\"R\"]/preceding-sibling::title[parent::movie]"
java XpathPlus RETURN document("Movies")/descendant::rating[text()="R"]/preceding-sibling::title[parent::movie]

#15. Movies Q5. List genres of all Sony Pictures movies
echo  "document(\"Movies\")/child::movie/child::studio[text()=\"Sony Pictures\"]/preceding-sibling::genres/child::genre"
java XpathPlus RETURN document("Movies")/child::movie/child::studio[text()="Sony Pictures"]/preceding-sibling::genres/child::genre

#16. Music Q1. report names of all albums
echo "document(\"Music\")/child::album/child::name"
java XpathPlus RETURN document("Music")/child::album/child::name

#17 Music Q2.  All tracks from an album, which features Kronos Quartet as one of the artists

echo "document(\"Music\")/child::album/child::artist[attribute::name[text()=\"Kronos Quartet\"]]/following-sibling::disk/child::track"
java XpathPlus RETURN document("Music")/child::album/child::artist[attribute::name[text()="Kronos Quartet"]]/following-sibling::disk/child::track

#18. Music Q3.  Find all bass players.
# note that we cannot do "following-sibling"/"preceding-sibling" on attributes, as they are not ordered

echo "document(\"Music\")/descendant::artist/attribute::type[text()=\"bass\"]/parent::node()/attribute::name"
java XpathPlus RETURN document("Music")/descendant::artist/attribute::type[text()="bass"]/parent::node()/attribute::name

#19. Find all tracks on "present" that preceed "Double Bass" (this DOES include both disks).
# if executed verbatim, this is not a very efficient query. but it will strain your system
echo "document(\"Music\")/descendant::track[ancestor::album/child::name[text()=\"Present\"]][following::track/attribute::name[text()=\"Double Bass\"]]"
java XpathPlus RETURN document("Music")/descendant::track[ancestor::album/child::name[text()="Present"]][following::track/attribute::name[text()="Double Bass"]]

#Q20. Find titles of all 1-disk CDs
# this is a bit clumsy, but it uses "not()" and avoids arithmetics.
echo "document(\"Music\")/child::album/child::name[following-sibling::disk[not(following-sibling::disk)]]"
java XpathPlus RETURN document("Music")/child::album/child::name[following-sibling::disk[not(following-sibling::disk)]]




# list all repositories, make certain things are fine 
java XpathPlus  LIST

#
# AND WE ARE DONE!
#























