Ein paar Kommentare zur Relevanz der einzelnen Vorlesungskapitel (entspricht weitgehend den Infos aus der letzten Vorlesung, s. Table of Contents: http://www.inf.uni-konstanz.de/dbis/teaching/ws0708/xml/Inhalt.pdf ). Wichtig: die Zusammenfassung dient nur als Richtlinie; v.a. solltet Ihr Euch auch die Übungen nochmal ansehen: 1.1. irrelevant 2.2-2.4. die wichtigsten Konzepte sollten bewusst sein, Details irrel. 3.5-3.7... ebenso: kein Detailwissen verlangt 4.8-4.11: relevant 5.12-5.13: irrelevant 5.14: relevant 5.15: XPath Accelerator & Staircase Join relevant 5.16-5.17: Konzepte sollten verstanden werden, techn. Details irrelevant 5.18: irrelevant (..happy? ;) 5.19-6.23: once more: Konzepte, keine Implementierungsdetails Native XML Processing/Info Retrieval/XQuery Fulltext: kein Detailfragen Übungsklausur: A 1) /descend::titel[following-sibling::mitarbeiter/assistent] 2) /descendant::titel[count(following-sibling::mitarbeiter/assistent) >= 2] 3) /descendant::node()/vorlesung[mitarbeiter/*/@id="seifert"]/preceding::node()/vorlesung 4) /descendant::vorlesung[last()] 5) /descendant::dozent[@id="scholl"]/parent::*/parent::vorlesung Welche Vorlesungen werden vom Dozent mi der id "scholl" betreut /descendant::vorlesung[mitarbeiter/dozent/@id="scholl"] B 1) pre size kind prop 0 9 element a 1 3 element b 2 2 element c 3 0 element d 4 0 element e 5 4 element f 6 0 element g 7 2 element h 8 0 element i 9 0 element j 2) ancestor: pre(v') < pre(v) & size(v') > size(v) & pre(v) - pre(v') >= size(v') descendant: pre(v') > pre(v) & size(v') < size(v) & pre(v') - pre(v) <= size(v) following: pre(v') > pre(v) & pre(v') - pre(v) size(v') preceding: pre(v') < pre(v) & size(v') D 1) Pruning: Beim Pruning werden diejenigen Kontextknoten ignoriert, die in der Region anderer Kontextknoten liegen. zB wenn bei (c1,c2)/descendant::node() c2 auch descendant von c1 ist, so reicht die Berechnung von c1/descendant::node() und man spart sich redundante Ergebnismengen Partitioning: Partioning teilt die den Bereich so ein das nur die für die Anfrage relevanten Knoten erfasst werden. zB werden bei der Anfrage (c1,c2)/descendant::node() alle Knoten entfernt die einen kleinere pre-Wert haben wie c1, solange bis c2 erreicht ist. Skipping: Skipping überspringt Knoten, die aufgrund ihrer pre/post Werte nicht im Bereich der Knotextknoten liegen können. zB: Bei (c1,c2)/descendant::node() kann im bereich zwischen pre(c2) - pre(c1), jeder Knoten übersprungen werden für den gilt c1.post < node.post. 1) Beim Pruning werden diejenigen Kontextknoten c2 ignoriert, die vom Bereich eines anderen Kontextknoten c1 abgedeckt werden. Da die aber jeder Knoten seine eigenen Kinder besitzt, können sich diese Bereiche nie überlappen, somit funktioniert Puning hier nicht. Beim Skipping werden diejenigen Kn Übung 3 XPath 1) Print all countries which are stored in the XML document descendant::country/@name 2) How many countries can be found? count(descendant::country) 231 3) Print the names of all Chinese cities descendant::country[./@name = "China"]/descendant-or-self::city/name/text() 4) How many people live in Bangladesh? descendant::country[./@name = Bangladesh]/@population 5) In which countries live more than 10 million people? descendant::country[./@population > 10000000]/@name 6) Find the first 3 French cities which are stored in the document descendant::country[./@name = "France"]/descendant-or-self::city[position() <= 3]/name/text() 7) Print all countries in which more than 60% of the population speak German descendant::ethnicgroups[. = "German"][./@percentage > 60]/ancestor::country/@name 8) Print the average number of inhabitants of all cities in the document sum(descendant::city/population) div count(descendant::city) 9) Print the names of all cities that have more than 20 characters descendant::city/name[string-length(.) > 20] 10) How many tag names in the document have less than 3 characters? count(descendant-or-self::*[string-length(name()) < 3]) Übung 4 XQuery Exercise 1: 1) 100 + 11 XQuery wertet "11" als rhs und "100" als lhs. Deswegen wird "11" als 11 und "100" als 100 interpretiert. lhs+rhs = 111 2) (1, 2) > (3, 2, 1) true, da XQuery immer dann true zurück gibt, wenn der Vergleich zwischen zwei Objekte der verglichenen Sequenzen true ergibt. Hier: 2 > 1 -> true 3) ( ) != 1 Es existiert kein Element für das gilt rhs = lhs -> false 4) /descendant-or-self::a XQuery geht in documentorder durch. Listet zuerst die descendandts und dann self 5) [//findme] Im Prädikat fehlt der Zugriff auf die document node, deswegen kommt ein Fehler. Richt: [.//findme] Exercise 2: 1) Which countries can be found that have Jewish and Russian ethnic groups? for $j in descendant::ethnicgroups where $j = 'Russian' and $j/parent::country/@id = (for $i in descendant::ethnicgroups where $i = 'Jewish' return $i/parent::country/@id) return $j/parent::country/@name oder for $y in descendant::country let $x := $y/ethnicgroups where $x = "Russian" and $x = "Jewish" return $y/@name 2) Create an alphabetically sorted list of all country names for $y in descendant::country/@name order by $y return $y 3) Print the names and founding dates (@established attribute) of all organizations that have more than 180 members for $y in descendant::organization where count($y/member) > 180 return $y/@name | $y/@established oder for $y in descendant::organization where count($y/member) > 180 return ($y/@name , $y/@established) 4) Create a list of all countries with the following syntax (whitespaces don’t matter): ... { for $y in descendant::country return {$y/@name} } 5) Guess you know that already, but... What’s the name of the country with the largest population? for $i in descendant::country where $i/@population = max(descendant::country/@population) return $i/@name oder für bessere Performance: let $y := max(descendant::country/@population) for $i in descendant::country where $i/@population = $y return $i/@name Assignment 9 Exercise 1: Starcase Join The Pre/Post Encoding and the Staircase Join allow efficient access to the four major XPath axes. Some additional work has to be done when other axes are evaluated: · explain why the Pruning algorithm can’t be applied to the child axis · analyze how the following-sibling axis can be evaluated without the Parent value Exercise 3: · /child::jamie/child::jerry/child::jeremie[text() = "joe”]/../.. /descendant::jeremie[./text() = "joe"] · /descendant-or-self::node()/child::james /descendant::james · /child::node()/parent::node() /self::node() · /parent::node()/ancestor-or-self::node() /ancestor::node() · /descendant::jason/preceding::jasper /descendant::jasper · /child::jim/preceding-sibling::jack /child::jack Assignment 10 Exercise 1: The Pre/Post encoding was initially developed to be stored in a relational database. XPath queries can be rewritten into SQL queries. Please write down SQL expressions for the following queries: XPath queries can also be expressed via so-called window queries. Have a look into the tutorial slides and formulate these two requests as window queries. · /child::jungle/following-sibling::fever SELECT DISTINCT t2.* FROM (SELECT DISTINCT t1.* FROM table t1 AND context c1 WHERE c1.pre < t1.pre AND c1.post < t1.post AND t1.kind='element' AND t1.par = c1.pre AND t1.tag = 'jungle') AS c2, table t2 WHERE c2.pre < t2.pre AND c2.post < t2.post AND t2.kind='element' AND t.tag='fever' AND c2.par = t2.par ORDER BY t2.pre SELECT DISTINCT t1.* FROM table t1, table t2, context c WHERE t1 INSIDE window(following-sibling::fever, t2) AND t2 INSIDE window(child::jungle, c) ORDER BY t1.pre · /descendant-or-self::abraka[child::blabla] SELECT DISTINCT c2.* FROM (SELECT DISTINCT t1.* FROM table t1 AND context c1 WHERE c1.pre <= t1.pre AND c1.post <= t1.post AND t1.kind='element' AND t1.tag='abraka') AS c2, table t2 WHERE c2.pre > t2.pre AND c2.post > t2.post AND t2.kind='element' AND t2.tag='blabla' ORDER BY c2.pre SELECT DISTINCT t2.* FROM table t1, table t2, context c WHERE t1 INSIDE window(child::blabla, t2) AND t2 INSIDE window(descendant-or-self::abraka, c) ORDER BY t2.pre Exercise 2: 1: delete nodes /node()/@state alternativ: delete nodes (for $x in */descendant-or-self::node() let $y := $x/@state return $y) 2: insert node as last into /node()/address 3: for $x in */address let $y := $x/city let $substring := substring($y, 7, string-length()) return replace node $y with {$substring} des /node()/@state alternativ: delete nodes (for $x in */descendant-or-self::node() let $y := $x/@state return $y) 2: insert node as last into /node()/address 3: for $x in */address let $y := $x/city let $substring := substring($y, 7, string-length()) return replace node $y with {$substring}