Commit bfbcd458 authored by MRodz's avatar MRodz Committed by mrodzis
Browse files

Add first draft for establishing right order

parent 8781e02a
xquery version "3.1";
module namespace presort="http://fontane-nb.dariah.eu/presort";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";
declare function presort:main($file as xs:string) as node()? {
let $doc :=
try {
(doc("/db/sade-projects/textgrid/data/xml/data/" || $file))
} catch * {
(console:log("It was not possible to open the requested file " || $file))
}
let $front-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "front_cover")]
let $back-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "back_cover")]
let $content := $doc//tei:sourceDoc/tei:surface[not(contains(@n, "cover")
or matches(@n, "spine"))]
let $tei := <TEI xmlns="http://www.tei-c.org/ns/1.0">
{$doc//tei:teiHeader}
<text>
<front>{presort:sort($front-covers)}</front>
<body>{presort:sort($content)}</body>
<back>{presort:sort($back-covers)}</back>
</text>
</TEI>
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-presort.xml", $tei)
return $tei
};
declare function presort:sort($nodes as node()*) as node()* {
for $node in $nodes
return
typeswitch ($node)
case text() return
$node
case attribute(prev) return
()
case attribute(next) return
"blubb"
default return
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
presort:sort($node/node())
}
};
\ No newline at end of file
xquery version "3.1";
(: This main module starts the tests stored in teisimple-test.xql. :)
import module namespace presort-test = "http://fontane-nb.dariah.eu/presort-test" at "presort-test.xql";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
declare namespace tei="http://www.tei-c.org/ns/1.0";
test:suite(
util:list-functions("http://fontane-nb.dariah.eu/presort-test")
)
xquery version "3.1";
(: This library module contains XQSuite tests for the presorting module stored
: in ../presort.xqm :)
module namespace presort-test = "http://fontane-nb.dariah.eu/presort-test";
import module namespace presort="http://fontane-nb.dariah.eu/presort" at "../presort.xqm";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";
(: Text :)
declare
%test:name("Text nodes")
%test:args("Just some text")
%test:assertEquals("Just some text")
%test:args("Text with Ümläöuts")
%test:assertEquals("Text with Ümläöuts")
%test:args("Hiſtoriſches ✓")
%test:assertEquals("Hiſtoriſches ✓")
function presort-test:text($node as text()) {
presort:sort($node)
};
(: Default nodes :)
declare
%test:name("Default nodes")
%test:args("<handShift xmlns=""http://www.tei-c.org/ns/1.0"" medium=""pencil"" script=""Latf""/>")
%test:assertEquals("<handShift xmlns=""http://www.tei-c.org/ns/1.0"" medium=""pencil"" script=""Latf""/>")
%test:args("<seg xmlns=""http://www.tei-c.org/ns/1.0""><stamp xmlns=""http://www.tei-c.org/ns/1.0"">STAATSBIBLIOTHEK •BERLIN•</stamp></seg>")
%test:assertEquals("<seg xmlns=""http://www.tei-c.org/ns/1.0""><stamp xmlns=""http://www.tei-c.org/ns/1.0"">STAATSBIBLIOTHEK •BERLIN•</stamp></seg>")
function presort-test:default-nodes($node as element(*)) {
presort:sort($node)
};
(: @prev nodes :)
declare
%test:name("Omit @prev nodes")
%test:args("<handShift xmlns=""http://www.tei-c.org/ns/1.0"" medium=""pencil"" script=""Latf""/>")
%test:assertEquals("<handShift xmlns=""http://www.tei-c.org/ns/1.0"" medium=""pencil"" script=""Latf""/>")
%test:args("<seg xmlns=""http://www.tei-c.org/ns/1.0"" prev=""#some_id""><stamp xmlns=""http://www.tei-c.org/ns/1.0"">STAATSBIBLIOTHEK •BERLIN•</stamp></seg>")
%test:assertEmpty
function presort-test:omit-prev-nodes($node as element(*)) {
presort:sort($node)
};
(: @next nodes :)
declare
%test:name("Establishing right order with @next nodes")
%test:args("<handShift xmlns=""http://www.tei-c.org/ns/1.0"" next=""#some-test-id""/>")
%test:assertEmpty
function presort-test:next-nodes($node as element(*)) {
presort:sort($node)
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment