Commit 6c4929c7 authored by Michelle Rodzis's avatar Michelle Rodzis Committed by mrodzis
Browse files

Tidy up and add documentation

parent 731de601
xquery version "3.1";
import module namespace fontane-simple="http://fontane-nb.dariah.eu/teisimple" at "/db/apps/SADE/modules/fontane/tei2teisimple.xqm";
(:~
: This modules runs the first and second process that transforms the Fontane
: TEI subset into the TEI simplePrint encoding.
:
: @author Michelle Rodzis
: @version 1.0
:)
fontane-simple:main("16b00.xml")
\ No newline at end of file
import module namespace fontane-simple="http://fontane-nb.dariah.eu/teisimple"
at "/db/apps/SADE/modules/fontane/tei2teisimple.xqm";
fontane-simple:main("16b00.xml")
This diff is collapsed.
......@@ -4,11 +4,9 @@ xquery version "3.1";
import module namespace teisimple-test = "http://fontane-nb.dariah.eu/teisimple-test" at "teisimple-test.xql";
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
import module namespace console="http://exist-db.org/xquery/console";
declare namespace tei="http://www.tei-c.org/ns/1.0";
test:suite(
util:list-functions("http://fontane-nb.dariah.eu/teisimple-test")
)
xquery version "3.1";
(:~
: This module contains a potpourri of functions that are needed to serialize
: the TEI simplePrint version of the Fontane TEI encoding.
:
: @author Michelle Rodzis
: @version 1.0
:)
module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers";
declare namespace tei="http://www.tei-c.org/ns/1.0";
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 fontaneSimple="http://fontane-nb.dariah.eu/teisimple" at "tei2teisimple.xqm";
import module namespace functx = "http://www.functx.com";
......@@ -12,22 +19,19 @@ import module namespace functx = "http://www.functx.com";
(: TODO: adapt to general XML :)
(:~
: Determines whether the passed tei:handShift is contemporary or not. For the
: edited text we only need to consider contemporary hands or additions of
: Friedrich Fontane if they occur on labels and on the backside of calendar
: pages.
:
: Determines whether the passed tei:handShift is contemporary or not.
:
: TODO: check if we reach backside of calendar pages at all
: @author Michelle Rodzis
: @param $hand the tei:handShift/@new or tei:mod/@hand to be checked
: @return xs:boolean
: :)
declare function simpleHelpers:is-hand-contemporary($hand as xs:string?)
:)
declare function simpleHelpers: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]
return
return
if($handNote/@script = "contemporary")
then
true()
......@@ -36,8 +40,17 @@ as xs:boolean {
};
declare function simpleHelpers:is-transposed($node as node())
(:~
: Checks if a node is transposed, i.e. if is encoded at another place than it
: should be serialized.
:
: TODO: doesn't work at the moment
:
: @author Michelle Rodzis
: @param $node the current TEI node to be checked
: @return xs:boolean
:)
declare function simpleHelpers:is-transposed($node as node())
as xs:boolean {
let $root := $node/ancestor::tei:TEI
return
......@@ -47,23 +60,15 @@ as xs:boolean {
false()
};
declare function simpleHelpers:strip-element($node as node()) {
element {$node/name()} {
$node/@type,
fontaneSimple:transform($node/node())
}
};
(:~
: Performs a couple of processing steps on a text node:
:
:
: 1. for the edited text only hyphens that are marked with
: <tei:lb break="keepHyphen"/> should be displayed
: 2. round s (ſ) is normalized to s
: 3. inserts an additional whitespace if a line ends with a character
:
: 2. round s (ſ) is normalized to "s"
: 3. the Tironian note is normalized to "etc.""
: 4. inserts an additional whitespace if a line ends with a character (TODO)
:
: @author Michelle Rodzis
: @param $node the current text node
: @return text() the formatted text
......@@ -71,7 +76,7 @@ declare function simpleHelpers:strip-element($node as node()) {
declare function simpleHelpers:prepare-text($node as text()) as text()? {
if(simpleHelpers:is-valid-text($node)
and not(normalize-space($node) = "")) then
let $cleared-hyphen :=
let $cleared-hyphen :=
if(ends-with($node, "-") and not(simpleHelpers:keep-hyphen($node))) then
text {functx:substring-before-last($node, "-")}
else if(ends-with($node, "⸗") and not(simpleHelpers:keep-hyphen($node))) then
......@@ -96,12 +101,12 @@ declare function simpleHelpers:prepare-text($node as text()) as text()? {
(:~
: Checks if a hyphen should be kept for the edited text or not.
:
: Checks if a hyphen should be kept for the edited text or not.
:
: @author Michelle Rodzis
: @param $node the current text node
: @return xs:boolean
: :)
:)
declare function simpleHelpers:keep-hyphen($node as text()) as xs:boolean {
if($node/parent::tei:line/following-sibling::*[1][self::tei:lb[@break = "keepHyphen"]])
then
......@@ -112,11 +117,11 @@ declare function simpleHelpers:keep-hyphen($node as text()) as xs:boolean {
(:~
: Takes a given element over as is since it is compliant to TEI simplePrint.
:
:
: @author Michelle Rodzis
: @param $node the current text node
: @return node() a copy of the current node
: :)
:)
declare function simpleHelpers:copy-element($node as node()) as node() {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
$node/@*,
......@@ -125,13 +130,20 @@ declare function simpleHelpers:copy-element($node as node()) as node() {
};
(:~
: Checks if the current node has valid text.
:
: @author Michelle Rodzis
: @param $node
: @return xs:boolean
:)
declare function simpleHelpers:has-valid-text($node as node()) as xs:boolean {
let $text-nodes := $node/descendant::text()[not(normalize-space(.) = "")]
let $results :=
let $results :=
for $text-node in $text-nodes
return
return
simpleHelpers:is-valid-text($text-node)
return
return
if(functx:is-value-in-sequence(true(), $results)) then
true()
else
......@@ -139,6 +151,16 @@ declare function simpleHelpers:has-valid-text($node as node()) as xs:boolean {
};
(:~
: Checks if a text node has valid text. A text is valid if it is written by a
: contemporary hand or by Friedrich Fontane (in case it's text on a label or
: on a calendar (TODO)). The same holds for notes of the modern editors which
: are marked by @type = "edited_text".
:
: @author Michelle Rodzis
: @node a text node
: @return xs:boolean
:)
declare function simpleHelpers:is-valid-text($node as text()) as xs:boolean {
let $current-hand := $node/preceding::tei:handShift[@new][1]/@new
return
......@@ -148,39 +170,56 @@ declare function simpleHelpers:is-valid-text($node as text()) as xs:boolean {
or $node/ancestor::*[@type = "edited_text"]
and not(normalize-space($node) = "")) then
true()
else
else
false()
};
declare function simpleHelpers:is-page($node as node()) as xs:boolean {
(:~
: Checks if the current tei:surface is a page. Pages can be recognized by their
: pagination (e.g. 4v) in the node's @n.
:
: @author Michelle Rodzis
: @node element(tei:surface)
: @return xs:boolean
:)
declare function simpleHelpers:is-page($node as element(tei:surface))
as xs:boolean {
matches($node/@n, "[0-9IVXMCD]{1,7}[rv]{1}")
};
(:~
: Creates a tei:pb.
:
:
: @author Michelle Rodzis
: @param $node the current tei:surface node
: @return element(tei:pb)
: :)
declare function simpleHelpers:make-pb($node as node()) as element(tei:pb) {
:)
declare function simpleHelpers:make-pb($node as element(tei:suface))
as element(tei:pb) {
element {QName("http://www.tei-c.org/ns/1.0", "pb")}{
$node/@n
}
};
declare function simpleHelpers:make-pb-with-type($type as xs:string) as element(tei:pb) {
(:~
: Creates a tei:pb with a type instead of a @n representing the pagination.
: This function is mainly used to separate the inner and outer book covers from
: each other.
:
: @author Michelle Rodzis
: @param $node the current tei:surface node
: @return element(tei:pb)
:)
declare function simpleHelpers: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.
:
: Creates a tei:head with an @rendition and a font-size, if available.
:
: @author Michelle Rodzis
: @param $node the current tei:line, tei:zone or tei:seg node
: @return element(tei:head)
......@@ -189,7 +228,7 @@ declare function simpleHelpers:make-head($node as node()) as element(tei:head) {
element tei:head {
(if($node/descendant::tei:seg[matches(@style, "font-size")]) then
attribute type {simpleHelpers:get-font-size($node)}
else
else
attribute type {"default"}
),
$node/@subtype,
......@@ -201,41 +240,27 @@ declare function simpleHelpers:make-head($node as node()) as element(tei:head) {
}
};
(:~
: Creates a tei:div.
:
:
: @author Michelle Rodzis
: @param $node the current tei:surface node
: @return element(tei:div)
: :)
declare function simpleHelpers:make-div($node as node()) as element(tei:div)? {
if(simpleHelpers:has-valid-text($node)) then
element tei:div{
$node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
fontaneSimple:transform($node/node())
}
else
()
};
declare function simpleHelpers:make-div-with-type($node as node(), $type as xs:string)
declare function simpleHelpers:make-div($node as element(tei:surface))
as element(tei:div)? {
if(simpleHelpers:has-valid-text($node)) then
element tei:div{
attribute type {$type},
$node/(@* except (@facs, @n, @attachment, @subtype, @ulx, @uly, @lrx, @lry, @points)),
fontaneSimple:transform($node/node())
}
}
else
()
};
(:~
: Retrieves the font size from the @style of a tei:seg.
:
:
: @author Michelle Rodzis
: @param $node the current tei:line, tei:zone or tei:seg node with @type = heading
: @return xs:string the font size value
......@@ -246,11 +271,17 @@ declare function simpleHelpers:get-font-size($node as node()) as xs:string {
return substring-before($tmp, ";")
};
declare function simpleHelpers:has-valid-style($node as node())
(:~
: Checks if a node's @style attribute contains any relevant information.
:
: @author Michelle Rodzis
: @param $node the current tei:zone, tei:line, or tei:seg node
: @return xs:boolean
:)
declare function simpleHelpers:has-valid-style($node as node())
as xs:boolean {
let $style := $node/@style
return
return
if(matches($style, "font")
or matches($style, "align")
or matches($style, "spacing")
......@@ -264,12 +295,24 @@ as xs:boolean {
false()
};
(:~
: Returns a sequence of strings containing renditions that are relevant for an
: element in the edited text and are merged into a single @rendition.
:
: Since this information can be held either in a node's @style or in its
: @rendition, we have to check both of them separately before combining them
: into one element for convenience reasons.
: TODO: check if @rendition is the right attribute for that
:
: @author Michelle Rodzis
: @param $node the current tei:zone, tei:line, or tei:seg element
: @return a string of all relevant information
:)
declare function simpleHelpers:filter-rendition($node as node()) as xs:string* {
let $styles := tokenize($node/@style, " ")
let $relevant-styles :=
for $style in $styles
return
return
if(matches($style, "font")
or matches($style, "align")
or matches($style, "spacing")
......@@ -294,11 +337,20 @@ declare function simpleHelpers:filter-rendition($node as node()) as xs:string* {
else
$rend
let $new-renditions := ($relevant-styles, $transformed-renditions)
return string-join($new-renditions, " ")
return string-join($new-renditions, " ")
};
declare function simpleHelpers:is-hand-valid($node as element(tei:handShift))
(:~
: Checks if the current hand is valid. For the edited text we only need to
: consider contemporary hands/prints or additions by Friedrich Fontane if they
: occur on labels and on the backside of calendar pages.
:
: TODO check if we reach calendar pages
: @author Michelle Rodzis
: @param $node the current tei:handShift element
: @return xs:boolean
:)
declare function simpleHelpers:is-hand-valid($node as element(tei:handShift))
as xs:boolean {
if(simpleHelpers:is-hand-contemporary($node/@new)
or ($node/ancestor::tei:surface[@type = "label"]
......@@ -309,11 +361,18 @@ as xs:boolean {
false()
};
declare function simpleHelpers:is-prev-valid-hand-same($node as element(tei:handShift))
(:~
: Checks if the previous valid handShift is the same as the current handShift.
: This does not only encompass the writer but also the script type and ductus.
:
: @author Michelle Rodzis
: @param $node the current tei:handShift element
: @return xs:boolean
:)
declare function simpleHelpers:is-prev-valid-hand-same($node as element(tei:handShift))
as xs:boolean {
let $prev-valid := $node/preceding::tei:handShift[simpleHelpers:is-hand-valid(.)][1]
return
return
if($prev-valid
and functx:sequence-deep-equal($node/@*, $prev-valid/@*)) then
true()
......@@ -323,29 +382,42 @@ as xs:boolean {
(: TODO :)
declare function simpleHelpers:make-section($node as element(tei:milestone))
(:declare function simpleHelpers:make-section($node as element(tei:milestone))
as element(tei:section) {
let $id := substring-after($node/@spanTo, "#")
let $corresp := $node/following::*[$id = @xml:id]
let $bla := console:log(util:get-fragment-between($node, $corresp, true(), true()))
return
<div/>
};
};:)
declare function simpleHelpers:make-seg-with-rendition($node as element(*))
(:~
: Creates a new tei:seg with all relevant rendition information.
:
: @author Michelle Rodzis
: @param $node the current tei:zone, tei:line, or tei:seg element
: @return element(tei:seg)
:)
declare function simpleHelpers:make-seg-with-rendition($node as element(*))
as element(tei:seg) {
element tei:seg {
attribute rendition {simpleHelpers:filter-rendition($node)},
$node/(@* except (@style, @rendition)),
fontaneSimple:transform($node/node())
}
}
};
(:~
: 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
};
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