Skip to content

Commit

Permalink
add xquery and BaseX command script(s).
Browse files Browse the repository at this point in the history
  • Loading branch information
CanOfBees committed May 2, 2017
1 parent 086e398 commit bfeccb3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions add-repox-sets.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace oai = "http://www.openarchives.org/OAI/2.0/";


for $set in fn:doc('http://dpla.lib.utk.edu/repox/OAIHandler?verb=ListSets')/oai:OAI-PMH/oai:ListSets/oai:set
let $spec := $set/oai:setSpec/text()
let $name := $set/oai:setName/text()
return(
db:add('repox-sets', <set><spec>{$spec}</spec><name>{$name}</name></set>, $name)
)
44 changes: 44 additions & 0 deletions add-sets-to-db.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(: preface this with a COMMAND: `set addcache true; create db OAI` :)
(: grab oai-pmh from repox :)
declare namespace oai = "http://www.openarchives.org/OAI/2.0/";

(: Retrieves metadata records for an entire OAI-PMH collection :)
(: Adds records to BaseX database:)

declare function local:request($base-url as xs:string, $verb as xs:string, $set-spec as xs:string) as document-node()*
{
let $request := $base-url || $verb || $set-spec
let $response := fn:doc($request)
let $token := $response//oai:resumptionToken/text()
return
if (fn:empty($token)) then
$response
else
($response,
local:resume($base-url, $token))
};

declare function local:resume($base-url as xs:string, $token as xs:string) as document-node()*
{
let $verb := "?verb=ListRecords&amp;resumptionToken="
let $request := $base-url || $verb || $token
let $response := fn:doc($request)
let $new-token := $response//oai:resumptionToken/text()
return
if (fn:empty($new-token)) then
$response
else
($response,
local:resume($base-url, $new-token))
};

for $set in db:open('repox-sets')/set/spec/text()
let $base-url := "http://dpla.lib.utk.edu/repox/OAIHandler" (: UTK's REPOX install :)
let $verb := "?verb=ListRecords&amp;metadataPrefix=oai_dc"
let $set-spec := "&amp;set=" || $set
let $response := local:request($base-url, $verb, $set-spec)
for $record in $response//oai:record
let $id := $record/oai:header/oai:identifier/text()
return(
db:add(($set), $record, $id, map { 'addcache': true() } )
)
5 changes: 5 additions & 0 deletions create-db-for-each-set.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(: this xquery script :)

for $set in db:open('repox-sets')/set/spec/text()
return
db:create(($set), (), (), map { 'textindex': true(), 'attrindex': true(), 'tokenindex': true(), 'ftindex': true() } )
5 changes: 5 additions & 0 deletions create-repox-sets-db.bxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- create a 'repox-sets' database -->

<commands>
<create-db name="repox-sets"/>
</commands>

0 comments on commit bfeccb3

Please sign in to comment.