Skip to content

Instantly share code, notes, and snippets.

View caschwartz's full-sized avatar

Christine Schwartz caschwartz

View GitHub Profile
@caschwartz
caschwartz / locate-comments.xqy
Last active December 28, 2015 08:18
XQuery - Query to locate MODS titleInfo elements that are commented out
xquery version "1.0-ml";
(: 11/14/13 Query to locate the titleInfo elements that are commented out :)
declare namespace mods = "http://www.loc.gov/mods/v3";
for $doc in xdmp:directory("/MODS/", "infinity")
let $comments := $doc/mods:modsCollection/mods:mods//comment()
for $comment in $comments
@caschwartz
caschwartz / ead-modify-headers.xqy
Last active December 21, 2015 21:38
XQuery - Query headers in EAD documents and create a new text nodes with the colons removed using MarkLogic imperative function
xquery version "1.0-ml";
(: 8/27/13 Query all headers in EAD documents and create a new text nodes with the colons removed using MarkLogic imperative function :)
declare namespace ead = "urn:isbn:1-931666-22-9";
let $docs := xdmp:directory("/EAD/")
let $headers := $docs/ead:ead//ead:head
for $header in $headers
where fn:ends-with($header, ":")
@caschwartz
caschwartz / find-title-date-duplicates.xqy
Last active December 21, 2015 14:59
XQuery - Query to retrieve all exact duplicates title-date values
xquery version "1.0-ml";
(: 8/6/13 Query to retrieve all exact duplicates title-date values (using one of Priscilla Walmsley's functx XQuery functions :)
declare namespace ia = "http://my.local.namespace";
declare namespace m = "http://www.loc.gov/MARC21/slim";
declare namespace functx = "http://www.functx.com";
declare function functx:non-distinct-values
( $seq as xs:anyAtomicType* ) as xs:anyAtomicType* {
@caschwartz
caschwartz / list-collection-names.xqy
Last active December 21, 2015 14:48
XQuery - Query to list unique PTS collection names (taken from MARC 730 fields)
xquery version "1.0-ml";
(: 8/21/13 Query to list unique PTS collection names (taken from MARC 730 fields) :)
declare namespace ia = "http://my.local.namespace";
declare namespace m = "http://www.loc.gov/MARC21/slim";
(: Finds unique collection names other than Benson and Torrance :)
let $collNames := fn:distinct-values(for $doc in fn:collection()[1 to 10000]
let $marc := $doc/ia:doc/ia:metadata/ia:marc/m:record
@caschwartz
caschwartz / edition-statements.xqy
Last active December 18, 2015 23:28
XQuery - Query theocom documents for edition for works by John Calvin
xquery version "1.0-ml";
(: 5/29/11 Query theocom documents for edition for works by John Calvin :)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
declare namespace m = "http://www.loc.gov/MARC21/slim";
for $doc in xdmp:directory("/ia-xml/8/", "infinity")
let $marc := $doc/ia:doc/ia:metadata/ia:marc/m:record
@caschwartz
caschwartz / create-edition-elements.xqy
Last active December 18, 2015 23:19
XQuery - Query embedded MARC records for edition statements and create <edition> element for local metadata schema
xquery version "1.0-ml";
(: 6/19/12 Query theocom documents for edition statements and create <edition> elements :)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
declare namespace m = "http://www.loc.gov/MARC21/slim";
for $doc in xdmp:directory("/ia-xml/l/ly/", "infinity")
let $marc := $doc/ia:doc/ia:metadata/ia:marc/m:record
@caschwartz
caschwartz / add-integer-attribute.xqy
Last active December 18, 2015 23:19
XQuery - Query that adds the @integer attribute to the <number> element
xquery version "1.0-ml";
(: 7/11/12 This query adds the @integer attribute to the <number> element :)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $docs := xdmp:directory("/ia-xml/d/", "infinity")
@caschwartz
caschwartz / ead-subject-headings.xqy
Last active March 10, 2020 13:35
XQuery - Query to locate EAD documents with <controlaccess> element containing subject headings
xquery version "1.0-ml";
(: 8/6/12 Query to locate EAD documents that have a <controlaccess> element with subject headings. :)
declare namespace ead = "urn:isbn:1-931666-22-9";
for $doc in xdmp:directory("/EAD/")
let $controlAccess := $doc/ead:ead/ead:archdesc/ead:controlaccess[2] (: Second controlaccess element contains subjects :)
let $title := $doc/ead:ead/ead:eadheader/ead:filedesc/ead:titlestmt/ead:titleproper
return $controlAccess
@caschwartz
caschwartz / add-type-elements-to-tei.xqy
Last active December 18, 2015 22:09
XQuery - Query to add <dc:type> element to TEI documents in lectures database
xquery version "1.0-ml";
(: 6/7/13 Query to add <dc:type> element to TEI documents in lectures database :)
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/";
for $teiDoc in xdmp:directory("/TEI/", "infinity")
let $id := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:identifier
@caschwartz
caschwartz / correct-problem-names.xqy
Last active December 18, 2015 22:09
XQuery - Query to find and correct problem names in the theocom database
xquery version "1.0-ml";
(: 5/1/13 This query find and corrects problem names in the theocom database :)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
for $doc in xdmp:directory("/ia-xml/h/hi/his/", "infinity")
let $name := $doc/ia:doc/ia:metadata/ia:name
let $newNameNode := <name xmlns="http://digital.library.ptsem.edu/ia">Goodspeed, Edgar J. (Edgar Johnson), 1871–1962</name>