Skip to content

Instantly share code, notes, and snippets.

@wsalesky
wsalesky / distinct-title-author.xql
Last active June 29, 2016 13:46
Titles and authors, distinct values
xquery version "3.0";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:item-separator "
";
distinct-values(
for $b in collection('/db/apps/bug-test/data/tei')//tei:bibl[not(tei:ptr)]
let $title := $b/tei:title[1]/text()
let $author := $b/tei:author[1]/descendant::tei:surname[1]/text()
return concat(normalize-space($title),' ', normalize-space($author),'
')
@wsalesky
wsalesky / update-bhse-events-relations.xql
Last active June 28, 2016 17:12
Update person records with BHSE attestation and update work recs with person relationship.
declare namespace tei = "http://www.tei-c.org/ns/1.0";
for $r in collection('/db/apps/srophe-data/data/persons/tei/saints/tei')//tei:revisionDesc[@status="incomplete"]/ancestor::tei:TEI[descendant::tei:idno[@type='BHS']]
let $uri := replace($r/descendant::tei:idno[@type='URI'][1],'/tei','')
let $name := $r/descendant::tei:persName[@syriaca-tags='#syriaca-headword'][@xml:lang='en'][1]/text()
let $pid := substring-after($uri,'person/')
return
for $b at $pos in $r//tei:idno[@type='BHS']
let $work := for $w in collection('/db/apps/srophe-data/data/works')//tei:idno[@type='BHS'][. = $b]
return $w/ancestor::tei:TEI
declare namespace tei = "http://www.tei-c.org/ns/1.0";
for $r in collection('/db/apps/bug-test/data/persons')//tei:revisionDesc[@status="incomplete"]/ancestor::tei:TEI
let $uri := replace($r/descendant::tei:idno[@type='URI'][1],'/tei','')
let $name := $r/descendant::tei:persName[@syriaca-tags='#syriaca-headword'][@xml:lang='en'][1]/text()
let $pid := substring-after($uri,'person/')
return
for $b in $r//tei:idno[@type='BHS']
let $work-id :=
for $w in collection('/db/apps/srophe-data/data/works')//tei:idno[@type='BHS'][. = $b]
@wsalesky
wsalesky / update-name-abstract.xql
Created June 24, 2016 14:58
Update incomplete persons abstracts.
for $rec in doc('/db/apps/bug-test/data/abstracts-incomplete-saints.xml')//tei:div
return
for $r in collection('/db/apps/bug-test/data/tei')//tei:idno[. = $rec/tei:idno]/ancestor::tei:TEI/descendant::tei:person
return
(
for $names in $r/tei:persName[@xml:id = $rec/tei:persName/@xml:id]
return
update replace $names with $rec/tei:persName[@xml:id = $names/@xml:id],
for $notes in $r/tei:note[@type='abstract']
return
@wsalesky
wsalesky / bibl-authors.xql
Last active July 1, 2016 13:27
Update person/bibl/authors.
xquery version "3.0";
import module namespace functx="http://www.functx.com";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare function local:parseName($names as xs:string*){
if(contains($names,'.')) then
<author xmlns="http://www.tei-c.org/ns/1.0">
<persName>
<forename>{concat(functx:substring-before-last($names, '.'),'.')}</forename>
<surname>{normalize-space(functx:substring-after-last($names, '.'))}</surname>
@wsalesky
wsalesky / bibl-lang.xql
Created June 21, 2016 18:19
Update note bibl lang
for $rec in collection('/db/apps/srophe-data/data/works/tei')//tei:note[@xml:lang][@type='ancientVersion' or @type='modernTranslation']
let $bibl := $rec/tei:bibl
let $lang := <lang xmlns="http://www.tei-c.org/ns/1.0">{string($rec/@xml:lang)}</lang>
return
(update insert $lang into $bibl,
update delete $rec/@xml:lang)
@wsalesky
wsalesky / idno-update.xql
Created May 4, 2016 17:46
Update Syriaca.org idno's in bibl records.
xquery version "3.0";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
for $rec in collection('/db/apps/srophe-data/data/bibl/tei')//tei:idno[ends-with(.,'/source')]
let $recid := replace($rec/text(),'/source','/tei')
return
update value $rec with $recid
@wsalesky
wsalesky / new-bibl-rec.xql
Created April 21, 2016 16:28
Create new TEI bibl records from bhse-reconciled-authors.xml
xquery version "3.0";
(:
: Create new TEI bibl records from bhse-reconciled-authors.xml
: Save records to db, must be logged into eXist as admin/with admin privileges
:)
declare default element namespace "http://www.tei-c.org/ns/1.0";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace syriaca = "http://syriaca.org";
declare namespace functx = "http://www.functx.com";
@wsalesky
wsalesky / en-headwords.xql
Last active May 4, 2016 17:33
Update Syriaca.org headwords to use first English name.
xquery version "3.0";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
for $rec in collection('/db/apps/srophe-data/data/persons/tei')//tei:title[@level="m"][. = 'Qadishe: A Guide to the Syriac Saints'][ancestor::tei:TEI/descendant::tei:person/tei:persName[@syriaca-tags='#syriaca-headword'][@xml:lang='en-x-gedsh']]
let $r := $rec/ancestor::tei:TEI
let $id := $r/descendant::tei:idno[1]
let $title := $r/descendant::tei:titleStmt/tei:title[@level='a']
let $gedesh := $r/descendant::tei:person/tei:persName[@syriaca-tags='#syriaca-headword'][@xml:lang='en-x-gedsh']
let $syr := $r/descendant::tei:person/tei:persName[@syriaca-tags='#syriaca-headword'][@xml:lang='syr'][1]
let $syr2 := $r/descendant::tei:person/tei:persName[@syriaca-tags='#syriaca-headword'][@xml:lang='syr'][2]
@wsalesky
wsalesky / works-source-update.xql
Created March 18, 2016 14:11
Update bad source refs in works
for $rec in collection('/db/apps/srophe-data/data/works/tei')//tei:note[@source= '#bib221-1']
let $id := tokenize($rec/parent::*[1]/tei:idno[@type='URI'][starts-with(.,'http://syriaca.org')],'/')[last()]
return
update value $rec/@source with concat('#bib',$id,'-1')