Created
October 2, 2015 01:15
-
-
Save jeffreycwitt/66a83703a0e885e2d53e to your computer and use it in GitHub Desktop.
existdb to IIIF search results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
import module namespace console="http://exist-db.org/xquery/console"; | |
declare option output:method "json"; | |
declare option output:media-type "application/json"; | |
declare function local:render($node) { | |
typeswitch($node) | |
case text() return concat($node, ' ') | |
case element(tei:p) return <p>{local:recurse($node)}</p> | |
case element(tei:title) return <em>{local:recurse($node)}</em> | |
case element(tei:name) return <span style="font-variant: small-caps">{local:recurse($node)}</span> | |
case element(exist:match) return <span style="background-color: yellow;">{local:recurse($node)}</span> | |
case element(tei:rdg) return () | |
case element(tei:bibl) return () | |
case element (tei:note) return () | |
default return local:recurse($node) | |
}; | |
declare function local:recurse($node) { | |
for $child in $node/node() | |
return | |
local:render($child) | |
}; | |
let $commentaryid := request:get-parameter('commentaryid', 'plaoulcommentary') | |
let $q := request:get-parameter('q', '') | |
let $searchuri := request:get-uri() | |
(: full-msslug should be able to be parsed from requesting url :) | |
let $msslug := "vat" | |
let $commentaryslug := "pp" | |
let $full-msslug : = concat ($commentaryslug, "-", $msslug) | |
let $docs := collection(concat('/db/apps/scta/', $commentaryid))[contains(util:document-name(.), $msslug)] | |
let $hits := $docs//tei:p[ft:query(., $q)] | |
return | |
map{ | |
"@context":"http://iiif.io/api/search/0/context.json", | |
"@id": $searchuri, | |
"@type":"sc:AnnotationList", | |
"resources": | |
for $hit in $hits | |
(: ancestor was not working in $pid statement. but ancestor should work and is preferabl to preceding :) | |
let $pid := $hit/preceding::tei:p[1]/@xml:id/string() | |
let $itemid := $hit/ancestor::tei:body/tei:div/@xml:id/string() | |
let $itemtitle := $hit/preceding::tei:titleStmt/tei:title/string() | |
let $bibl := $hit/following-sibling::tei:bibl | |
(: needs to make adjustments if hit occurs in zone 1 or 2 or 3, etc | |
currently it just defaults to the first zone :) | |
let $witfolio := $hit/preceding::tei:zone[@start=concat("#", $pid)][1]/parent::tei:surface/@n/string() | |
return | |
map { | |
"test": $pid, | |
"@id": concat("http://scta.info/iiif/", $full-msslug, "/search/annotations/", $pid), | |
"@type": "oa:Annotation", | |
"motivation": "sc:painting", | |
"resource": | |
map { | |
"@type": "cnt:ContentAsText", | |
"chars": local:render(util:expand($hit)) | |
}, | |
"on": concat("http://scta.info/iiif/", $full-msslug, "/canvas/", $witfolio) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment