Sunday 19 January 2014

XQuery for VIAF id numbers

Our bibliography has (too many) authors for whom we need VIAF numbers. Using VIAF API (as described), we get numbers from the database in several steps.

  1. find distinct values of unassigned authors in the bibliography
  2. turn these values into a XML sequence
  3. use the sequence to query VIAF

For the last phase, we use this XQuery (and BaseX GUI):

declare namespace ns2="http://viaf.org/viaf/terms#";
declare namespace ns3="http://viaf.org/viaf/terms#";
(: address to which we are sending the queries :)
let $url :=
("http://www.viaf.org/viaf/search?query=local.personalNames+all+%22REPLACE_URN%22&maximumRecords=1&sortKeys=holdingscount&httpAccept=text/xml")
(: our sequence :)
let $rijeci :=
<a>
<n>Adelmann von Adelmannsfelden, Konrad</n>
<n>Aegidii, Guillermus</n>
<n>Alexander, Natalis</n>
<n>Algerus</n>
<!-- many more -->
<n>Zoller, Martin</n>
</a>

(: for each item in sequence, batches of 100 :)
for $r in $rijeci/n[401>position() and position()>=301]

let $qrijeci := replace($r, " ", "+")
let $parsed := (doc(replace($url,'REPLACE_URN',$qrijeci)))

return element author {
element ref {
attribute type { "viaf" } ,
attribute target { data($parsed//ns2:VIAFCluster/ns2:viafID) } ,
data($r) }
}

No comments:

Post a Comment