Skip to content

Commit

Permalink
IIIF presentation API: use rendering property on canvas to link back …
Browse files Browse the repository at this point in the history
…to transcription
  • Loading branch information
wolfgangmm committed Nov 12, 2023
1 parent 974ff81 commit a112a35
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion data/doc/documentation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3583,7 +3583,7 @@ declare function pmf:code($config as map(*), $node as element(), $class as xs:st
by <tag>pb-split-list</tag>, displaying the list of available lemmata in the encyclopedia.</para>
<para>In addition, it imports a separate module from <link xlink:href="modules/iiif.xql" role="source">modules/iiif.xql</link>, containing functions for
generating a IIIF presentation manifest (see the <link xlink:href="../test/F-rom.xml" xlink:show="new">Shakespeare example</link>):</para>
<synopsis language="xquery">import module namespace iiif="https://stonesutras.org/api/iiif" at "iiif.xql";</synopsis>
<synopsis language="xquery">import module namespace iiif="https://e-editiones.org/api/iiif" at "iiif.xql";</synopsis>
<para>To reference a custom function in the <parameter>operationId</parameter> parameter of
<filename>modules/custom-api.json</filename>, use the prefix <parameter>custom:</parameter> if the corresponding XQuery
function is available in <filename>modules/custom-api.xql</filename>. If it resides in an imported module, use
Expand Down
2 changes: 1 addition & 1 deletion modules/config.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ declare variable $config:enable-proxy-caching :=
: In this case, change $config:webcomponents-cdn to point to http://localhost:port
: (default: 8000, but check where your server is running).
:)
declare variable $config:webcomponents := "2.12.8";
declare variable $config:webcomponents := "2.14.1";

(:~
: CDN URL to use for loading webcomponents. Could be changed if you created your
Expand Down
2 changes: 1 addition & 1 deletion modules/custom-api.xql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import module namespace rutil="http://e-editiones.org/roaster/util";
import module namespace tpu="http://www.tei-c.org/tei-publisher/util" at "lib/util.xql";
import module namespace pm-config="http://www.tei-c.org/tei-simple/pm-config" at "pm-config.xql";
import module namespace roaster="http://e-editiones.org/roaster";
import module namespace iiif="https://stonesutras.org/api/iiif" at "iiif.xql";
import module namespace iiif="https://e-editiones.org/api/iiif" at "iiif.xql";

declare function api:lookup($name as xs:string, $arity as xs:integer) {
try {
Expand Down
54 changes: 41 additions & 13 deletions modules/iiif.xql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
:
: While the XQuery code is quite generic, it may need to be adjusted for
: concrete use-cases.
:
: The general assumption is that for each milestone element in the TEI (usually a pb or milestone),
: a canvas is created, containing one image. The image service URL is generated
: by appending the string returned by iiif:milestone-id to $iiif:IMAGE_API_BASE.
: The canvas id will correspond to $iiif:CANVAS_ID_PREFIX with iiif:milestone-id appended.
:)
module namespace iiif="https://stonesutras.org/api/iiif";
module namespace iiif="https://e-editiones.org/api/iiif";

import module namespace http="http://expath.org/ns/http-client" at "java:org.exist.xquery.modules.httpclient.HTTPClientModule";
import module namespace config="http://www.tei-c.org/tei-simple/config" at "config.xqm";
Expand All @@ -18,7 +23,29 @@ declare namespace tei="http://www.tei-c.org/ns/1.0";
(:~
: Base URI of the IIIF image API service to use for the images
:)
declare variable $iiif:IMAGE_API_BASE := "https://apps.existsolutions.com/cantaloupe/iiif/2/";
declare variable $iiif:IMAGE_API_BASE := "https://apps.existsolutions.com/cantaloupe/iiif/2";

(:~
: URL prefix to use for the canvas id
:)
declare variable $iiif:CANVAS_ID_PREFIX := "https://e-editiones.org/canvas/";

(:~
: Return all milestone elements pointing to images, usually pb or milestone.
:
: @param $doc the document root node to scan
:)
declare function iiif:milestones($doc as node()) {
$doc//tei:body//tei:pb
};

(:~
: Extract the image path from the milestone element. If you need to strip
: out or add something, this is the place.
:)
declare function iiif:milestone-id($milestone as element()) {
substring-after($milestone/@facs, "FFimg:")
};

(:~ Contact the IIIF image api to get the dimensions of an image :)
declare %private function iiif:image-info($path as xs:string) {
Expand All @@ -37,13 +64,13 @@ declare %private function iiif:image-info($path as xs:string) {
: Create the list of canvases: for each pb element in the document, one canvas is output.
:)
declare %private function iiif:canvases($doc as node()) {
for $pb in $doc//tei:body//tei:pb
let $id := substring-after($pb/@facs, "FFimg:")
for $pb in iiif:milestones($doc)
let $id := iiif:milestone-id($pb)
let $info := iiif:image-info($id)
where exists($info)
return
map {
"@id": "https://e-editiones.org/canvas/page-" || $pb/@n || ".json",
"@id": $iiif:CANVAS_ID_PREFIX || $id,
"@type": "sc:Canvas",
"label": "Page " || $pb/@n,
"width": $info?width,
Expand All @@ -64,16 +91,17 @@ declare %private function iiif:canvases($doc as node()) {
"profile": "http://iiif.io/api/image/2/level2.json"
}
},
"on": "https://e-editiones.org/canvas/page-" || $pb/@n || ".json"
"on": $iiif:CANVAS_ID_PREFIX || $id
}
],
(: Extension property to keep track of the corresponding page as shown in a pb-view.
: This should either contain a root or id parameter which could be used to navigate
: to the correct page in the transcription.
:)
"https://teipublisher.com/page": map {
"root": util:node-id($pb)
}
"rendering": [
map {
"@id": iiif:link("api/parts/" || encode-for-uri(config:get-relpath($doc)) || "/html") ||
"?root=" || util:node-id($pb),
"format": "text/html",
"label": "Transcription of page"
}
]
}
};

Expand Down

0 comments on commit a112a35

Please sign in to comment.