Commit b43a5f5c authored by mrodzis's avatar mrodzis 🌎
Browse files

Feature/#96 robustness in sorting

parent 2f6ed890
......@@ -29,13 +29,15 @@ import module namespace tidySimple ="http://fontane-nb.dariah.eu/tidysimple" at
declare variable $etTransfo:cases :=
(
(: "3qtcz.xml", (: case C :):)
"3qtcz.xml", (: case C :)
"3qtqv.xml" (: case A :)
(: "3qtqw.xml" (: case B :) :)
(: "3qtqx.xml" (: case D :):)
(: "3qtqz.xml" (: case E :):)
);
declare variable $etTransfo:dir := "/db/apps/SADE/modules/fontane/edited-text/";
(:~
: The main function
......@@ -57,14 +59,6 @@ declare function etTransfo:complete() {
};
declare function etTransfo:transform-on-publish($notebook) {
try {
etTransfo:transform-tei($notebook//tei:TEI)
} catch * {
error(QName("error", "ETTRANSFO05"), "Could not transform " || $notebook//tei:title[1]/string() || " to XHTML.")
}
};
(:~
: Resolves all XIncludes in a given case file and copies all notebooks belonging to a case into one file.
:
......@@ -146,7 +140,9 @@ declare function etTransfo:create-htmls($showcase as xs:string) as xs:string+ {
let $teis := etTransfo:get-teis($showcase)
for $tei in $teis return
etTransfo:transform-tei($tei)
let $log := etTransfo:create-log(substring-after($tei//tei:idno[@type = "TextGrid"], "textgrid:"))
return
etTransfo:transform-tei($tei, $log)
};
......@@ -156,10 +152,10 @@ declare function etTransfo:create-htmls($showcase as xs:string) as xs:string+ {
:
: @param $tei The current notebook as element(tei:TEI)
:)
declare function etTransfo:transform-tei($tei as element(tei:TEI)) {
declare function etTransfo:transform-tei($tei as element(tei:TEI), $log as xs:string) {
(: macro-sort:main($tei, $tei/@id):)
(: => fsort:main():)
fsort:main($tei)
fsort:main($tei, $log)
=> prepCom:main($tei/@id)
=> fontaneSimple:main($tei/@id)
=> tidySimple:main($tei/@id)
......@@ -314,3 +310,19 @@ declare function etTransfo:make-bib-entries($type as xs:string) as element(tei:d
()
}
};
declare function etTransfo:create-log($uri as xs:string) as xs:string {
let $assure-dir-available := etTransfo:assure-dir-available("logs")
let $log-name := $uri || "-log.xml"
return xmldb:store($etTransfo:dir || "logs", $log-name, <log/>)
};
declare function etTransfo:assure-dir-available($dir-name as xs:string) {
if(xmldb:collection-available($etTransfo:dir || "logs")) then
$etTransfo:dir || "logs"
else
xmldb:create-collection($etTransfo:dir, "logs")
};
......@@ -250,6 +250,12 @@ declare function simple2xhtml:recursion($nodes as node()*) as node()* {
else if($node/@type = ("caret", "footnote-mark")) then
()
else if($node/@type = "paragraph" and $node/string = "z") then
(element xhtml:br{},
element xhtml:div {
attribute class {"nb-paragraph"}
})
else
simple2xhtml:recursion($node/node())
......
......@@ -22,9 +22,9 @@ import module namespace presort="http://fontane-nb.dariah.eu/presort" at "presor
:
: @author Michelle Weidling
:)
declare function fsort:main($tei as node()*) as element(tei:TEI) {
declare function fsort:main($tei as node()*, $log as xs:string) as element(tei:TEI) {
let $prepared := presort:prepare($tei)
let $tei := fsort:sort($prepared)
let $tei := fsort:sort($prepared, $log)
let $fully-sorted := presort:sort-integrations($tei)
let $id := $tei/@id
......@@ -38,7 +38,7 @@ declare function fsort:main($tei as node()*) as element(tei:TEI) {
: same rules that are specified in fsort:default-return().
:
:)
declare function fsort:sort($nodes as node()*) {
declare function fsort:sort($nodes as node()*, $log as xs:string) {
for $node in $nodes return
typeswitch ( $node )
case text() return
......@@ -51,7 +51,7 @@ declare function fsort:sort($nodes as node()*) {
()
case element(tei:zone) return
fsort:default-return($node)
fsort:default-return($node, $log)
(: case element(tei:hi) return:)
(: if($node/@next and not($node/ancestor::tei:rs)) then:)
......@@ -86,7 +86,7 @@ declare function fsort:sort($nodes as node()*) {
(: fsort:keep-node($node):)
default return
fsort:keep-node($node)
fsort:keep-node($node, $log)
};
(:~
......@@ -98,7 +98,7 @@ declare function fsort:sort($nodes as node()*) {
: @param $node the current TEI element
: @return a copy of the current element, a fully sorted virtual aggregation or an empty sequence
:)
declare function fsort:default-return($node as node()) as node()* {
declare function fsort:default-return($node as node(), $log as xs:string) as node()* {
(: nodes with @next and @prev are in the middle of a virtual aggregation and
handled in fsort:apply-all-nexts, thus we only look at the first element of
the aggregation.
......@@ -106,10 +106,10 @@ declare function fsort:default-return($node as node()) as node()* {
or similar), their @prev/@next doesn't indicate the chronology but only the
continuation of the highlighting. they should thus be omitted.:)
if(matches($node/@style, "underline")) then
fsort:keep-node($node)
fsort:keep-node($node, $log)
else if($node[@next and not(@prev)]) then
fsort:apply-all-nexts($node)
fsort:apply-all-nexts($node, $log)
(: since all parts of the virtual aggregation are handled by fsort:apply-all-nexts
we can ignore the ones that have a @prev :)
......@@ -118,7 +118,7 @@ declare function fsort:default-return($node as node()) as node()* {
(: we distinguish this case and the one below to improve performance :)
else if($node[descendant::*[@next or @prev]]) then
fsort:keep-node($node)
fsort:keep-node($node, $log)
(: nodes with this attribute are part of an interlinear addition; they have
been marked by presort:prepare. since interlinear additions are handled as a
......@@ -142,7 +142,7 @@ declare function fsort:default-return($node as node()) as node()* {
: @return a sequence of all nodes belonging to the virtual aggregation in the
: right order
: :)
declare function fsort:apply-all-nexts($node as node()) as node()* {
declare function fsort:apply-all-nexts($node as node(), $log as xs:string) as node()* {
(: in case an addSpan is part of a virtual aggregation :)
if($node[self::tei:addSpan]) then
let $spanTo := substring-after($node/@spanTo, "#")
......@@ -151,26 +151,36 @@ declare function fsort:apply-all-nexts($node as node()) as node()* {
return
for $node-inbetween in $nodes-inbetween return
fsort:keep-node($node-inbetween)
fsort:keep-node($node-inbetween, $log)
else
(: first element of a virtual aggregation: entry point :)
if($node/@next and not($node/@prev)) then
let $next-node := fsort:find-corresp-node($node, "next")
return
(fsort:keep-node($node),
fsort:apply-all-nexts($next-node))
if(count($next-node) = 1) then
(fsort:keep-node($node, $log),
fsort:apply-all-nexts($next-node, $log))
else if(not($next-node)) then
fsort:add-log-entry($log, "No next node found for " || $node/@next)
else
fsort:add-log-entry($log, "Several next nodes found for " || $node/@next)
(: last of a virtual aggregation: exit point :)
else if(not($node/@next)) then
fsort:keep-node($node)
fsort:keep-node($node, $log)
(: element in the middle of a virtual aggregation:)
else
let $next-node := fsort:find-corresp-node($node, "next")
return
(fsort:keep-node($node),
fsort:apply-all-nexts($next-node))
if(count($next-node) = 1) then
(fsort:keep-node($node, $log),
fsort:apply-all-nexts($next-node, $log))
else if(not($next-node)) then
fsort:add-log-entry($log, "No next node found for " || $node/@next)
else
fsort:add-log-entry($log, "Several next nodes found for " || $node/@next)
};
......@@ -188,10 +198,10 @@ declare function fsort:apply-all-nexts($node as node()) as node()* {
: @param $node the current node
: @return a copy of the current node with sorted descendants
:)
declare function fsort:keep-node($node as node()) as node() {
declare function fsort:keep-node($node as node(), $log as xs:string) as node() {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
fsort:sort($node/node())
fsort:sort($node/node(), $log)
}
};
......@@ -234,7 +244,7 @@ element(tei:rs)? {
for $child in $rs-children return
if($child/@next
and not(matches($child/@style, "underline"))) then
fsort:apply-all-nexts($child)
fsort:apply-all-nexts($child, $log)
else
$child
......@@ -270,3 +280,10 @@ xs:boolean {
return
not($are-copied = false())
};
declare function fsort:add-log-entry($log-file as xs:string,
$message as xs:string) as empty-sequence() {
let $entry := <LogEntry timestamp="{util:system-time()}">{$message}</LogEntry>
return update insert $entry into doc($log-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