Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fontane-notizbuecher
SADE
Commits
23513ad1
Commit
23513ad1
authored
Jun 26, 2018
by
MRodz
Committed by
mrodzis
Feb 05, 2019
Browse files
Move helper function to separate module and rename transformation module
parent
04d88dba
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
modules/fontane/run-transform2teisimple.xql
View file @
23513ad1
xquery version "3.1";
import module namespace fontane-simple="http://fontane-nb.dariah.eu/teisimple" at "/db/apps/SADE/modules/fontane/t
ransform
2teisimple.xqm";
import module namespace fontane-simple="http://fontane-nb.dariah.eu/teisimple" at "/db/apps/SADE/modules/fontane/t
ei
2teisimple.xqm";
fontane-simple:main("16b00.xml")
\ No newline at end of file
modules/fontane/t
ransform
2teisimple.xqm
→
modules/fontane/t
ei
2teisimple.xqm
View file @
23513ad1
This diff is collapsed.
Click to expand it.
modules/fontane/teisimple-test.xql
View file @
23513ad1
This diff is collapsed.
Click to expand it.
modules/fontane/teisimplehelpers.xqm
0 → 100644
View file @
23513ad1
xquery version "3.1";
module namespace fontaneSimpleHelpers="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";
(: 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.
:
: TODO: check if we reach backside of calendar pages at all
: @author Michelle Rodzis
: @param $hand the tei:handShift/@new to be checked
: @return xs:boolean
: :)
declare function fontaneSimpleHelpers: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
if($handNote/@script = "contemporary")
then
true()
else
false()
};
declare function fontaneSimpleHelpers:is-transposed($node as node())
as xs:boolean {
let $root := $node/ancestor::tei:TEI
return
if($root//tei:ptr[contains(@target, $node/@xml:id)]) then
true()
else
false()
};
declare function fontaneSimpleHelpers: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
:
: @author Michelle Rodzis
: @param $node the current text node
: @return text() the formatted text
: :)
declare function fontaneSimpleHelpers:prepare-text($node as text()) as text()? {
if(fontaneSimpleHelpers:is-valid-text($node)) then
let $cleared-hyphen :=
if(ends-with($node, "-") and not(fontaneSimpleHelpers:keep-hyphen($node))) then
text {functx:substring-before-last($node, "-")}
else if(ends-with($node, "⸗") and not(fontaneSimpleHelpers:keep-hyphen($node))) then
text {functx:substring-before-last($node, "⸗")}
else
$node
let $cleared-round-s := replace($cleared-hyphen, "ſ", "s")
(: let $normalized := normalize-space($cleared-round-s):)
return text {$cleared-round-s}
else
()
};
(:~
: 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 fontaneSimpleHelpers: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()
};
(:~
: 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 fontaneSimpleHelpers:copy-element($node as node()) as node() {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
$node/@*,
fontaneSimple:transform($node/node())
}
};
declare function fontaneSimpleHelpers:has-valid-text($node as node()) as xs:boolean {
let $text-nodes := $node/descendant::text()[not(normalize-space(.) = "")]
let $results :=
for $text-node in $text-nodes
return
fontaneSimpleHelpers:is-valid-text($text-node)
return
if(functx:is-value-in-sequence(true(), $results)) then
true()
else
false()
};
declare function fontaneSimpleHelpers:is-valid-text($node as text()) as xs:boolean {
let $current-hand := $node/preceding::tei:handShift[@new][1]/@new
return
if(fontaneSimpleHelpers:is-hand-contemporary($current-hand)
or ($node[ancestor::tei:surface[@type = "label"]]
and matches($current-hand, "Friedrich_Fontane"))
or $node/ancestor::*[@type = "edited_text"]
and not(normalize-space($node) = "")) then
true()
else
false()
};
declare function fontaneSimpleHelpers:is-page($node as node()) 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 fontaneSimpleHelpers:make-pb($node as node()) as element(tei:pb) {
element {QName("http://www.tei-c.org/ns/1.0", "pb")}{
$node/@n
}
};
declare function fontaneSimpleHelpers: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.
:
: @author Michelle Rodzis
: @param $node the current tei:line, tei:zone or tei:seg node
: @return element(tei:head)
: :)
declare function fontaneSimpleHelpers:make-head($node as node()) as element(tei:head) {
element tei:head {
(if($node/descendant::tei:seg[matches(@style, "font-size")]) then
attribute type {fontaneSimpleHelpers:get-font-size($node)}
else
attribute type {"default"}
),
$node/@subtype,
fontaneSimple:transform($node/node())
}
};
(:~
: Creates a tei:div.
:
: @author Michelle Rodzis
: @param $node the current tei:surface node
: @return element(tei:div)
: :)
declare function fontaneSimpleHelpers:make-div($node as node()) as element(tei:div)? {
if(fontaneSimpleHelpers: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 fontaneSimpleHelpers:make-div-with-type($node as node(), $type as xs:string)
as element(tei:div)? {
if(fontaneSimpleHelpers: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
: :)
declare function fontaneSimpleHelpers:get-font-size($node as node()) as xs:string {
(: example for style: "font-size:large; letter-spacing:0.2cm; text-decoration:underline" :)
let $tmp := substring-after($node/descendant-or-self::tei:seg[matches(@style, "font-size")]/@style, "font-size:")
return substring-before($tmp, ";")
};
declare function fontaneSimpleHelpers:filter-rendition($seg-styles as xs:string) as xs:string* {
let $styles := tokenize($seg-styles, " ")
let $relevant-styles :=
for $style in $styles
return
if(matches($style, "font")
or matches($style, "align")
or matches($style, "spacing")
or matches($style, "line-through")) then
$style
else
()
return string-join($relevant-styles, " ")
};
declare function fontaneSimpleHelpers:is-hand-valid($node as element(tei:handShift))
as xs:boolean {
if(fontaneSimpleHelpers:is-hand-contemporary($node/@new)
or ($node/ancestor::tei:surface[@type = "label"]
and matches($node/@new, "Friedrich_Fontane"))
) then
true()
else
false()
};
declare function fontaneSimpleHelpers:is-prev-valid-hand-same($node as element(tei:handShift))
as xs:boolean {
let $prev-valid := $node/preceding::tei:handShift[fontaneSimpleHelpers:is-hand-valid(.)][1]
return
if($prev-valid
and functx:sequence-deep-equal($node/@*, $prev-valid/@*)) then
true()
else
false()
};
\ No newline at end of file
resources/xml/tei-simple.xml
View file @
23513ad1
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment