tidysimple.xqm 2.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
xquery version "3.1";

(:~
 : This modules handles the conversion of the Fontante-TEI/XML into TEI simplePrint
 : for the edited text. The resulting TEI simplePrint is the basis for the "Editerter
 : Text" (edited text) view on the website and the book. It represents the latest
 : layer of text.
 :
 : @author Michelle Rodzis
 : @version 0.1
 : @since TODO
 :)

module namespace tidySimple ="http://fontane-nb.dariah.eu/tidysimple";

MRodz's avatar
MRodz committed
16

17
declare namespace tei="http://www.tei-c.org/ns/1.0";
MRodz's avatar
MRodz committed
18
declare namespace test="http://exist-db.org/xquery/xqsuite";
19

MRodz's avatar
MRodz committed
20
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
21
22
23
import module namespace console="http://exist-db.org/xquery/console";
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";

MRodz's avatar
MRodz committed
24

25
declare variable $tidySimple:valid-hands :=
MRodz's avatar
MRodz committed
26
27
28
29
30
    for $res in collection("/db/sade-projects/textgrid/data/xml/data")
    return
        $res//tei:handNote[@script = "contemporary"]/@xml:id/string();


MRodz's avatar
MRodz committed
31
32
declare function tidySimple:main($tei as node()*) as xs:string* {
    let $text := $tei//tei:text
MRodz's avatar
MRodz committed
33
    let $tidied-text := tidySimple:tidy($text)
34
    let $final-tei:=
MRodz's avatar
MRodz committed
35
        <TEI xmlns="http://www.tei-c.org/ns/1.0">
MRodz's avatar
MRodz committed
36
            {$tei//tei:teiHeader}
MRodz's avatar
MRodz committed
37
38
            {$tidied-text}
        </TEI>
39

MRodz's avatar
MRodz committed
40
41
42
43
44
45
46
47
48
49
    return xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple.xml", $final-tei)
};


declare function tidySimple:tidy($nodes as node()*) as node()* {
    for $node in $nodes return
        typeswitch ($node)
        case text() return
            $node
        case element(tei:handShift) return
MRodz's avatar
MRodz committed
50
            if(simpleHelpers:is-hand-valid($tidySimple:valid-hands, $node)) then
51
                tidySimple:clear-handshift($node)
MRodz's avatar
MRodz committed
52
53
54
            else
                ()
        default return
55
            if(simpleHelpers:belongs-to-valid-hand($tidySimple:valid-hands, $node)) then
56
                tidySimple:copy-second-stage-element($node)
57
58
            else
                ()
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
};


declare function tidySimple:copy-second-stage-element($node as node())
as node() {
    element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
        $node/@*,
        tidySimple:tidy($node/node())
    }
};


declare function tidySimple:clear-handshift($node as element(tei:handShift))
as element(tei:handShift) {
    element tei:handShift {
        if($node/@new = "") then
            ()
        else
            $node/@new,
        if($node/@script = "") then
            ()
        else
            $node/@script,
        if($node/@medium = "") then
            ()
        else
            $node/@medium
    }
};