tidysimple.xqm 2.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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";


declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";

MRodz's avatar
MRodz committed
20
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
21
22
23
24
25
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";
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";

MRodz's avatar
MRodz committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

declare variable $tidySimple:valid-hand := 
    for $res in collection("/db/sade-projects/textgrid/data/xml/data")
    return
        $res//tei:handNote[@script = "contemporary"]/@xml:id/string();


declare function tidySimple:main() {
  let $doc :=
    try {
      (doc($config:app-root || "/resources/xml/tei-simple-tmp.xml"))
    } catch * {
      (console:log("It was not possible to open the requested file tei-simple-tmp.xml."))
    }

    let $text := $doc//tei:text
    let $tidied-text := tidySimple:tidy($text)
    let $final-tei:= 
        <TEI xmlns="http://www.tei-c.org/ns/1.0">
            {$doc//tei:teiHeader}
            {$tidied-text}
        </TEI>
        
    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
        (console:log($node),
        typeswitch ($node)
        case text() return
            $node
        case element(tei:handShift) return
            if(simpleHelpers:is-hand-valid($tidySimple:valid-hand, $node)) then
                simpleHelpers:copy-second-stage-element($node)
            else
                ()
        default return
            simpleHelpers:copy-second-stage-element($node))
66
};