Commit 8e6a2a6a authored by mrodzis's avatar mrodzis 🌎
Browse files

Feature/#66 handshifts

parent 1d9dfb7d
......@@ -24,6 +24,7 @@ import module namespace presort="http://fontane-nb.dariah.eu/presort" at "presor
:)
declare function fsort:main($tei as node()*, $log as xs:string) as element(tei:TEI) {
let $prepared := presort:prepare($tei)
let $prepared := fsort:enhance-handshifts($prepared, $log)
let $tei := fsort:sort($prepared, $log)
let $fully-sorted := presort:sort-integrations($tei)
let $id := $tei/@id
......@@ -86,7 +87,7 @@ declare function fsort:sort($nodes as node()*, $log as xs:string) {
(: fsort:keep-node($node):)
default return
fsort:keep-node($node, $log)
fsort:keep-node($node, "sort", $log)
};
(:~
......@@ -106,7 +107,7 @@ declare function fsort:default-return($node as node(), $log as xs:string) as nod
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, $log)
fsort:keep-node($node, "sort", $log)
else if($node[@next and not(@prev)]) then
fsort:apply-all-nexts($node, $log)
......@@ -118,7 +119,7 @@ declare function fsort:default-return($node as node(), $log as xs:string) as nod
(: we distinguish this case and the one below to improve performance :)
else if($node[descendant::*[@next or @prev]]) then
fsort:keep-node($node, $log)
fsort:keep-node($node, "sort", $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
......@@ -151,7 +152,7 @@ declare function fsort:apply-all-nexts($node as node(), $log as xs:string) as no
return
for $node-inbetween in $nodes-inbetween return
fsort:keep-node($node-inbetween, $log)
fsort:keep-node($node-inbetween, "sort", $log)
else
(: first element of a virtual aggregation: entry point :)
......@@ -159,7 +160,7 @@ declare function fsort:apply-all-nexts($node as node(), $log as xs:string) as no
let $next-node := fsort:find-corresp-node($node, "next")
return
if(count($next-node) = 1) then
(fsort:keep-node($node, $log),
(fsort:keep-node($node, "sort", $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)
......@@ -168,14 +169,17 @@ declare function fsort:apply-all-nexts($node as node(), $log as xs:string) as no
(: last of a virtual aggregation: exit point :)
else if(not($node/@next)) then
fsort:keep-node($node, $log)
($node/preceding::tei:handShift[1],
fsort:keep-node($node, "sort", $log))
(: element in the middle of a virtual aggregation:)
else
let $next-node := fsort:find-corresp-node($node, "next")
let $prev-handshift := $node/preceding::tei:handShift[1]
return
if(count($next-node) = 1) then
(fsort:keep-node($node, $log),
($prev-handshift,
fsort:keep-node($node, "sort", $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)
......@@ -198,10 +202,13 @@ declare function fsort:apply-all-nexts($node as node(), $log as xs:string) as no
: @param $node the current node
: @return a copy of the current node with sorted descendants
:)
declare function fsort:keep-node($node as node(), $log as xs:string) as node() {
declare function fsort:keep-node($node as node(), $flag as xs:string, $log as xs:string) as node() {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
fsort:sort($node/node(), $log)
if($flag = "sort") then
fsort:sort($node/node(), $log)
else
fsort:enhance-handshifts($node/node(), $log)
}
};
......@@ -287,3 +294,46 @@ $message as xs:string) as empty-sequence() {
let $entry := <LogEntry timestamp="{util:system-time()}">{$message}</LogEntry>
return update insert $entry into doc($log-file)/*
};
(:~
: Adds the information back to tei:handShifts that have been omitted in order to
: avoid redundancy.
:
:)
declare function fsort:enhance-handshifts($nodes as node()*, $log as xs:string)
as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case comment() return
if(matches($node, "transform")) then
$node
else
()
case element(tei:handShift) return
element tei:handShift {
if($node/@new) then
$node/@new
else
attribute new {$node/preceding::tei:handShift[@new][1]/@new},
if($node/@medium) then
$node/@medium
else
attribute medium {$node/preceding::tei:handShift[@medium][1]/@medium},
if($node/@script) then
$node/@script
else
attribute script {$node/preceding::tei:handShift[@script][1]/@script}
}
default return
fsort:keep-node($node, "handshift", $log)
};
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