Commit d6fc8ee7 authored by MRodz's avatar MRodz Committed by mrodzis
Browse files

Add first draft for making tei:div[@type = section] and tei:p

parent 5fb3caed
......@@ -46,7 +46,7 @@ declare function fontaneSimple:main($file as xs:string) as node()? {
<back>{fontaneSimple:transform($back-covers)}</back>
</text>
</TEI>
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-tmp.xml", $tei)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-pre.xml", $tei)
return $tei
};
......
......@@ -303,6 +303,11 @@ $node as element(*)*) as xs:boolean {
};
declare function simpleHelpers:find-prev-valid-hand($hands as xs:string*,
$node as element(tei:handShift)) as element(tei:handShift){
$node/preceding::tei:handShift[1][simpleHelpers:is-hand-valid($hands, $node)]
};
(:~
: Checks if the previous handShift is the same as the current handShift. Two
: handShifts are the same if they have the same attributes.
......@@ -311,29 +316,15 @@ $node as element(*)*) as xs:boolean {
: @param $node the current tei:handShift element
: @return xs:boolean
:)
declare function simpleHelpers:is-prev-hand-same($node as element(tei:handShift))
as xs:boolean {
let $prev-hand := $node/preceding::tei:handShift[1]
return
(: since we can't take the order of the attributes for granted we can't
use functx:sequence-deep-equal :)
if($prev-hand
and $node/@new = $prev-hand/@new
and $node/@script = $prev-hand/@script
and $node/@medium = $prev-hand/@medium) then
true()
else
false()
};
declare function simpleHelpers:is-prev-valid-hand-same($hands as xs:string,
$node as element(tei:handShift)) as xs:boolean {
let $prev-hand := $node/preceding::tei:handShift[simpleHelpers:is-hand-contemporary(.)][1]
let $prev-valid-hand := simpleHelpers:find-prev-valid-hand($hands, $node)
let $prev-hand := $node/preceding::tei:handShift[1]
return
(: since we can't take the order of the attributes for granted we can't
use functx:sequence-deep-equal :)
if($prev-hand
and $prev-hand = $prev-valid-hand
and $node/@new = $prev-hand/@new
and $node/@script = $prev-hand/@script
and $node/@medium = $prev-hand/@medium) then
......@@ -351,21 +342,4 @@ as element(tei:section) {
let $bla := console:log(util:get-fragment-between($node, $corresp, true(), true()))
return
<div/>
};:)
(:~
: Returns all nodes between a tei:milestone and its corresponding tei:anchor
: without the parent node.
:
: @author Michelle Rodzis
: @param the current tei:milestone element
: @return all nodes between the current element and the respective tei:anchor
:)
declare function simpleHelpers:get-xml-chunk($node as node()) as node()* {
let $target-id := substring-after($node/@spanTo, "#")
let $target := //tei:anchor[matches(@xml:id, $target-id)]
return
util:get-fragment-between($node, $target, false(), false())
};
\ No newline at end of file
};:)
\ No newline at end of file
......@@ -29,15 +29,25 @@ declare variable $tidySimple:valid-hands :=
declare function tidySimple:main($tei as node()*) as xs:string* {
let $text := $tei//tei:text
let $tidied-text := tidySimple:tidy($text)
let $final-tei:=
<TEI xmlns="http://www.tei-c.org/ns/1.0">
{$tei//tei:teiHeader}
{$tidied-text}
</TEI>
return xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple.xml", $final-tei)
let $doc :=
try {
(doc($config:app-root || "/resources/xml/tei-simple-pre.xml"))
} catch * {
(console:log("It was not possible to open the requested file tei-simple-pre.xml."))
}
let $text := $doc//tei:text
let $text-with-sections := tidySimple:make-structure($text)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-tmp.xml", <div>{$text-with-sections}</div>)
return ""
(: let $doc := doc($config:app-root || "/resources/xml/tei-simple-tmp.xml"):)
(: let $tidied-text := tidySimple:tidy($doc//tei:text):)
(: let $final-tei:=:)
(: <TEI xmlns="http://www.tei-c.org/ns/1.0">:)
(: {$tei//tei:teiHeader}:)
(: {$tidied-text}:)
(: </TEI>:)
(::)
(: return xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple.xml", $final-tei):)
};
......@@ -46,24 +56,49 @@ declare function tidySimple:tidy($nodes as node()*) as node()* {
typeswitch ($node)
case text() return
$node
case element(tei:handShift) return
if(simpleHelpers:is-hand-valid($tidySimple:valid-hands, $node)) then
if(simpleHelpers:is-hand-valid($tidySimple:valid-hands, $node)
and not(simpleHelpers:is-prev-valid-hand-same($tidySimple:valid-hands, $node))) then
tidySimple:clear-handshift($node)
else
()
default return
if(simpleHelpers:belongs-to-valid-hand($tidySimple:valid-hands, $node)) then
tidySimple:copy-second-stage-element($node)
tidySimple:copy-element($node, "tidy")
else
()
};
declare function tidySimple:make-structure($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case element(tei:milestone) return
if($node/@unit = "section") then
tidySimple:make-section($node)
else
tidySimple:make-paragraph($node)
default return
if($node[preceding::tei:milestone]) then
()
else
tidySimple:copy-element($node, "structure")
};
declare function tidySimple:copy-second-stage-element($node as node())
declare function tidySimple:copy-element($node as node(), $flag as xs:string)
as node() {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
$node/@*,
tidySimple:tidy($node/node())
if($flag = "structure") then
tidySimple:make-structure($node/node())
else
tidySimple:tidy($node/node())
}
};
......@@ -85,3 +120,54 @@ as element(tei:handShift) {
$node/@medium
}
};
declare function tidySimple:make-section($node as element(tei:milestone))
as element(tei:div) {
element tei:div {
attribute type {"section"},
tidySimple:get-section-chunk($node)
}
};
(:~
: Returns all nodes between a tei:milestone[@unit = "section"] and its
: corresponding tei:anchor.
:
: @author Michelle Rodzis
: @param the current tei:milestone element
: @return all nodes between the current element and the respective tei:anchor
:)
declare function tidySimple:get-section-chunk($node as element(tei:milestone))
as node()* {
let $target-id := substring-after($node/@spanTo, "#")
let $target := $node/following::tei:anchor[matches(@xml:id, $target-id)]
return
$node/following::*[. << $target]
};
declare function tidySimple:make-paragraph($node as element(tei:milestone))
as element(tei:p) {
element tei:p {
tidySimple:get-paragraph-chunk($node)
}
};
(:~
: Returns all nodes between a tei:milestone[@unit = "paragraph"] and the next
: one.
:
: @author Michelle Rodzis
: @param the current tei:milestone element
: @return all nodes between the current element and the next tei:milestone[@unit = "paragraph"]
:)
declare function tidySimple:get-paragraph-chunk($node as element(tei:milestone))
as node()* {
let $target := $node/following::tei:milestone[@unit = "paragraph"]
return
$node/following::*[. << $target]
};
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -1091,8 +1091,7 @@
<tei:handShift xmlns:tei="http://www.tei-c.org/ns/1.0" new="#Fontane" script="Latn"/>
<tei:item xmlns:tei="http://www.tei-c.org/ns/1.0">
<ref target="#C07_60v_11">C.</ref>
<rs type="direct" ref="psn:Soult">
<tei:handShift new="#Fontane" script="Latn"/>Soult<tei:handShift new="#Fontane" script="Latf"/>
<rs type="direct" ref="psn:Soult">Soult<tei:handShift new="#Fontane" script="Latf"/>
</rs>.</tei:item>
</list>
<tei:handShift xmlns:tei="http://www.tei-c.org/ns/1.0" new="#Fontane" script="Latn"/>
......@@ -1157,9 +1156,7 @@
<tei:handShift xmlns:tei="http://www.tei-c.org/ns/1.0" new="#Fontane" script="Latf"/>
</seg>
<seg type="caption" rendition="margin-left:1.4cm; margin-top:7.0cm">
<tei:handShift xmlns:tei="http://www.tei-c.org/ns/1.0" new="#Fontane" script="Latf"/>
<rs type="direct" ref="plc:Auerstedt">Auerstädt</rs>
<tei:handShift xmlns:tei="http://www.tei-c.org/ns/1.0" new="#Fontane" script="Latf"/>
</seg>
</ab>
<milestone unit="paragraph"/>Es scheint daß wir <hi>nördlich</hi>der von <rs type="direct" ref="plc:Koesen">Kösen </rs>nach <rs type="direct" ref="plc:Eckartsberga">Eckartsberga</rs>führenden Straße standen, wahrscheinlich um und hinter <rs xml:id="C07_61r_c" next="#C07_61r_d" type="direct" ref="plc:Eckartsberga">Eckarts</rs>
......
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