Skip to content

Commit

Permalink
add an export script and all-all-records script
Browse files Browse the repository at this point in the history
  • Loading branch information
CanOfBees committed Aug 10, 2017
1 parent ebf8928 commit 826ba91
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
42 changes: 42 additions & 0 deletions add-all-records-to-db.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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) as document-node()*
{
let $request := $base-url || $verb
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&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))
};

let $base-url := "http://dpla.lib.utk.edu/repox/OAIHandler"
let $verb := "?verb=ListRecords&metadataPrefix=MODS"
let $response := local:request($base-url, $verb)
for $record in $response//oai:record
let $id := $record/oai:header/oai:identifier/text()
return(
(: db:replace('cmhf', $record, $id, map { 'addcache': true() }) :)
db:add('all-records', $record, $id, map { 'addcache': true() }),
db:optimize('all-records', true(), map { 'textindex': true(), 'attrindex': true(), 'tokenindex': true(), 'ftindex': true() })
)
17 changes: 17 additions & 0 deletions export-records.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(: db:export to a directory structure in /ghome/bridger :)
import module namespace fnx = 'http://www.functx.com';

let $target := '/mnt/ghome/repox-export/'

for $set-name in db:open('repox-sets')/set/spec/text()
let $output-dir := $target || $set-name
return (
file:create-dir($output-dir),
for $doc in db:open($set-name)
let $file-name := if (fn:contains($doc/record/header/identifier/text(), '/'))
then (fn:substring-after($doc/record/header/identifier/text(), '/') || '.xml')
else (fnx:substring-after-last-match($doc/record/header/identifier/text(), ':') || '.xml')
return (
file:write($output-dir || '/' || $file-name, $doc)
)
)

0 comments on commit 826ba91

Please sign in to comment.