Next page Previous page Start of chapter End of chapter

Running example

Write in XQuery the following queries for the DBLP application and run them:

  1. The publications of Moshe Y. Vardi sorted in reverse cronological order
    for $p in /dblp/*[author = "Moshe Y. Vardi"]
    order by xs:integer($p/year) descending  
    return $p
    
  2. The publications of Moshe Y. Vardi sorted in decreasing order by number of authors
    for $p in /dblp/*[author = "Moshe Y. Vardi"]
    order by count($p/author) descending
    return $p
    
  3. The (distinct) book authors sorted by name
    for $a in distinct-values(/dblp/book/author)
    order by $a  
    return 
    <author>{$a}</author>
    
  4. One publication with the maximum number of authors
    let $q := for $p in /dblp/*
              order by count($p/author)  descending
              return $p
    return $q[1]          
    
  5. The publications with the maximum number of authors labelled with that number
    (: compute the maximum number of authors :)
    let $count := for $c in /dblp/* 
                  return count($c/author)
    let $max := max($count)              
    (: find the papers with that number of authors :)
    for $p in /dblp/*
    where count($p/author) = $max  
    return <pub authors="{$max}">{$p}</pub>
    
  6. The proceedings edited by Moshe Y. Vardi and the corresponding inproceedings papers
    for $proc in /dblp/proceedings[editor = "Moshe Y. Vardi"]
    let $inproc := /dblp/inproceedings[crossref = $proc/@key]
    return ($proc, $inproc)
    
  7. The proceedings edited by Moshe Y. Vardi labelled with the number of corresponding inproceedings papers
    for $proc in /dblp/proceedings[editor = "Moshe Y. Vardi"]
    let $inproc := /dblp/inproceedings[crossref = $proc/@key]
    return <proceedings size="{count($inproc)}">{$proc/*}</proceedings>
    
  8. The papers containing the word XML in the title sorted by relevance score in decreasing order
    for $hit score $score in /dblp/*[title contains text "XML"]
    order by $score descending
    return <hit score="{$score}">{$hit}</hit>
    
  9. The papers containing the word XML in the title sorted by the product of the relevance score and the number of authors in decreasing order
    for $hit score $relevance in /dblp/inproceedings[title contains text "XML"]
    let $authors := count($hit/author)
    let $score := $relevance * $authors 
    order by $score descending
    return <hit relevance="{$relevance}" authors="{$authors}" score="{$score}">{$hit}</hit>
  10. A function that computes the average number of authors of the publications in the h sequence of a given author
    declare function local:avgh($doc as node()*, $author as xs:string) as xs:decimal
    {
      let $pub := for $x in $doc/dblp/*[author=$author]
                  order by xs:integer($x/@cites) descending
                  return $x
      let $auth :=  for $n in (1 to count($pub))
                    where xs:integer($pub[$n]/@cites) >= $n
                    return count($pub[$n]/author)
      return avg($auth)
    };
    
Next page Previous page Start of chapter End of chapter
Caffè XML - Massimo Franceschet