Commit 260b4e1e authored by MRodz's avatar MRodz Committed by mrodzis
Browse files

Add 3.21.20 abbreviations

parent 65f65e50
......@@ -320,7 +320,7 @@ declare
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0"" style=""border-style:solid"" ulx=""0.3"" uly=""6.1"" lrx=""8.3"" lry=""9.3""><line style=""margin-left:1.1cm"">Test</line></zone>")
%test:assertEquals("<div xmlns=""http://www.tei-c.org/ns/1.0"" type=""frame"">Test</div>")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0"" style=""border-left-style:solid; border-top-style:solid; border-right-style:solid"" ulx=""0.4"" uly=""7.3"" lrx=""9.9"" lry=""16.1""><zone xmlns=""http://www.tei-c.org/ns/1.0"" ulx=""0.0"" uly=""0.5"" lrx=""9.2"" lry=""5.8""><line xmlns=""http://www.tei-c.org/ns/1.0"" style=""margin-left:0.5cm"">„Es hätte ſie ſehr</line></zone></zone>")
%test:assertEquals("„Es hätte ſie ſehr")
%test:assertEquals("„Es hätte sie sehr")
function teisimple-test:analyze-rect-frames($node as element(*)) {
fontane-simple:transform($node)
};
......@@ -481,13 +481,13 @@ declare
reason unclear since a test with an XML yielded the desired output :)
(: %test:args("<line xmlns=""http://www.tei-c.org/ns/1.0""><seg xmlns=""http://www.tei-c.org/ns/1.0"" type=""multiphrase"" xml:id=""B02_78v_a"" corresp=""#B02_78v_b"">an<anchor xmlns=""http://www.tei-c.org/ns/1.0"" xml:id=""B02_78v_c""/>geſehenſten</seg> <add xmlns=""http://www.tei-c.org/ns/1.0"" corresp=""#B02_78v_c"" place=""above""><seg xmlns=""http://www.tei-c.org/ns/1.0"" type=""multiphrase"" xml:id=""B02_78v_b"" corresp=""#B02_78v_a"">vornehmſten</seg></add> Financiers</line>"):)
(: %test:assertEquals("<seg xmlns=""http://www.tei-c.org/ns/1.0"" type=""multiphrase"" xml:id=""B02_78v_a"" corresp=""#B02_78v_b"">an<anchor xmlns=""http://www.tei-c.org/ns/1.0"" xml:id=""B02_78v_c""/>geſehenſten</seg>", " ", "<add xmlns=""http://www.tei-c.org/ns/1.0"" corresp=""#B02_78v_c"" place=""above""><seg type=""multiphrase"" xml:id=""B02_78v_b"" corresp=""#B02_78v_a"">vornehmſten</seg></add>", " Financiers"):)
(: %test:assertEquals("<seg xmlns=""http://www.tei-c.org/ns/1.0"" type=""multiphrase"" xml:id=""B02_78v_a"" corresp=""#B02_78v_b"">an<anchor xmlns=""http://www.tei-c.org/ns/1.0"" xml:id=""B02_78v_c""/>gesehensten</seg>", " ", "<add xmlns=""http://www.tei-c.org/ns/1.0"" corresp=""#B02_78v_c"" place=""above""><seg type=""multiphrase"" xml:id=""B02_78v_b"" corresp=""#B02_78v_a"">vornehmsten</seg></add>", " Financiers"):)
%test:args("<addSpan xmlns=""http://www.tei-c.org/ns/1.0"" type=""multiphrase"" subtype=""extensive"" xml:id=""D04_10r_c"" corresp=""#D04_10r_2"" spanTo=""#D04_10r_a"" place=""margin""/>")
%test:assertEmpty
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0"" type=""multiphrase"" subtype=""extensive"" xml:id=""D04_10r_2"" next=""#D04_10v_a"" corresp=""#D04_10r_c""><zone style=""border-left-style:solid""><line xmlns=""http://www.tei-c.org/ns/1.0"">mit einem ſlaviſch⸗ſtubs-</line></zone></zone>")
%test:assertEquals("mit einem ſlaviſch⸗ſtubs-")
%test:assertEquals("mit einem slavisch⸗stubs")
function teisimple-test:analyze-multiphrase($node as element(*)) {
fontane-simple:transform($node)
};
......@@ -522,7 +522,7 @@ declare
declare
%test:name("Underline")
%test:args("<hi xmlns=""http://www.tei-c.org/ns/1.0"">K<mod xmlns=""http://www.tei-c.org/ns/1.0"" style=""text-decoration:underline"" rend=""underline-style:retrace"">aiſer</mod></hi>")
%test:assertEquals("<hi xmlns=""http://www.tei-c.org/ns/1.0"">Kaiſer</hi>")
%test:assertEquals("<hi xmlns=""http://www.tei-c.org/ns/1.0"">Kaiser</hi>")
function teisimple-test:analyze-underline($node as element(*)) {
fontane-simple:transform($node)
......@@ -535,11 +535,112 @@ declare
%test:assertEquals("<hi xmlns=""http://www.tei-c.org/ns/1.0"" type=""vertical-mark"">Aber alles mehr</hi>")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0"" type=""highlighted"" style=""border-left-style:double""><zone xmlns=""http://www.tei-c.org/ns/1.0"" type=""highlighted"" style=""border-left-style:double""><line xmlns=""http://www.tei-c.org/ns/1.0"" style=""margin-left:0.2cm""><hi xmlns=""http://www.tei-c.org/ns/1.0"" xml:id=""B11_49v_a"" next=""#B11_41v_b"">Ein<seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""text-decoration:underline"">e koloſſa</seg>le</hi></line></zone></zone>")
%test:assertEquals("<hi xmlns=""http://www.tei-c.org/ns/1.0"" type=""vertical-mark""><hi xmlns=""http://www.tei-c.org/ns/1.0"">Eine koloſſale</hi></hi>")
%test:assertEquals("<hi xmlns=""http://www.tei-c.org/ns/1.0"" type=""vertical-mark""><hi xmlns=""http://www.tei-c.org/ns/1.0"">Eine kolossale</hi></hi>")
function teisimple-test:analyze-vertical-marks($node as element(*)) {
fontane-simple:transform($node)
};
(: 3.21.21 SPECIAL CASES (CHARACTERS) :)
(: hyphens :)
declare
%test:name("Special cases (hyphens)")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0""><line xmlns=""http://www.tei-c.org/ns/1.0"">Coſtümen, unter beſti<g ref=""#mgem"">mm</g>ter Um-</line><line xmlns=""http://www.tei-c.org/ns/1.0"">gebung.</line></zone>")
%test:assertEquals("Costümen, unter besti", "mm", "ter Um", "gebung.")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0""><line xmlns=""http://www.tei-c.org/ns/1.0"">Coſtümen, unter beſti<g ref=""#mgem"">mm</g>ter Um⸗</line><line xmlns=""http://www.tei-c.org/ns/1.0"">gebung.</line></zone>")
%test:assertEquals("Costümen, unter besti", "mm", "ter Um", "gebung.")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0""><line xmlns=""http://www.tei-c.org/ns/1.0"">Kunſt-Vereins-</line><lb xmlns=""http://www.tei-c.org/ns/1.0"" break=""keepHyphen""/><line xmlns=""http://www.tei-c.org/ns/1.0"">Lokal.</line></zone>")
%test:assertEquals("Kunst-Vereins-","Lokal.")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0""><line xmlns=""http://www.tei-c.org/ns/1.0"">Kunſt-Vereins⸗</line><lb xmlns=""http://www.tei-c.org/ns/1.0"" break=""keepHyphen""/><line xmlns=""http://www.tei-c.org/ns/1.0"">Lokal.</line></zone>")
%test:assertEquals("Kunst-Vereins⸗","Lokal.")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0""><line xmlns=""http://www.tei-c.org/ns/1.0"">ſich durch den Baurath um<g xmlns=""http://www.tei-c.org/ns/1.0"" ref=""#vds"">⸗</g></line><line xmlns=""http://www.tei-c.org/ns/1.0"">ſtimmen; wir fahren um</line></zone>")
%test:assertEquals("sich durch den Baurath um","stimmen; wir fahren um")
function teisimple-test:analyze-hyphens($node as element(*)) {
fontane-simple:transform($node)
};
(: tremata :)
declare
%test:name("Special cases (tremata)")
%test:args("<line xmlns=""http://www.tei-c.org/ns/1.0"">eine blühende Aloë, eine Ananas, ei<retrace xmlns=""http://www.tei-c.org/ns/1.0"">n</retrace></line>")
%test:assertEquals("eine blühende Aloë, eine Ananas, ei", "n")
%test:args("<line xmlns=""http://www.tei-c.org/ns/1.0"">Du Baste de l‘Héro&#x1e2f;ne</line>")
%test:assertEquals("Du Baste de l‘Héro&#x1e2f;ne")
function teisimple-test:analyze-tremata($node as element(*)) {
fontane-simple:transform($node)
};
(: superscript :)
declare
%test:name("Special cases (superscript and subscript)")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0""><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:super; text-decoration:underline"">r</seg></zone>")
%test:assertEquals("<seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:super; text-decoration:underline"">r</seg>")
%test:args("<line xmlns=""http://www.tei-c.org/ns/1.0""><hi xmlns=""http://www.tei-c.org/ns/1.0""><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""text-decoration:underline"">Dinstag d. 20</seg>.</hi><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""text-decoration:underline; vertical-align:super"">ten</seg></line>")
%test:assertEquals("<hi xmlns=""http://www.tei-c.org/ns/1.0"">Dinstag d. 20.</hi>","<seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""text-decoration:underline; vertical-align:super"">ten</seg>")
%test:args("<zone xmlns=""http://www.tei-c.org/ns/1.0""><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:sub; text-decoration:underline"">r</seg></zone>")
%test:assertEquals("<seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:sub; text-decoration:underline"">r</seg>")
function teisimple-test:analyze-superscript($node as element(*)) {
fontane-simple:transform($node)
};
(: spaces :)
declare
%test:name("Special cases (spaces)")
%test:args("<space xmlns=""http://www.tei-c.org/ns/1.0"" type=""placeholder""/>")
%test:assertEquals("<space xmlns=""http://www.tei-c.org/ns/1.0"" type=""placeholder""/>")
%test:args("<space xmlns=""http://www.tei-c.org/ns/1.0"" type=""pause""/>")
%test:assertEquals("<space xmlns=""http://www.tei-c.org/ns/1.0"" type=""pause""/>")
%test:args("<metamark xmlns=""http://www.tei-c.org/ns/1.0"" function=""placeholder"">. . .</metamark>")
%test:assertEquals("<ab xmlns=""http://www.tei-c.org/ns/1.0"" type=""placeholder"">. . .</ab>")
function teisimple-test:analyze-spaces($node as element(*)) {
fontane-simple:transform($node)
};
(: repetitions :)
declare
%test:name("Special cases (repetitions)")
%test:args("<add xmlns=""http://www.tei-c.org/ns/1.0"" copyOf=""#C01_48r_1"" cause=""catchword"">dem </add>")
%test:assertEmpty
%test:args("<add xmlns=""http://www.tei-c.org/ns/1.0"" place=""above"" style=""margin-left:-0.0cm"" copyOf=""#C05_31v_a"" cause=""unclear"">engſten</add>")
%test:assertEmpty
function teisimple-test:analyze-repetitions($node as element(*)) {
fontane-simple:transform($node)
};
(: abbreviations :)
declare
%test:name("Special cases (abbreviations)")
%test:args("<choice xmlns=""http://www.tei-c.org/ns/1.0""><abbr xmlns=""http://www.tei-c.org/ns/1.0"">fr.</abbr><expan xmlns=""http://www.tei-c.org/ns/1.0"">Franken</expan></choice>")
%test:assertEquals("<choice xmlns=""http://www.tei-c.org/ns/1.0""><abbr xmlns=""http://www.tei-c.org/ns/1.0"">fr.</abbr><expan xmlns=""http://www.tei-c.org/ns/1.0"">Franken</expan></choice>")
%test:args("<line xmlns=""http://www.tei-c.org/ns/1.0"">6 &#x20b0;</line>")
%test:assertEquals("6 &#x20b0;")
(: TODO: insert character from Fontine :)
%test:args("<line xmlns=""http://www.tei-c.org/ns/1.0"">mit Küche 60 <g xmlns=""http://www.tei-c.org/ns/1.0"" ref=""#rth"">Reichstaler</g></line>")
%test:assertEquals("mit Küche 60 ", "<g xmlns=""http://www.tei-c.org/ns/1.0"" ref=""#rth"">Reichstaler</g>")
%test:args("<metamark xmlns=""http://www.tei-c.org/ns/1.0"" function=""etc."">...</metamark>")
%test:assertEquals("<ab xmlns=""http://www.tei-c.org/ns/1.0"" type=""etc."">...</ab>")
%test:args("<line xmlns=""http://www.tei-c.org/ns/1.0"">ſind bedeutend. 1 <seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""font-size:small""><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:super"">1</seg><g xmlns=""http://www.tei-c.org/ns/1.0"" ref=""#hb"">/</g><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:sub"">2</seg></seg> Sgr</line>")
%test:assertEquals("sind bedeutend. 1 ", "<seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""font-size:small""><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:super"">1</seg><g xmlns=""http://www.tei-c.org/ns/1.0"" ref=""#hb"">/</g><seg xmlns=""http://www.tei-c.org/ns/1.0"" style=""vertical-align:sub"">2</seg></seg>", " Sgr")
function teisimple-test:analyze-abbreviations($node as element(*)) {
fontane-simple:transform($node)
};
......@@ -15,11 +15,13 @@ xquery version "3.1";
module namespace fontane-simple="http://fontane-nb.dariah.eu/teisimple";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace functx = "http://www.functx.com";
(:~
: The main function initiates the transformation of a given notebook.
......@@ -68,9 +70,22 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
for $node in $nodes
return
typeswitch ($node)
case text()
return
$node
case text() return
local:prepare-text($node)
case element(tei:lb) return
if($node[@break = "keepHyphen"]) then
()
else
$node
case element(tei:g) return
if($node[@ref = "#vds"]) then
()
else if($node/@ref ="#rth" or $node/@ref ="#hb") then
$node
else
fontane-simple:transform($node/node())
case element(tei:graphic)
return
......@@ -109,6 +124,8 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
$node/@*,
fontane-simple:transform($node/node())
}
else if($node/@cause ="catchword" or $node/@cause ="unclear") then
()
else if(not($node/@xml:id)) then
fontane-simple:transform($node/node())
else if(fontane-simple:is-transposed($node)) then
......@@ -176,8 +193,14 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
($node/child::tei:stamp or $node/child::tei:metamark[@function = "caret"]))
then
()
else if(matches($node/@style, "underline")) then
else if(matches($node/@style, "underline")
and not(matches($node/@style, "vertical-align"))) then
fontane-simple:transform($node/node())
else if(contains($node/@style, "vertical-align")) then
element tei:seg {
$node/@*,
fontane-simple:transform($node/node())
}
else if($node/@type = "initials" or $node/@type = "monogram"
or $node/@style or $node/@type = "multiphrase")
then
......@@ -275,6 +298,11 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
attribute type {"paragraph-line-special"},
fontane-simple:transform($node/node())
}
else if($node/@function = "placeholder" or $node/@function ="etc.") then
element tei:ab {
attribute type {$node/@function},
fontane-simple:transform($node/node())
}
else
()
......@@ -366,12 +394,25 @@ declare function fontane-simple:transform($nodes as node()*) as node()* {
case element(tei:ref) return
$node
case element(tei:space) return
$node
case element(tei:choice) return
local:keep-element($node)
case element(tei:abbr) return
local:keep-element($node)
case element(tei:expan) return
local:keep-element($node)
case element(tei:ptr) return
let $target-id := substring-after($node/@target, "#")
let $target := $node/ancestor::tei:TEI//*[matches(@xml:id, $target-id)]
let $stripped-target := fontane-simple:strip-element($target)
return fontane-simple:transform($stripped-target)
default return
fontane-simple:transform($node/node())
};
......@@ -403,4 +444,31 @@ declare function fontane-simple:strip-element($node as node()) {
$node/@type,
fontane-simple:transform($node/node())
}
};
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:keep-hyphen($node as text()) as xs:boolean {
if($node/parent::tei:line/following-sibling::*[1][self::tei:lb[@break = "keepHyphen"]])
then
true()
else
false()
};
declare function local:keep-element($node as node()) as node() {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
$node/@*,
fontane-simple:transform($node/node())
}
};
\ No newline at end of file
This diff is collapsed.
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