Commit 9dcacdb7 authored by MRodz's avatar MRodz Committed by mrodzis
Browse files

Add first draft for deleting surplus lines

parent 3881a7da
......@@ -456,7 +456,8 @@ declare function fontaneSimple:transform($nodes as node()*) as node()* {
else if($node/@type = "heading") then
fontaneSimple:make-head($node)
else if($node/@type = "list" or $node/@type = "item") then
else if($node/@type = "list"
or $node/@type = "item") then
element {QName("http://www.tei-c.org/ns/1.0", $node/@type)} {
$node/(@xml:id, @subtype, @rendition, @prev, @next),
if($node/@rend) then
......
......@@ -50,7 +50,7 @@ declare
%test:assertEquals("<body xmlns=""http://www.tei-c.org/ns/1.0""><milestone xmlns=""http://www.tei-c.org/ns/1.0"" unit=""line""/><milestone xmlns=""http://www.tei-c.org/ns/1.0"" unit=""section"" type=""Text_1"" spanTo=""#C07_3r_s""/><milestone xmlns=""http://www.tei-c.org/ns/1.0"" unit=""handshift"" subtype=""#Fontane"" rend=""script(Latn clean) medium()""/><head xmlns=""http://www.tei-c.org/ns/1.0"" type=""x-large"" rend=""align(center)""><rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""psn:Luther""><hi xmlns=""http://www.tei-c.org/ns/1.0"">Luther</hi></rs></head></body>")
function tidysimple-test:handShift-surplus($node as element(*)) {
tidySimple:sort-out-surplus-hands($node)
tidySimple:sort-out-surplus-elements($node)
};
......@@ -70,3 +70,14 @@ declare
function tidysimple-test:sections($node as element(*)) {
tidySimple:make-structure($node)
};
(: tidying :)
declare
%test:name("Tidying up surplus elements")
%test:args("<text xmlns:tei=""http://www.tei-c.org/ns/1.0""><pb xmlns:tei=""http://www.tei-c.org/ns/1.0"" n=""58r""/><milestone xmlns:tei=""http://www.tei-c.org/ns/1.0"" unit=""line""/><pb xmlns:tei=""http://www.tei-c.org/ns/1.0"" n=""58v""/></text>")
%test:assertEquals("<text xmlns:tei=""http://www.tei-c.org/ns/1.0""><pb xmlns:tei=""http://www.tei-c.org/ns/1.0"" n=""58r""/><pb xmlns:tei=""http://www.tei-c.org/ns/1.0"" n=""58v""/></text>")
function tidysimple-test:tidying($node as element(*)) {
tidySimple:sort-out-surplus-elements($node)
};
\ No newline at end of file
......@@ -37,12 +37,13 @@ declare function tidySimple:main($tei as node()*) {
} catch * {
(console:log("It was not possible to open the requested file tei-simple-pre.xml."))
}
let $text := $doc//tei:text
let $text := $tei//tei:text
let $clear-invalid-hands := tidySimple:sort-out-invalid-hands($text)
let $clear-surplus-hands := tidySimple:sort-out-surplus-hands($clear-invalid-hands)
let $text-with-sections := tidySimple:make-structure($clear-surplus-hands)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-tmp.xml", <div>{$text-with-sections}</div>)
return element tei:div {$text-with-sections}
let $clear-surplus-hands := tidySimple:sort-out-surplus-elements($clear-invalid-hands)
(: let $text-with-sections := tidySimple:make-structure($clear-surplus-hands):)
(: let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-tmp.xml", <div>{$text-with-sections}</div>):)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-tmp.xml", <div>{$clear-surplus-hands}</div>)
return "done"
(: let $doc := doc($config:app-root || "/resources/xml/tei-simple-tmp.xml"):)
(: let $tidied-text := tidySimple:tidy($doc//tei:text):)
(: let $final-tei:=:)
......@@ -101,7 +102,7 @@ as node()* {
};
declare function tidySimple:sort-out-surplus-hands($nodes as node()*)
declare function tidySimple:sort-out-surplus-elements($nodes as node()*)
as node()* {
for $node in $nodes return
typeswitch ($node)
......@@ -115,16 +116,35 @@ as node()* {
()
else
tidySimple:clear-handshift($node)
else if($node/@unit = "line") then
let $next-pb := $node/following::tei:pb[1]
let $nodes-on-page := $node/preceding::tei:pb[1]/following::node()[. << $next-pb][functx:node-kind(.) = "text"]
let $contains-text :=
for $node-pb in $nodes-on-page return
if(normalize-space($node-pb) != "") then
true()
else
false()
return
if(functx:is-value-in-sequence(true(), $contains-text)) then
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
tidySimple:sort-out-surplus-elements($node/node())
}
else
()
else
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
tidySimple:sort-out-surplus-hands($node/node())
tidySimple:sort-out-surplus-elements($node/node())
}
default return
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
tidySimple:sort-out-surplus-hands($node/node())
tidySimple:sort-out-surplus-elements($node/node())
}
};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Supports Markdown
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