Gitlab Community Edition Instance

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • subugoe/ahiqar/backend
1 result
Select Git revision
Show changes
Commits on Source (4)
Showing
with 1190 additions and 550 deletions
......@@ -15,6 +15,7 @@ docker/frontend
# exclude local scripts
*.sh
!get-unit-test-failures-and-errors.sh
# exlude data for commitizen
node_modules
......
......@@ -43,11 +43,9 @@ test_exist_app:
- curl http://localhost:8080/exist/restxq/trigger-tests
- sleep 60
- bash exist-app/test/bin/shutdown.sh
- failures=$(xmllint --xpath '/tests/testsuites/testsuite/@failures' exist-app/test/test-results.xml | egrep -o "[0-9]+")
- echo "There is/are currently $failures failures."
# one test fails on purpose to ensure the test suite is running correctly.
# thus we always have 1 failing test which indicates that everything is fine.
- if [[ "$failures" -gt 1 ]]; then exit 1; else exit 0; fi
- failures=$(./get-unit-test-failures-and-errors.sh)
- echo -e "\033[1;33mThere is/are currently $failures failures or errors.\033[0m"
- if [[ "$failures" -gt 0 ]]; then exit 1; else exit 0; fi
artifacts:
paths:
- exist-app/test/test-results.xml
......
......@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.11.0] - 2020-09-22
### Changed
- In order to improve the clearity of the application, `tapi.xqm` now only holds the RESTXQ endpoints of the TextAPI.
All further functionality has been moved to separate module and furnished with tests.
- The test runner has been designed to be self-reporting, i.e. only faulty results are displayed fully.
## [1.10.1] - 2020-09-24
### Fixed
- Faulty link to OpenAPI documentation of the RESTXQ endpoints has been corrected.
## [1.10.0] - 2020-09-18
### Added
......
......@@ -121,7 +121,7 @@ The frontend takes care of the data transfer as described in the [frontend's REA
## API documentation
The backend comes shipped with an OpenAPI documentation of its API.
The docs are available at <https://ahikar-dev.uni-goettingen.de/openapi>.
The docs are available at <https://ahikar-dev.sub.uni-goettingen.de/openapi>.
### Interplay of TextAPI and AnnotationAPI
......
project.name=https://ahikar-test.sub.uni-goettingen.de/
project.version=1.10.0
project.version=1.11.0
project.title=TextAPI for Ahikar
project.abbrev=ahikar-test
project.processorversion=5.2.0
......
xquery version "3.1";
(:~
: This module provides the TextAPI for Ahikar.
: This module provides the Annotation Layer via TextAPI for Ahikar.
:
: @author Michelle Weidling
: @version 1.8.1
......
......@@ -2,6 +2,9 @@ xquery version "3.1";
module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons";
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare variable $commons:expath-pkg := doc("../expath-pkg.xml");
declare variable $commons:version := $commons:expath-pkg/*/@version;
declare variable $commons:tg-collection := "/db/apps/sade/textgrid";
......@@ -15,4 +18,29 @@ declare variable $commons:responseHeader200 :=
<http:response xmlns:http="http://expath.org/ns/http-client" status="200">
<http:header name="Access-Control-Allow-Origin" value="*"/>
</http:response>
</rest:response>;
\ No newline at end of file
</rest:response>;
declare function commons:get-aggregation($manifest-uri as xs:string)
as document-node() {
doc($commons:agg || $manifest-uri || ".xml")
};
declare function commons:get-xml-uri($manifest-uri as xs:string)
as xs:string {
let $aggregation-file := commons:get-aggregation($manifest-uri)
return
$aggregation-file//ore:aggregates[1]/@rdf:resource
=> substring-after(":")
};
declare function commons:get-tei-xml-for-manifest($manifest-uri as xs:string)
as document-node() {
let $xml-uri := commons:get-xml-uri($manifest-uri)
return
doc($commons:data || $xml-uri || ".xml")
};
declare function commons:open-tei-xml($tei-xml-uri as xs:string)
as document-node() {
doc($commons:data || $tei-xml-uri || ".xml")
};
\ No newline at end of file
......@@ -6,39 +6,13 @@ xquery version "3.1";
: /textapi/ahikar/3r9ps/collection.json
:)
module namespace t-coll="http://ahikar.sub.uni-goettingen.de/ns/tapi/collection";
module namespace tapi-coll="http://ahikar.sub.uni-goettingen.de/ns/tapi/collection";
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "commons.xqm";
import module namespace requestr="http://exquery.org/ns/request";
import module namespace rest="http://exquery.org/ns/restxq";
declare variable $t-coll:server :=
if(requestr:hostname() = "existdb") then
$commons:expath-pkg/*/@name => replace("/$", "")
else
"http://localhost:8094/exist/restxq";
(:~
: @see https://subugoe.pages.gwdg.de/emo/text-api/page/specs/#collection
: @see https://subugoe.pages.gwdg.de/emo/text-api/page/specs/#collection-object
: @param $collection-uri The unprefixed TextGrid URI of a collection, e.g. '3r132'
: @return A collection object as JSON
:)
declare
%rest:GET
%rest:HEAD
%rest:path("/textapi/ahikar/{$collection-uri}/collection.json")
%output:method("json")
function t-coll:endpoint($collection-uri as xs:string)
as item()+ {
$commons:responseHeader200,
t-coll:get-json($collection-uri, $t-coll:server)
};
(:~
: Returns information about the main collection for the project. This encompasses
......@@ -53,13 +27,13 @@ as item()+ {
: @param $server A string indicating the server. This parameter has been introduced to make this function testable.
: @return An object element containing all necessary information
:)
declare function t-coll:get-json($collection-uri as xs:string,
declare function tapi-coll:get-json($collection-uri as xs:string,
$server as xs:string)
as item()+ {
let $metadata-file := t-coll:get-metadata-file($collection-uri)
let $format-type := t-coll:get-format-type($metadata-file)
let $sequence := t-coll:make-sequence($collection-uri, $server)
let $annotationCollection-uri := t-coll:make-annotationCollection-uri($server, $collection-uri)
let $metadata-file := tapi-coll:get-metadata-file($collection-uri)
let $format-type := tapi-coll:get-format-type($metadata-file)
let $sequence := tapi-coll:make-sequence($collection-uri, $server)
let $annotationCollection-uri := tapi-coll:make-annotationCollection-uri($server, $collection-uri)
return
<object>
......@@ -86,7 +60,7 @@ as item()+ {
</object>
};
declare function t-coll:get-aggregation($collection-uri as xs:string)
declare function tapi-coll:get-aggregation($collection-uri as xs:string)
as document-node() {
doc($commons:agg || $collection-uri || ".xml")
};
......@@ -102,7 +76,7 @@ as document-node() {
: @return A list of ore:aggregates without the manifests to be excluded
:
:)
declare function t-coll:get-allowed-manifest-uris($aggregation-file as node())
declare function tapi-coll:get-allowed-manifest-uris($aggregation-file as node())
as xs:string+ {
let $not-allowed :=
(
......@@ -113,29 +87,29 @@ as xs:string+ {
$aggregate[@rdf:resource != $not-allowed]/@rdf:resource
return
for $uri in $allowed return
t-coll:remove-textgrid-prefix($uri)
tapi-coll:remove-textgrid-prefix($uri)
};
declare function t-coll:remove-textgrid-prefix($uri as xs:string)
declare function tapi-coll:remove-textgrid-prefix($uri as xs:string)
as xs:string {
replace($uri, "textgrid:", "")
};
declare function t-coll:get-metadata-file($uri as xs:string)
declare function tapi-coll:get-metadata-file($uri as xs:string)
as document-node() {
doc($commons:meta || $uri || ".xml")
};
declare function t-coll:make-sequence($collection-uri as xs:string,
declare function tapi-coll:make-sequence($collection-uri as xs:string,
$server as xs:string)
as element(sequence)+ {
let $aggregation := t-coll:get-aggregation($collection-uri)
let $allowed-manifest-uris := t-coll:get-allowed-manifest-uris($aggregation/*)
let $aggregation := tapi-coll:get-aggregation($collection-uri)
let $allowed-manifest-uris := tapi-coll:get-allowed-manifest-uris($aggregation/*)
for $manifest-uri in $allowed-manifest-uris return
let $manifest-metadata := t-coll:get-metadata-file($manifest-uri)
let $id := t-coll:make-id($server, $collection-uri, $manifest-uri)
let $type := t-coll:make-format-type($manifest-metadata)
let $manifest-metadata := tapi-coll:get-metadata-file($manifest-uri)
let $id := tapi-coll:make-id($server, $collection-uri, $manifest-uri)
let $type := tapi-coll:make-format-type($manifest-metadata)
return
<sequence>
<id>{$id}</id>
......@@ -143,20 +117,20 @@ as element(sequence)+ {
</sequence>
};
declare function t-coll:make-id($server as xs:string,
declare function tapi-coll:make-id($server as xs:string,
$collection-uri as xs:string,
$manifest-uri as xs:string)
as xs:string {
$server || "/api/textapi/ahikar/" || $collection-uri || "/" || $manifest-uri || "/manifest.json"
};
declare function t-coll:get-format-type($metadata as document-node())
declare function tapi-coll:get-format-type($metadata as document-node())
as xs:string {
$metadata//tgmd:format[1]/string()
=> t-coll:make-format-type()
=> tapi-coll:make-format-type()
};
declare function t-coll:make-format-type($tgmd-format as xs:string)
declare function tapi-coll:make-format-type($tgmd-format as xs:string)
as xs:string {
switch ($tgmd-format)
case "text/tg.aggregation+xml" return "collection"
......@@ -164,7 +138,7 @@ as xs:string {
default return "manifest"
};
declare function t-coll:make-annotationCollection-uri($server as xs:string,
declare function tapi-coll:make-annotationCollection-uri($server as xs:string,
$collection-uri as xs:string)
as xs:string {
$server || "/api/textapi/ahikar/" || $collection-uri || "/annotationCollection.json"
......
xquery version "3.1";
(:
: This module is for preparing the HTML serialization of a
: given TEI document or fragment.
:)
module namespace tapi-html="http://ahikar.sub.uni-goettingen.de/ns/tapi/html";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "commons.xqm";
import module namespace fragment="https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery" at "fragment.xqm";
(:~
: Initiates the HTML serialization of a given page.
:
: @param $manifest-uri The unprefixed TextGrid URI of a document, e.g. '3rbmb'
: @param $page The page to be rendered. This has to be the string value of a tei:pb/@n in the given document, e.g. '1a'
: @return A div wrapper containing the rendered page
:)
declare function tapi-html:get-html($tei-xml-uri as xs:string,
$page as xs:string)
as element(div) {
let $tei-xml-base-uri := $commons:data || $tei-xml-uri || ".xml"
let $fragment :=
if ($page) then
tapi-html:get-page-fragment($tei-xml-base-uri, $page)
else
doc($tei-xml-base-uri)/*
return
tapi-html:get-html-from-fragment($fragment)
};
declare function tapi-html:get-page-fragment($tei-xml-base-uri as xs:string,
$page as xs:string)
as element() {
let $node := doc($tei-xml-base-uri)/*
=> tapi-html:add-IDs(),
$start-node := $node//tei:pb[@n = $page and @facs],
$end-node := tapi-html:get-end-node($start-node),
$wrap-in-first-common-ancestor-only := false(),
$include-start-and-end-nodes := false(),
$empty-ancestor-elements-to-include := ("")
return
fragment:get-fragment-from-doc(
$node,
$start-node,
$end-node,
$wrap-in-first-common-ancestor-only,
$include-start-and-end-nodes,
$empty-ancestor-elements-to-include)
};
declare function tapi-html:add-IDs($nodes as node()*)
as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case comment() return
()
case processing-instruction() return
$node
default return
element {QName("http://www.tei-c.org/ns/1.0", local-name($node))} {
attribute id {generate-id($node)},
$node/@*,
tapi-html:add-IDs($node/node())
}
};
declare function tapi-html:get-end-node($start-node as element(tei:pb))
as element() {
let $following-pb := $start-node/following::tei:pb[1][@facs]
return
if($following-pb) then
$following-pb
else
$start-node/following::tei:ab[last()]
};
declare function tapi-html:get-html-from-fragment($fragment as element())
as element(xhtml:div) {
let $stylesheet := doc("/db/apps/sade_assets/TEI-Stylesheets/html5/html5.xsl")
return
(: this wrapping is necessary in order to correctly set the namespace.
otherwise, error XQST0070 is raised during the tests. :)
element xhtml:div {
attribute class {"tei_body"},
transform:transform($fragment, $stylesheet, ())/xhtml:body//xhtml:div[@class = "tei_body"]/*
}
};
xquery version "3.1";
(:
: This module handles calls to the API on item level, e.g.
:
: /textapi/ahikar/3r9ps/3rx15-8a/latest/item.json
:)
module namespace tapi-item="http://ahikar.sub.uni-goettingen.de/ns/tapi/item";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "commons.xqm";
declare function tapi-item:get-json($collection-uri as xs:string,
$manifest-uri as xs:string,
$page as xs:string,
$server as xs:string)
as element(object) {
<object>
<textapi>{$commons:version}</textapi>
<title>{tapi-item:make-title($manifest-uri)}</title>
<type>page</type>
<n>{$page}</n>
<content>{$server}/api/content/{commons:get-xml-uri($manifest-uri)}-{$page}.html</content>
<content-type>application/xhtml+xml</content-type>
{tapi-item:make-language-elements($manifest-uri)}
<x-langString>{tapi-item:get-language-string($manifest-uri)}</x-langString>
<image>
<id>{tapi-item:make-facsimile-id($manifest-uri, $page, $server)}</id>
</image>
<annotationCollection>{$server}/api/textapi/ahikar/{$collection-uri}/{$manifest-uri}-{$page}/annotationCollection.json</annotationCollection>
</object>
};
declare function tapi-item:make-title($manifest-uri)
as xs:string {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
return
$tei-xml//tei:title[@type = "main"]/string()
};
declare function tapi-item:make-language-elements($manifest-uri as xs:string)
as element()+ {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
let $languages := $tei-xml//tei:language
return
for $lang in $languages return
if ($lang[@xml:base = "https://iso639-3.sil.org/code/"]) then
element lang {$lang/@ident/string()}
else
element langAlt {$lang/@ident/string()}
};
declare function tapi-item:get-language-string($manifest-uri as xs:string)
as xs:string {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
let $langString :=
for $lang in $tei-xml//tei:language/text()
order by $lang
return $lang
return
string-join($langString, ", ")
};
declare function tapi-item:make-facsimile-id($manifest-uri as xs:string,
$page as xs:string,
$server as xs:string)
as xs:string {
let $image-uri := tapi-item:get-facsimile-uri-for-page($manifest-uri, $page)
return
$server || "/api/images/" || $image-uri
};
declare function tapi-item:get-facsimile-uri-for-page($manifest-uri as xs:string,
$page as xs:string)
as xs:string {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
return
$tei-xml//tei:pb[@n = $page]/@facs
=> substring-after("textgrid:")
};
xquery version "3.1";
(:
: This module handles calls to the API on manifest level, e.g.
:
: /textapi/ahikar/3r9ps/3rx15/manifest.json
:)
module namespace tapi-mani="http://ahikar.sub.uni-goettingen.de/ns/tapi/manifest";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "commons.xqm";
declare function tapi-mani:get-json($collection-uri as xs:string,
$manifest-uri as xs:string,
$server as xs:string)
as element(object) {
<object>
<textapi>{$commons:version}</textapi>
<id>{$server || "/api/textapi/ahikar/" || $collection-uri || "/" || $manifest-uri || "/manifest.json"}</id>
<label>{tapi-mani:get-manifest-title($manifest-uri)}</label>
{
tapi-mani:make-editors($manifest-uri),
tapi-mani:make-creation-date($manifest-uri),
tapi-mani:make-origin($manifest-uri),
tapi-mani:make-current-location($manifest-uri)
}
<license>CC0-1.0</license>
<annotationCollection>{$server}/api/textapi/ahikar/{$collection-uri}/{$manifest-uri}/annotationCollection.json</annotationCollection>
{tapi-mani:make-sequences($collection-uri, $manifest-uri, $server)}
</object>
};
declare function tapi-mani:make-sequences($collection-uri as xs:string,
$manifest-uri as xs:string,
$server as xs:string)
as element(sequence)+ {
let $valid-pages := tapi-mani:get-valid-page-ids($manifest-uri)
return
for $page in $valid-pages
let $uri := "/api/textapi/ahikar/" || $collection-uri || "/" || $manifest-uri || "-" || $page || "/latest/item.json"
return
<sequence>
<id>{$server}{$uri}</id>
<type>item</type>
</sequence>
};
declare function tapi-mani:get-valid-page-ids($manifest-uri as xs:string)
as xs:string+ {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
return
$tei-xml//tei:pb[@facs]/string(@n)
};
declare function tapi-mani:get-manifest-title($manifest-uri as xs:string)
as xs:string {
let $metadata-file := tapi-mani:get-metadata-file($manifest-uri)
return
$metadata-file//tgmd:title/string()
};
declare function tapi-mani:get-metadata-file($manifest-uri as xs:string)
as document-node() {
doc($commons:tg-collection || "/meta/" || $manifest-uri || ".xml")
};
declare function tapi-mani:make-editors($manifest-uri as xs:string)
as element(x-editor)+ {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
let $editors := $tei-xml//tei:titleStmt//tei:editor
return
if (exists($editors)) then
for $editor in $editors
return
<x-editor>
<role>editor</role>
<name>{$editor/string()}</name>
</x-editor>
else
<x-editor>
<name>none</name>
</x-editor>
};
declare function tapi-mani:make-creation-date($manifest-uri as xs:string)
as element(x-date) {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
let $creation-date := $tei-xml//tei:history//tei:date
let $string :=
if ($creation-date) then
$creation-date/string()
else
"unknown"
return
<x-date>{$string}</x-date>
};
declare function tapi-mani:make-origin($manifest-uri as xs:string) as
element(x-origin) {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
let $country := $tei-xml//tei:history//tei:country
let $place := $tei-xml//tei:history//tei:placeName
let $string :=
if ($country and $place) then
$place/string() || ", " || $country/string()
else if ($country) then
$country/string()
else if($place) then
$place/string()
else
"unknown"
return
<x-origin>{$string}</x-origin>
};
declare function tapi-mani:make-current-location($manifest-uri as xs:string) as
element(x-location) {
let $tei-xml := commons:get-tei-xml-for-manifest($manifest-uri)
let $institution := $tei-xml//tei:msIdentifier//tei:institution
let $country := $tei-xml//tei:msIdentifier//tei:country
let $string :=
if ($country and $institution) then
$institution || ", " || $country
else if ($country) then
$country/string()
else if($institution) then
$institution/string()
else
"unknown"
return
<x-location>{$string}</x-location>
};
\ No newline at end of file
......@@ -7,43 +7,46 @@ xquery version "3.1";
: pipelines.
:)
module namespace coll="http://ahikar.sub.uni-goettingen.de/ns/collate";
module namespace tapi-txt="http://ahikar.sub.uni-goettingen.de/ns/tapi/txt";
declare namespace ore="http://www.openarchives.org/ore/terms/";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "commons.xqm";
import module namespace fragment="https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery" at "fragment.xqm";
declare variable $coll:textgrid := "/db/apps/sade/textgrid";
declare variable $coll:data := $coll:textgrid || "/data";
declare variable $coll:txt := $coll:textgrid || "/txt";
declare variable $tapi-txt:textgrid := "/db/apps/sade/textgrid";
declare variable $tapi-txt:data := $tapi-txt:textgrid || "/data";
declare variable $tapi-txt:txt := $tapi-txt:textgrid || "/txt";
declare function coll:main()
declare function tapi-txt:main()
as xs:string+ {
coll:create-txt-collection-if-not-available(),
for $text in coll:get-transcriptions-and-transliterations() return
let $relevant-text := coll:get-relevant-text($text)
let $file-name := coll:make-file-name($text)
tapi-txt:create-txt-collection-if-not-available(),
for $text in tapi-txt:get-transcriptions-and-transliterations() return
let $relevant-text := tapi-txt:get-relevant-text($text)
let $file-name := tapi-txt:make-file-name($text)
return
xmldb:store($coll:txt, $file-name, $relevant-text, "text/plain")
xmldb:store($tapi-txt:txt, $file-name, $relevant-text, "text/plain")
};
declare function coll:create-txt-collection-if-not-available()
declare function tapi-txt:create-txt-collection-if-not-available()
as xs:string? {
if (xmldb:collection-available($coll:txt)) then
if (xmldb:collection-available($tapi-txt:txt)) then
()
else
xmldb:create-collection($coll:textgrid, "txt")
xmldb:create-collection($tapi-txt:textgrid, "txt")
};
declare function coll:get-transcriptions-and-transliterations()
declare function tapi-txt:get-transcriptions-and-transliterations()
as element(tei:text)+ {
collection($coll:data)//tei:text[@type = ("transcription", "transliteration")]
[coll:has-text-milestone(.)]
collection($tapi-txt:data)//tei:text[@type = ("transcription", "transliteration")]
[tapi-txt:has-text-milestone(.)]
};
declare function coll:has-text-milestone($text as element(tei:text))
declare function tapi-txt:has-text-milestone($text as element(tei:text))
as xs:boolean {
if ($text//tei:milestone) then
true()
......@@ -55,16 +58,16 @@ as xs:boolean {
: An example for the file name is
: syriac-Brit_Lib_Add_7200-3r131-transcription.txt
:)
declare function coll:make-file-name($text as element(tei:text))
declare function tapi-txt:make-file-name($text as element(tei:text))
as xs:string {
let $lang-prefix := coll:get-language-prefix($text)
let $title-from-metadata := coll:create-metadata-title-for-file-name($text)
let $uri-plus-text-type := coll:make-file-name-suffix($text)
let $lang-prefix := tapi-txt:get-language-prefix($text)
let $title-from-metadata := tapi-txt:create-metadata-title-for-file-name($text)
let $uri-plus-text-type := tapi-txt:make-file-name-suffix($text)
return
$lang-prefix || "-" || $title-from-metadata || "-" || $uri-plus-text-type
};
declare function coll:get-language-prefix($text as element(tei:text))
declare function tapi-txt:get-language-prefix($text as element(tei:text))
as xs:string? {
switch ($text/@type)
case "transcription" return
......@@ -85,9 +88,9 @@ as xs:string? {
default return ()
};
declare function coll:create-metadata-title-for-file-name($text as element(tei:text))
declare function tapi-txt:create-metadata-title-for-file-name($text as element(tei:text))
as xs:string {
let $base-uri := coll:get-base-uri($text)
let $base-uri := tapi-txt:get-base-uri($text)
let $metadata := doc($base-uri => replace("/data/", "/meta/"))
return
$metadata//tgmd:title
......@@ -95,50 +98,50 @@ as xs:string {
=> replace("[_]+", "_")
};
declare function coll:get-base-uri($text as element(tei:text))
declare function tapi-txt:get-base-uri($text as element(tei:text))
as xs:string{
base-uri($text)
};
declare function coll:make-file-name-suffix($text as element(tei:text))
declare function tapi-txt:make-file-name-suffix($text as element(tei:text))
as xs:string {
let $base-uri := coll:get-base-uri($text)
let $file-name := coll:get-file-name($base-uri)
let $base-uri := tapi-txt:get-base-uri($text)
let $file-name := tapi-txt:get-file-name($base-uri)
let $type := $text/@type
return
$file-name || "-" || $type || ".txt"
};
declare function coll:get-file-name($base-uri as xs:string)
declare function tapi-txt:get-file-name($base-uri as xs:string)
as xs:string {
tokenize($base-uri, "/")[last()]
=> substring-before(".xml")
};
declare function coll:get-relevant-text($text as element(tei:text))
declare function tapi-txt:get-relevant-text($text as element(tei:text))
as xs:string {
let $milestones := coll:get-milestones-in-text($text)
let $chunks := coll:get-chunks($milestones)
let $texts := coll:get-relevant-text-from-chunks($chunks)
let $milestones := tapi-txt:get-milestones-in-text($text)
let $chunks := tapi-txt:get-chunks($milestones)
let $texts := tapi-txt:get-relevant-text-from-chunks($chunks)
return
string-join($texts, " ")
};
declare function coll:get-milestones-in-text($text as element(tei:text))
declare function tapi-txt:get-milestones-in-text($text as element(tei:text))
as element(tei:milestone)+ {
$text//tei:milestone
};
declare function coll:get-chunks($milestones as element(tei:milestone)+)
declare function tapi-txt:get-chunks($milestones as element(tei:milestone)+)
as element(tei:TEI)+ {
for $milestone in $milestones return
coll:get-chunk($milestone)
tapi-txt:get-chunk($milestone)
};
declare function coll:get-chunk($milestone as element(tei:milestone))
declare function tapi-txt:get-chunk($milestone as element(tei:milestone))
as element(tei:TEI) {
let $root := $milestone/root()
let $end-of-chunk := coll:get-end-of-chunk($milestone)
let $end-of-chunk := tapi-txt:get-end-of-chunk($milestone)
return
fragment:get-fragment-from-doc(
$root,
......@@ -149,15 +152,15 @@ as element(tei:TEI) {
(""))
};
declare function coll:get-end-of-chunk($milestone as element(tei:milestone))
declare function tapi-txt:get-end-of-chunk($milestone as element(tei:milestone))
as node() {
if (coll:has-following-milestone($milestone)) then
coll:get-next-milestone($milestone)
if (tapi-txt:has-following-milestone($milestone)) then
tapi-txt:get-next-milestone($milestone)
else
$milestone/ancestor::tei:text[1]/tei:body/child::*[last()]
};
declare function coll:has-following-milestone($milestone as element(tei:milestone))
declare function tapi-txt:has-following-milestone($milestone as element(tei:milestone))
as xs:boolean {
if ($milestone/following::tei:milestone[ancestor::tei:text[1] = $milestone/ancestor::tei:text[1]]) then
true()
......@@ -165,29 +168,29 @@ as xs:boolean {
false()
};
declare function coll:get-next-milestone($milestone as element(tei:milestone))
declare function tapi-txt:get-next-milestone($milestone as element(tei:milestone))
as element(tei:milestone)? {
$milestone/following::tei:milestone[ancestor::tei:text[1] = $milestone/ancestor::tei:text[1]][1]
};
declare function coll:get-relevant-text-from-chunks($chunks as element(tei:TEI)+)
declare function tapi-txt:get-relevant-text-from-chunks($chunks as element(tei:TEI)+)
as xs:string {
let $texts :=
for $chunk in $chunks return
coll:make-plain-text-from-chunk($chunk)
tapi-txt:make-plain-text-from-chunk($chunk)
return
string-join($texts, " ")
=> normalize-space()
};
declare function coll:make-plain-text-from-chunk($chunk as element(tei:TEI))
declare function tapi-txt:make-plain-text-from-chunk($chunk as element(tei:TEI))
as xs:string {
let $texts := coll:get-relevant-text-nodes($chunk)
let $texts := tapi-txt:get-relevant-text-nodes($chunk)
let $prepared-texts :=
for $text in $texts return
coll:prepare-plain-text-creation($text)
tapi-txt:prepare-plain-text-creation($text)
return
coll:format-and-normalize-string($prepared-texts)
tapi-txt:format-and-normalize-string($prepared-texts)
};
(:~
......@@ -201,7 +204,7 @@ as xs:string {
: * catchwords (they simply serve to bind the books correctly and reduplicate text)
: * note (they have been added later by another scribe)
:)
declare function coll:get-relevant-text-nodes($chunk as element(tei:TEI))
declare function tapi-txt:get-relevant-text-nodes($chunk as element(tei:TEI))
as text()+ {
(($chunk//text()
[not(parent::tei:sic)]
......@@ -214,7 +217,7 @@ as text()+ {
[not(parent::tei:note)]
};
declare function coll:prepare-plain-text-creation($text as text())
declare function tapi-txt:prepare-plain-text-creation($text as text())
as xs:string {
if ($text/preceding-sibling::*[1][self::tei:lb[@break = "no"]]) then
"@" || $text
......@@ -222,10 +225,92 @@ as xs:string {
$text
};
declare function coll:format-and-normalize-string($strings as xs:string+)
declare function tapi-txt:format-and-normalize-string($strings as xs:string+)
as xs:string {
string-join($strings, " ")
=> replace(" @", "")
=> replace("[\p{P}\n+]", "")
=> replace("\s+", " ")
};
(:~
: Returns the tei:text of a document as indicated by the @type parameter.
:
: Due to the structure of the Ahikar project we can pass either an edition or
: an XML file to the API endpoint for plain text creation.
: This function determines the correct file which serves as a basis for the plain text.
:
: @param $document The URI of a resource
: @param $type Indicates the @type of tei:text to be processed
: @return The tei:text element to be serialized as plain text
:)
declare function tapi-txt:get-TEI-text($document-uri as xs:string,
$type as xs:string)
as element(tei:text) {
if (tapi-txt:is-document-tei-xml($document-uri)) then
commons:open-tei-xml($document-uri)//tei:text[@type = $type]
else
tapi-txt:get-tei-xml-uri-from-edition
=> tapi-txt:get-text-of-type($type)
};
declare function tapi-txt:is-document-tei-xml($document-uri as xs:string) {
let $format := tapi-txt:get-format($document-uri)
return
if ($format = "text/xml") then
true()
else
false()
};
(:~
: Returns the TextGrid metadata type of a resource.
:
: @param $uri The URI of the resource
: @return The resource's format as tgmd:format
:)
declare function tapi-txt:get-format($uri as xs:string) as xs:string {
doc($commons:meta || $uri || ".xml")//tgmd:format
};
declare function tapi-txt:get-tei-xml-uri-from-edition($document-uri as xs:string)
as xs:string {
let $aggregates := tapi-txt:get-edition-aggregates-without-uri-namespace($document-uri)
return
tapi-txt:get-tei-xml-from-aggregates($aggregates)
};
declare function tapi-txt:get-edition-aggregates-without-uri-namespace($document-uri as xs:string)
as xs:string+ {
let $edition := commons:get-aggregation($document-uri)
for $agg in $edition//ore:aggregates/@rdf:resource return
replace($agg, "textgrid:", "")
};
declare function tapi-txt:get-tei-xml-from-aggregates($aggregates as xs:string+)
as xs:string {
for $agg in $aggregates return
if (tapi-txt:get-format($agg) = "text/xml") then
$agg
else
()
};
declare function tapi-txt:get-text-of-type($uri as xs:string,
$type as xs:string)
as element(tei:text) {
commons:open-tei-xml($uri)//tei:text[@type = $type]
};
declare function tapi-txt:compress-to-zip()
as xs:base64Binary* {
compression:zip(xs:anyURI($commons:tg-collection || "/txt/"), false())
};
\ No newline at end of file
This diff is collapsed.
......@@ -6,7 +6,6 @@ xquery version "3.1";
: since at this point the RESTXQ API isn't fired up yet which causes the tests to throw errors.
:
: @author Michelle Weidling
: @version 0.1.0
: @since 0.4.0
:)
......@@ -14,7 +13,14 @@ module namespace testtrigger="http://ahikar.sub.uni-goettingen.de/ns/testtrigger
import module namespace rest="http://exquery.org/ns/restxq";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace tests="http://ahikar.sub.uni-goettingen.de/ns/tapi/tests" at "../tests.xqm";
import module namespace ttt="http://ahikar.sub.uni-goettingen.de/ns/tapi/txt/tests" at "../tests/tapi-txt-tests.xqm";
import module namespace ct="http://ahikar.sub.uni-goettingen.de/ns/commons-tests" at "../tests/commons-tests.xqm";
import module namespace tct="http://ahikar.sub.uni-goettingen.de/ns/tapi/collection/tests" at "../tests/tapi-collection-tests.xqm";
import module namespace thtmlt="http://ahikar.sub.uni-goettingen.de/ns/tapi/html/tests" at "../tests/tapi-html-tests.xqm";
import module namespace titemt="http://ahikar.sub.uni-goettingen.de/ns/tapi/item/tests" at "../tests/tapi-item-tests.xqm";
import module namespace tmt="http://ahikar.sub.uni-goettingen.de/ns/tapi/manifest/tests" at "../tests/tapi-manifest-tests.xqm";
import module namespace tt="http://ahikar.sub.uni-goettingen.de/ns/tapi/tests" at "../tests/tapi-tests.xqm";
(:~
: Triggers the tests for the Ahikar backend. Called by the CI.
......@@ -33,7 +39,16 @@ as item()? {
then error(QName("error://1", "deploy"), "Deploy token incorrect.")
else
let $sysout := util:log-system-out("TextAPI and package installation done. running tests…")
let $tests := test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/tests"))
let $tests :=
(
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/txt/tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/commons-tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/collection/tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/manifest/tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/item/tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/html/tests"))
)
let $fileSeparator := util:system-property("file.separator")
let $system-path := system:get-exist-home() || $fileSeparator
......
xquery version "3.1";
(:~
: Script providing access to the test functions (XQSuite) for local unit test
: execution.
:)
import module namespace tct="http://ahikar.sub.uni-goettingen.de/ns/tapi/collection/tests" at "tests/tapi-collection-tests.xqm";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace tests="http://ahikar.sub.uni-goettingen.de/ns/tapi/tests" at "tests.xqm";
import module namespace coll-tests="http://ahikar.sub.uni-goettingen.de/ns/coll-tests" at "tests/collate-tests.xqm";
import module namespace ct="http://ahikar.sub.uni-goettingen.de/ns/commons-tests" at "tests/commons-tests.xqm";
(: test API endpoints :)
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/coll-tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/commons-tests")),
test:suite(util:list-functions("http://ahikar.sub.uni-goettingen.de/ns/tapi/collection/tests"))
\ No newline at end of file
......@@ -5,13 +5,36 @@ module namespace ct="http://ahikar.sub.uni-goettingen.de/ns/commons-tests";
declare namespace http = "http://expath.org/ns/http-client";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "../modules/commons.xqm";
import module namespace map="http://www.w3.org/2005/xpath-functions/map";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
declare variable $ct:restxq := "http://0.0.0.0:8080/exist/restxq/";
declare
%test:assertTrue
function ct:succes() {
true()
};
\ No newline at end of file
%test:args("ahiqar_agg") %test:assertXPath("$result//@* = 'textgrid:ahiqar_sample'")
function ct:get-aggregation($manifest-uri as xs:string) {
commons:get-aggregation($manifest-uri)
};
declare
%test:args("ahiqar_agg") %test:assertEquals("ahiqar_sample")
function ct:get-xml-uri($manifest-uri as xs:string)
as xs:string {
commons:get-xml-uri($manifest-uri)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("$result//*[local-name(.) = 'title'] = 'The Proverbs or History of Aḥīḳar the wise, the scribe of Sanḥērībh,
king of Assyria and Nineveh'")
function ct:get-tei-xml-for-manifest($manifest-uri) {
commons:get-tei-xml-for-manifest($manifest-uri)
};
declare
%test:args("ahiqar_sample") %test:assertXPath("$result//*[local-name(.) = 'TEI']")
function ct:open-tei-xml($tei-xml-uri as xs:string)
as document-node() {
commons:open-tei-xml($tei-xml-uri)
};
......@@ -7,11 +7,11 @@ declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "../modules/commons.xqm";
import module namespace map="http://www.w3.org/2005/xpath-functions/map";
import module namespace tc="http://ahikar.sub.uni-goettingen.de/ns/tests/commons" at "test-commons.xqm";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace t-coll="http://ahikar.sub.uni-goettingen.de/ns/tapi/collection" at "../modules/tapi-collection.xqm";
import module namespace tapi-coll="http://ahikar.sub.uni-goettingen.de/ns/tapi/collection" at "../modules/tapi-collection.xqm";
declare variable $tct:restxq := "http://0.0.0.0:8080/exist/restxq";
declare variable $tct:collection-uri := "test-collection.xml";
declare variable $tct:collection-uri := "testapi-collection.xml";
declare variable $tct:agg1-uri := "test-aggregation-1.xml";
declare variable $tct:agg2-uri := "test-aggregation-2.xml";
......@@ -21,7 +21,7 @@ function tct:_test-setup(){
let $collection :=
<rdf:RDF xmlns:ore="http://www.openarchives.org/ore/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="textgrid:test-collection">
<rdf:Description rdf:about="textgrid:testapi-collection">
<ore:aggregates rdf:resource="textgrid:test-aggregation-1"/>
<ore:aggregates rdf:resource="textgrid:test-aggregation-2"/>
</rdf:Description>
......@@ -102,18 +102,10 @@ function tct:_test-teardown() {
xmldb:remove($commons:meta, $tct:agg2-uri)
};
declare
%test:assertTrue
function tct:is-endpoint-available() {
let $url := $tct:restxq || "/textapi/ahikar/ahiqar_collection/collection.json"
return
local:is-endpoint-http200($url)
};
declare
%test:args("ahiqar_collection") %test:assertXPath("$result//*[local-name(.) = 'aggregates']")
function tct:get-aggregation($uri as xs:string) {
t-coll:get-aggregation($uri)
tapi-coll:get-aggregation($uri)
};
declare
......@@ -129,7 +121,7 @@ function tct:get-allowed-manifest-uris-mock-up-input-included() {
</rdf:Description>
</rdf:RDF>
return
t-coll:get-allowed-manifest-uris($collection-metadata) = "3rx14"
tapi-coll:get-allowed-manifest-uris($collection-metadata) = "3rx14"
};
declare
......@@ -145,7 +137,7 @@ function tct:get-allowed-manifest-uris-mock-up-input-excluded() {
</rdf:Description>
</rdf:RDF>
return
t-coll:get-allowed-manifest-uris($collection-metadata) = "3vp38"
tapi-coll:get-allowed-manifest-uris($collection-metadata) = "3vp38"
};
......@@ -153,22 +145,22 @@ declare
%test:args("ahiqar_collection", "ahiqar_agg") %test:assertEquals("http://0.0.0.0:8080/exist/restxq/api/textapi/ahikar/ahiqar_collection/ahiqar_agg/manifest.json")
function tct:make-id($colletion-uri as xs:string, $manifest-uri as xs:string)
as xs:string {
t-coll:make-id($tct:restxq, $colletion-uri, $manifest-uri)
tapi-coll:make-id($tc:server, $colletion-uri, $manifest-uri)
};
declare
%test:assertEquals("ahiqar_agg")
function tct:get-allowed-manifest-uris-sample-input() {
let $collection-metadata := t-coll:get-aggregation("ahiqar_collection")
let $collection-metadata := tapi-coll:get-aggregation("ahiqar_collection")
return
t-coll:get-allowed-manifest-uris($collection-metadata)
tapi-coll:get-allowed-manifest-uris($collection-metadata)
};
declare
%test:args("ahiqar_collection") %test:assertXPath("$result[self::document-node()]")
function tct:get-metadata-file($uri as xs:string) {
t-coll:get-metadata-file($uri)
tapi-coll:get-metadata-file($uri)
};
......@@ -176,7 +168,7 @@ declare
%test:args("textgrid:1234") %test:assertEquals("1234")
%test:args("1234") %test:assertEquals("1234")
function tct:remove-textgrid-prefix($uri as xs:string) {
t-coll:remove-textgrid-prefix($uri)
tapi-coll:remove-textgrid-prefix($uri)
};
declare
......@@ -184,32 +176,32 @@ declare
%test:args("text/tg.edition+tg.aggregation+xml") %test:assertEquals("manifest")
%test:args("test") %test:assertEquals("manifest")
function tct:make-format-type($tgmd-format as xs:string) {
t-coll:make-format-type($tgmd-format)
tapi-coll:make-format-type($tgmd-format)
};
declare
%test:assertEquals("manifest")
function tct:get-format-type() {
let $metadata := t-coll:get-metadata-file("ahiqar_agg")
let $metadata := tapi-coll:get-metadata-file("ahiqar_agg")
return
t-coll:get-format-type($metadata)
tapi-coll:get-format-type($metadata)
};
declare
%test:args("ahiqar_collection") %test:assertXPath("$result//type[. = 'manifest']")
%test:args("ahiqar_collection") %test:assertXPath("$result//id[matches(., 'ahiqar_agg/manifest.json')]")
%test:args("test-collection") %test:assertXPath("$result//id[matches(., 'test-aggregation-1/manifest.json')]")
%test:args("test-collection") %test:assertXPath("$result//id[matches(., 'test-aggregation-2/manifest.json')]")
%test:args("testapi-collection") %test:assertXPath("$result//id[matches(., 'test-aggregation-1/manifest.json')]")
%test:args("testapi-collection") %test:assertXPath("$result//id[matches(., 'test-aggregation-2/manifest.json')]")
function tct:make-sequence($collection-uri as xs:string) {
t-coll:make-sequence($collection-uri, $tct:restxq)
tapi-coll:make-sequence($collection-uri, $tc:server)
};
declare
%test:args("ahiqar_collection") %test:assertEquals("http://0.0.0.0:8080/exist/restxq/api/textapi/ahikar/ahiqar_collection/annotationCollection.json")
function tct:make-annotationCollection-uri($collection-uri as xs:string)
as xs:string {
t-coll:make-annotationCollection-uri($tct:restxq, $collection-uri)
tapi-coll:make-annotationCollection-uri($tc:server, $collection-uri)
};
......@@ -217,44 +209,5 @@ declare
%test:args("ahiqar_collection") %test:assertXPath("$result//title = 'The Story and Proverbs of Ahikar the Wise'")
%test:args("ahiqar_collection") %test:assertXPath("$result//*/string() = 'http://0.0.0.0:8080/exist/restxq/api/textapi/ahikar/ahiqar_collection/ahiqar_agg/manifest.json' ")
function tct:get-json($collection-uri as xs:string) {
t-coll:get-json($collection-uri, $tct:restxq)
tapi-coll:get-json($collection-uri, $tc:server)
};
declare
(: check if all parts are present.
: no further tests are needed since the content has been tested while testing
: the underlying function. :)
%test:assertXPath("map:contains($result, 'title')")
%test:assertXPath("map:contains($result, 'collector')")
%test:assertXPath("map:contains($result, 'description')")
%test:assertXPath("map:contains($result, 'sequence')")
function tct:endpoint()
as item() {
let $url := $tct:restxq || "/textapi/ahikar/ahiqar_collection/collection.json"
let $req := <http:request href="{$url}" method="get">
<http:header name="Connection" value="close"/>
</http:request>
return http:send-request($req)[2] => util:base64-decode() => parse-json()
};
declare function local:is-endpoint-http200($url as xs:string) as xs:boolean {
let $http-status := local:get-http-status($url)
return
$http-status = "200"
};
declare function local:get-http-status($url as xs:string) as xs:string {
let $req := local:make-request($url)
return
http:send-request($req)[1]/@status
};
declare function local:make-request($url as xs:string) {
<http:request href="{$url}" method="get">
<http:header name="Connection" value="close"/>
</http:request>
};
\ No newline at end of file
xquery version "3.1";
module namespace thtmlt="http://ahikar.sub.uni-goettingen.de/ns/tapi/html/tests";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "../modules/commons.xqm";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace tapi-html="http://ahikar.sub.uni-goettingen.de/ns/tapi/html" at "../modules/tapi-html.xqm";
declare
%test:assertXPath("$result//@id = 'N4'")
function thtmlt:add-IDs()
as node()+ {
let $manifest := doc($commons:data || "ahiqar_sample.xml")/*
return
tapi-html:add-IDs($manifest)
};
declare
%test:args("/db/apps/sade/textgrid/data/ahiqar_sample.xml", "82a") %test:assertXPath("$result[local-name(.) = 'pb']")
%test:args("/db/apps/sade/textgrid/data/ahiqar_sample.xml", "82a") %test:assertXPath("$result/@facs = 'textgrid:3r1p0'")
%test:args("/db/apps/sade/textgrid/data/ahiqar_sample.xml", "82a") %test:assertXPath("$result/@n = '82b'")
%test:args("/db/apps/sade/textgrid/data/ahiqar_sample.xml", "83b") %test:assertXPath("$result[local-name(.) = 'ab']")
%test:args("/db/apps/sade/textgrid/data/ahiqar_sample.xml", "83b") %test:assertXPath("matches($result, 'ܘܗܦܟܬ ܛܥܢܬ ܐܰܒܵܪܐ ܘܠܐ ܐܝܼܩܰܪ ܥܠ')")
function thtmlt:get-end-node($tei-xml-base-uri as xs:string,
$page as xs:string)
as item()+ {
let $node := doc($tei-xml-base-uri)/*
let $start-node := $node//tei:pb[@n = $page and @facs]
return
tapi-html:get-end-node($start-node)
};
declare
%test:args("/db/apps/sade/textgrid/data/ahiqar_sample.xml", "82a") %test:assertXPath("$result//*[local-name(.) = 'add'][@place = 'margin'] = 'حقًا'")
function thtmlt:get-page-fragment($tei-xml-base-uri as xs:string,
$page as xs:string)
as element() {
tapi-html:get-page-fragment($tei-xml-base-uri, $page)
};
declare
%test:args("/db/apps/sade/textgrid/data/ahiqar_sample.xml", "82a") %test:assertXPath("$result//text()[matches(., 'حقًا')]")
function thtmlt:transform-fragment($tei-xml-base-uri as xs:string,
$page as xs:string)
as element(xhtml:div) {
let $fragment := tapi-html:get-page-fragment($tei-xml-base-uri, $page)
return
tapi-html:get-html-from-fragment($fragment)
};
declare
%test:args("ahiqar_sample", "82a") %test:assertXPath("$result//text()[matches(., 'حقًا')]")
%test:args("ahiqar_sample", "82a")
(: checks if there is text at all in the result :)
%test:assertXPath("$result//text()[matches(., '[\w]')]")
(: if a div[@class = 'tei_body'] is present, the transformation has been successfull :)
%test:assertXPath("$result[@class = 'tei_body']")
(: this is some text on 82a (and thus should be part of the result) :)
%test:assertXPath("$result//* = 'ܘܬܥܐܠܝ ܕܟܪܗ ܐܠܝ ܐܠܐܒܕ. ܘܢܟܬܒ ܟܒܪ'")
(: this is some text on 83a which shouldn't be part of the result :)
%test:assertXPath("not($result//* = 'ܡܢ ܐܠܣܡܐ ܩܐܝܠܐ. ܒܚܝܬ ܐܬܟܠܬ ܐܘܠܐ ܥܠܝ ܐܠܐܨܢܐܡ' )")
function thtmlt:get-html($tei-xml-uri as xs:string,
$page as xs:string)
as element(div) {
tapi-html:get-html($tei-xml-uri, $page)
};
xquery version "3.1";
module namespace titemt="http://ahikar.sub.uni-goettingen.de/ns/tapi/item/tests";
declare namespace http = "http://expath.org/ns/http-client";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "../modules/commons.xqm";
import module namespace map="http://www.w3.org/2005/xpath-functions/map";
import module namespace tc="http://ahikar.sub.uni-goettingen.de/ns/tests/commons" at "test-commons.xqm";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace tapi-item="http://ahikar.sub.uni-goettingen.de/ns/tapi/item" at "../modules/tapi-item.xqm";
declare
%test:args("ahiqar_agg", "82a") %test:assertEquals("3r1nz")
function titemt:get-facsimile-uri-for-page($manifest-uri as xs:string,
$page as xs:string)
as xs:string {
tapi-item:get-facsimile-uri-for-page($manifest-uri, $page)
};
declare
%test:args("ahiqar_agg") %test:assertEquals("Arabic, Classical Syriac, Eastern Syriac, Karshuni, Western Syriac")
function titemt:get-language-string($manifest-uri as xs:string)
as xs:string {
tapi-item:get-language-string($manifest-uri)
};
declare
%test:args("ahiqar_agg", "82a") %test:assertEquals("http://0.0.0.0:8080/exist/restxq/api/images/3r1nz")
function titemt:make-facsimile-id($manifest-uri as xs:string,
$page as xs:string)
as xs:string {
tapi-item:make-facsimile-id($manifest-uri, $page, $tc:server)
};
declare
%test:args("ahiqar_agg") %test:assertEquals("The Proverbs or History of Aḥīḳar the wise, the scribe of Sanḥērībh,
king of Assyria and Nineveh")
function titemt:make-title($manifest-uri as xs:string)
as xs:string {
tapi-item:make-title($manifest-uri)
};
declare
%test:args("ahiqar_collection", "ahiqar_agg", "82a")
(: checks if the correct file has been opened :)
%test:assertXPath("$result//*[local-name(.) = 'title'] = 'The Proverbs or History of Aḥīḳar the wise, the scribe of Sanḥērībh,
king of Assyria and Nineveh' ")
(: checks if language assembling works correctly :)
%test:assertXPath("$result//*[local-name(.) = 'lang'] = 'syc' ")
%test:assertXPath("$result//*[local-name(.) = 'langAlt'] = 'karshuni' ")
%test:assertXPath("$result//*[local-name(.) = 'x-langString'][matches(., 'Classical Syriac')]")
(: checks if underlying pages are identified :)
%test:assertXPath("$result//*[local-name(.) = 'content'] = 'http://0.0.0.0:8080/exist/restxq/api/content/ahiqar_sample-82a.html' ")
(: checks if images connected to underlying pages are identified :)
%test:assertXPath("$result//*[local-name(.) = 'id'] = 'http://0.0.0.0:8080/exist/restxq/api/images/3r1nz' ")
function titemt:get-json($collection as xs:string,
$document as xs:string,
$page as xs:string)
as element(object){
tapi-item:get-json($collection, $document, $page, $tc:server)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("count($result) = 5")
%test:args("ahiqar_agg") %test:assertXPath("$result[local-name(.) = ('lang', 'langAlt')]")
%test:args("ahiqar_agg") %test:assertXPath("count($result[local-name(.) = 'lang']) = 2")
function titemt:make-language-elements($manifest-uri as xs:string) {
tapi-item:make-language-elements($manifest-uri)
};
\ No newline at end of file
xquery version "3.1";
module namespace tmt="http://ahikar.sub.uni-goettingen.de/ns/tapi/manifest/tests";
declare namespace http = "http://expath.org/ns/http-client";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "../modules/commons.xqm";
import module namespace map="http://www.w3.org/2005/xpath-functions/map";
import module namespace tc="http://ahikar.sub.uni-goettingen.de/ns/tests/commons" at "test-commons.xqm";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace tapi-mani="http://ahikar.sub.uni-goettingen.de/ns/tapi/manifest" at "../modules/tapi-manifest.xqm";
declare variable $tmt:manifest1 := "test-manifest1.xml";
declare variable $tmt:manifest2 := "test-manifest2.xml";
declare variable $tmt:manifest3 := "test-manifest3.xml";
declare variable $tmt:tei1-uri := "test-tei-1.xml";
declare variable $tmt:tei2-uri := "test-tei-2.xml";
declare variable $tmt:tei3-uri := "test-tei-3.xml";
declare
%test:setUp
function tmt:_test-setup(){
let $manifest1 :=
<rdf:RDF xmlns:ore="http://www.openarchives.org/ore/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="test-aggregation-1">
<ore:aggregates rdf:resource="textgrid:test-tei-1"/>
</rdf:Description>
</rdf:RDF>
let $manifest2 :=
<rdf:RDF xmlns:ore="http://www.openarchives.org/ore/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="test-aggregation-1">
<ore:aggregates rdf:resource="textgrid:test-tei-2"/>
</rdf:Description>
</rdf:RDF>
let $manifest3 :=
<rdf:RDF xmlns:ore="http://www.openarchives.org/ore/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="test-aggregation-1">
<ore:aggregates rdf:resource="textgrid:test-tei-3"/>
</rdf:Description>
</rdf:RDF>
let $tei1 :=
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title type="main">A Minimal Dummy TEI</title>
</titleStmt>
</fileDesc>
</teiHeader>
</TEI>
let $tei2 :=
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title type="main">A Minimal Dummy TEI2</title>
</titleStmt>
<sourceDesc>
<msDesc>
<msIdentifier>
<institution>University of Cambridge - Cambridge University Library</institution>
</msIdentifier>
<history>
<origin>
<country>Iraq</country>
</origin>
</history>
</msDesc>
</sourceDesc>
</fileDesc>
</teiHeader>
</TEI>
let $tei3 :=
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title type="main">A Minimal Dummy TEI3</title>
</titleStmt>
<sourceDesc>
<msDesc>
<msIdentifier>
<settlement>
<country>Great Britain</country>
</settlement>
</msIdentifier>
<history>
<origin>
<placeName>Alqosh</placeName>
</origin>
</history>
</msDesc>
</sourceDesc>
</fileDesc>
</teiHeader>
</TEI>
return
(
xmldb:store($commons:agg, $tmt:manifest1, $manifest1),
xmldb:store($commons:agg, $tmt:manifest2, $manifest2),
xmldb:store($commons:agg, $tmt:manifest3, $manifest3),
xmldb:store($commons:data, $tmt:tei1-uri, $tei1),
xmldb:store($commons:data, $tmt:tei2-uri, $tei2),
xmldb:store($commons:data, $tmt:tei3-uri, $tei3)
)
};
declare
%test:tearDown
function tmt:_test-teardown() {
xmldb:remove($commons:agg, $tmt:manifest1),
xmldb:remove($commons:agg, $tmt:manifest2),
xmldb:remove($commons:agg, $tmt:manifest3),
xmldb:remove($commons:data, $tmt:tei1-uri),
xmldb:remove($commons:data, $tmt:tei2-uri),
xmldb:remove($commons:data, $tmt:tei3-uri)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("$result//* = 'textgrid:ahiqar_agg.0'")
function tmt:get-metadata-file($manifest-uri) {
tapi-mani:get-metadata-file($manifest-uri)
};
declare
%test:args("ahiqar_collection", "ahiqar_agg") %test:assertXPath("$result//id[matches(., '/api/textapi/ahikar/ahiqar_collection/ahiqar_agg-82a/latest/item.json')]")
function tmt:make-sequences($collection-uri as xs:string,
$manifest-uri as xs:string) {
tapi-mani:make-sequences($collection-uri, $manifest-uri, $tc:server)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("count($result) = 4")
function tmt:get-valid-page-ids($manifest-uri as xs:string) {
tapi-mani:get-valid-page-ids($manifest-uri)
};
declare
%test:args("ahiqar_collection", "ahiqar_agg") %test:assertXPath("$result//label = 'Beispieldatei zum Testen'")
%test:args("ahiqar_collection", "ahiqar_agg") %test:assertXPath("$result//id[matches(., '/api/textapi/ahikar/ahiqar_collection/ahiqar_agg/manifest.json')]")
function tmt:get-json($collection-uri as xs:string,
$manifest-uri as xs:string) {
tapi-mani:get-json($collection-uri, $manifest-uri, $tc:server)
};
declare
%test:args("ahiqar_agg") %test:assertEquals("Beispieldatei zum Testen")
function tmt:get-manifest-title($manifest-uri as xs:string) {
tapi-mani:get-manifest-title($manifest-uri)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("count($result) = 2")
%test:args("ahiqar_agg") %test:assertXPath("$result//name = 'Simon Birol'")
%test:args("test-manifest1") %test:assertXPath("count($result) = 1")
%test:args("test-manifest1") %test:assertXPath("$result//name = 'none'")
function tmt:make-editors($manifest-uri as xs:string) {
tapi-mani:make-editors($manifest-uri)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("$result/string() = '18.10.1697'")
%test:args("test-manifest1") %test:assertXPath("$result/string() = 'unknown'")
function tmt:make-creation-date($manifest-uri as xs:string) {
tapi-mani:make-creation-date($manifest-uri)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("$result/string() = 'Alqosh, Iraq'")
%test:args("test-manifest1") %test:assertXPath("$result/string() = 'unknown'")
%test:args("test-manifest2") %test:assertXPath("$result/string() = 'Iraq'")
%test:args("test-manifest3") %test:assertXPath("$result/string() = 'Alqosh'")
function tmt:make-origin($manifest-uri as xs:string) {
tapi-mani:make-origin($manifest-uri)
};
declare
%test:args("ahiqar_agg") %test:assertXPath("$result/string() = 'University of Cambridge - Cambridge University Library, Great Britain'")
%test:args("test-manifest1") %test:assertXPath("$result/string() = 'unknown'")
%test:args("test-manifest2") %test:assertXPath("$result/string() = 'University of Cambridge - Cambridge University Library'")
%test:args("test-manifest3") %test:assertXPath("$result/string() = 'Great Britain'")
function tmt:make-current-location($manifest-uri as xs:string) {
tapi-mani:make-current-location($manifest-uri)
};
declare
%test:args("ahiqar_collection", "ahiqar_agg") %test:assertExists
function tmt:get-json($collection-uri as xs:string,
$manifest-uri as xs:string) {
tapi-mani:get-json($collection-uri, $manifest-uri, $tc:server)
};