Skip to content

Instantly share code, notes, and snippets.

View caschwartz's full-sized avatar

Christine Schwartz caschwartz

View GitHub Profile
@caschwartz
caschwartz / insert-introductions-tei.xqy
Last active December 18, 2015 22:09
XQuery - Query to find TEI documents lacking introductions and insert correct introductions based on year of lecture
xquery version "1.0-ml";
(: 4/18/13 Query to find TEI documents lacking introductions and insert correct introductions based on year of lecture :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace localtei = "http://digital.library.ptsem.edu/lectures/tei";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
let $teiDocs := fn:collection()
@caschwartz
caschwartz / no-bios-tei.xqy
Last active December 18, 2015 22:09
XQuery - Query to find TEI documents lacking biographies
xquery version "1.0-ml";
(: 4/18/13 Query to find TEI documents lacking biographies :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace localtei = "http://digital.library.ptsem.edu/lectures/tei";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
let $teiDocs := fn:collection()
@caschwartz
caschwartz / insert-bios-tei.xqy
Last active December 18, 2015 22:09
XQuery - Query to find TEI documents lacking biographies and insert correct biographies
xquery version "1.0-ml";
(: 4/17/13 Query to find TEI documents lacking biographies and insert correct biographies :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace localtei = "http://digital.library.ptsem.edu/lectures/tei";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
let $teiDocs := fn:collection()
@caschwartz
caschwartz / load-pdf-files.xqy
Last active December 15, 2015 04:08
XQuery - Query filesystem to load PDF files and modify PDF filenames
xquery version "1.0-ml";
(: 3/27/13 Query the filesystem to add finalized PDFs to a MarkLogic database using the <dc:identfier> value for the filenames :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace localtei = "http://my.local.tei.customized.schema/tei";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
for $teiDoc in fn:collection()
let $newID := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:identifier
@caschwartz
caschwartz / add-documents-to-collection.xqy
Last active October 13, 2015 07:48
XQuery - Query to add documents to the Benson Collection (using MARCXML record for collection heading)
xquery version "1.0-ml";
(: 9/5/12 Query to add documents to the Benson collection :)
declare namespace ia = "http://my.local.namespace";
declare namespace m = "http://www.loc.gov/MARC21/slim";
for $doc in xdmp:directory("/ia-xml/", "infinity")
let $marcRecord := $doc/ia:doc/ia:metadata/ia:marc/m:record
let $collectionTitles := $marcRecord/m:datafield[@tag = "730"]
@caschwartz
caschwartz / correct-sort-title-punctuation.xqy
Last active October 13, 2015 02:47
XQuery - Query retrieves and replaces sort titles with punctuation at the beginning of the title
xquery version "1.0-ml";
(: 11/7/12 This query retrieves and replaces sort titles with punctuation at the beginning of the title :)
declare namespace ia = "http://my.namespace.uri";
let $docs := xdmp:directory("/ia-xml/o/", "infinity")
let $sortTitles := $docs/ia:doc/ia:metadata/ia:sortTitle
for $sortTitle in $sortTitles
let $newSortTitle := fn:replace($sortTitle, "^\p{P}+\s*", "")
@caschwartz
caschwartz / remove-final-period-from-names.xqy
Last active October 13, 2015 00:57
XQuery - Query removes final period from names unless part of name
xquery version "1.0-ml";
(: 11/16/12 This query removes the final period from names :)
declare namespace ia = "http://my.local.namespace.name";
let $docs := xdmp:directory("/ia-xml/i/", "infinity")
let $meta := $docs/ia:doc/ia:metadata
for $name in $meta/ia:name
let $newNameNode := if (fn:matches($name, "[a-zA-Z]\.\s*$")) then (: keeps final period for names with initials, titles, etc. :)
@caschwartz
caschwartz / delete-obsolete-docs.xqy
Last active October 11, 2015 13:47
Query two databases, compare URIs, and delete obsolete documents
xquery version "1.0-ml";
let $query := 'cts:uris()'
let $options :=
<options xmlns="xdmp:eval">
<database>{ xdmp:database("my.database") }</database>
</options>
let $theocomURIs := xdmp:eval($query, (), $options)
let $dcwebURIs := cts:uris("/theocom/ia-xml/")[70001 to 80000]
for $dcwebURI in $dcwebURIs
@caschwartz
caschwartz / construct-volume-info-elements.xqy
Last active October 6, 2015 06:18
Query constructs a <volumeInfo> element using part of the Internet Archive ID for the <volume> value
xquery version "1.0-ml";
(: 6/4/12 This query constructs a <volumeInfo> element using part of the IA ID for the <volume> value. :)
declare namespace ia = "http://my.server/my.directory";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $docs := xdmp:directory("/ia-xml/l/lv/", "infinity")
for $doc in $docs
@caschwartz
caschwartz / add-id-attributes.xqy
Last active October 5, 2015 20:17
Query adds identifiers to local metadata schema <volumeInfo> elements
xquery version "1.0-ml";
(: 5/31/12 This query adds identifiers to <volumeInfo> elements :)
declare namespace ia = "http://my.server/my.directory";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $docs := xdmp:directory("/ia-xml/f/", "infinity")
let $titles := $docs/ia:doc/ia:metadata/ia:title