Commit f0e02318 authored by Michelle Rodzis's avatar Michelle Rodzis
Browse files

Add first draft for serializing only valid text

parent b46cb75a
This diff is collapsed.
......@@ -155,7 +155,7 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
(: tei:local:copy-element($node)ft without @new denote the duct of the current
writer or a change of writing medium :)
if($node/@new and (fontane-simple:is-hand-contemporary($node/@new) or
$node/@new = "#Friedrich_Fontane") or not($node/@new))
($node/@new = "#Friedrich_Fontane" and $node/ancestor::tei:surface[@type = "label"])) or not($node/@new))
then
local:copy-element($node)
else
......@@ -209,24 +209,9 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
case element(tei:surface) return
if(matches($node/@n, "cover")) then
((if(not($node/@n = "outer_front_cover"))
then
element tei:pb {
if($node/@n = "inner_front_cover"
or $node/@n = "outer_back_cover")
then
attribute type {"flyleaf"}
else
attribute type {"cover"}
}
else
()),
element tei:div {
attribute type {$node/@n},
$node/(@* except (@facs, @n)),
fontane-simple:transform($node/node())
})
else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
(local:make-pb-with-type($node/@n),
local:make-div-with-type($node, $node/@n))
else if(local:is-page($node)
and $node/@type = "clipping") then
(local:make-pb($node),
(if(not($node/@subtype = "Kalenderblatt"
......@@ -234,23 +219,16 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
local:make-div($node)
else
()))
else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
else if(local:is-page($node)
and $node/@type = "fragment") then
(local:make-pb($node),
local:make-div($node))
else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
else if(local:is-page($node)
and $node/@type = "pocket") then
local:make-pb($node)
else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
and $node/@type = "label" and $node/@subtype = "Oblate") then
()
else if(matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")) then
local:make-pb($node)
else if(local:is-page($node)) then
(local:make-pb($node),
element tei:div{
attribute type {"page"},
$node/(@* except (@facs, @n)),
fontane-simple:transform($node/node())
})
local:make-div-with-type($node, "page"))
else if($node/@type = "label" and
(contains($node/@subtype, "Fontane")
or contains($node/@subtype, "Hersteller"))
......@@ -488,7 +466,7 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
: @param $hand the tei:handShift/@new to be checked
: @return xs:boolean
: :)
declare function fontane-simple:is-hand-contemporary($hand as xs:string) as xs:boolean {
declare function fontane-simple:is-hand-contemporary($hand as xs:string?) as xs:boolean {
let $hand := replace($hand, "#", "")
let $file := doc("/db/sade-projects/textgrid/data/xml/data/16b00.xml")
let $handNote := $file//tei:handNote[@xml:id = $hand]
......@@ -530,16 +508,19 @@ declare function fontane-simple:strip-element($node as node()) {
: @param $node the current text node
: @return text() the formatted text
: :)
declare function local:prepare-text($node as text()) as text() {
let $cleared-hyphen :=
if(ends-with($node, "-") and not(local:keep-hyphen($node))) then
text {functx:substring-before-last($node, "-")}
else if(ends-with($node, "⸗") and not(local:keep-hyphen($node))) then
text {functx:substring-before-last($node, "⸗")}
else
$node
let $cleared-round-s := replace($cleared-hyphen, "ſ", "s")
return text {$cleared-round-s}
declare function local:prepare-text($node as text()) as text()? {
if(local:is-valid-text($node)) then
let $cleared-hyphen :=
if(ends-with($node, "-") and not(local:keep-hyphen($node))) then
text {functx:substring-before-last($node, "-")}
else if(ends-with($node, "⸗") and not(local:keep-hyphen($node))) then
text {functx:substring-before-last($node, "⸗")}
else
$node
let $cleared-round-s := replace($cleared-hyphen, "ſ", "s")
return text {$cleared-round-s}
else
()
};
......@@ -572,12 +553,36 @@ declare function local:copy-element($node as node()) as node() {
}
};
declare function local:has-valid-text($node as node()) as xs:boolean {
(: TODO :)
true()
let $text-nodes := $node/descendant::text()
let $results :=
for $text-node in $text-nodes
return
local:is-valid-text($text-node)
return
if(functx:is-value-in-sequence(true(), $results)) then
(true(), console:log("true"))
else
false()
};
declare function local:is-valid-text($node as text()) as xs:boolean {
let $current-hand := $node/preceding::tei:handShift[@new][1]/@new
return
if(fontane-simple:is-hand-contemporary($current-hand)
or $node/ancestor::*[@type = "edited_text"]) then
true()
else
false()
};
declare function local:is-page($node as node()) as xs:boolean {
matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
};
(:~
: Creates a tei:pb.
:
......@@ -592,6 +597,13 @@ declare function local:make-pb($node as node()) as element(tei:pb) {
};
declare function local:make-pb-with-type($type as xs:string) as element(tei:pb) {
element {QName("http://www.tei-c.org/ns/1.0", "pb")}{
attribute type {$type}
}
};
(:~
: Creates a tei:head.
:
......@@ -619,11 +631,27 @@ declare function local:make-head($node as node()) as element(tei:head) {
: @param $node the current tei:surface node
: @return element(tei:div)
: :)
declare function local:make-div($node as node()) as element(tei:div) {
element tei:div{
$node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
fontane-simple:transform($node/node())
}
declare function local:make-div($node as node()) as element(tei:div)? {
if(local:has-valid-text($node)) then
element tei:div{
$node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
fontane-simple:transform($node/node())
}
else
()
};
declare function local:make-div-with-type($node as node(), $type as xs:string)
as element(tei:div)? {
if(local:has-valid-text($node)) then
element tei:div{
attribute type {$type},
$node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
fontane-simple:transform($node/node())
}
else
()
};
......
This diff is collapsed.
This diff is collapsed.
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