index-info.xqm 5.06 KB
Newer Older
1
2
3
xquery version "3.1";

(:~
mrodzis's avatar
mrodzis committed
4
5
 : This module is responsible for retrieving all relevant information from the
 : different indicies in order to create a tei:index in the simpler TEI.
6
 :
MRodz's avatar
MRodz committed
7
 : @author Michelle Weidling
8
 : @version 0.1
mrodzis's avatar
mrodzis committed
9
 : @since v4.0.
10
11
12
13
14
15
16
17
18
19
20
 :)

module namespace index-info="http://fontane-nb.dariah.eu/index-info";

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 simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";

declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace tei="http://www.tei-c.org/ns/1.0";

MRodz's avatar
MRodz committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
declare variable $index-info:event-map :=
    map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t0.xml")//tei:event
    return 
        map:entry(string($entry/@xml:id), 
            map { 
                "regular-name"  : string-join($entry/tei:label[not(@type)], ", "),
                "place"         : string-join($entry/@where),
                "occs-in-nbs"   : ""
            }
        ));

declare variable $index-info:org-map := 
    map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t1.xml")//tei:org
    return 
        map:entry(string($entry/@xml:id), 
            map { 
MRodz's avatar
MRodz committed
37
                "regular-name"  : string-join($entry/tei:orgName[not(@type)], ", "),
MRodz's avatar
MRodz committed
38
39
40
41
                "occs-in-nbs"   : ""
            }
        ));

42
43
44
45
46
47
48
49
50
51
52
declare variable $index-info:place-map :=
    map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t2.xml")//tei:place
    return 
        map:entry(string($entry/@xml:id), 
            map { 
                "regular-name"  : string-join($entry/tei:placeName, ", "),
                "subref-of"     : string-join($entry/parent::tei:place/tei:placeName, ", "),
                "occs-in-nbs"   : ""
            }
        ));

MRodz's avatar
MRodz committed
53
declare variable $index-info:psn-map :=
54
    map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/test-psn.xml")//*[self::tei:person or self::tei:personGrp]
MRodz's avatar
MRodz committed
55
56
57
    return 
        map:entry(string($entry/@xml:id), 
            map { 
mrodzis's avatar
mrodzis committed
58
59
60
61
62
                "regular-name"          : string-join($entry/tei:persName[not(@type)], ", "),
                "birth"                 : string($entry/tei:birth),
                "death"                 : string($entry/tei:death),
                "occupation"            : string($entry/tei:occupation),
                "occs-in-nbs"           : "",
63
64
                "relation-to-fontane"   : string($entry/tei:state/tei:desc),
                "same-as"               : string($entry/ancestor::tei:listPerson//tei:person[not(@xml:id)][descendant::tei:ptr[contains(@target, $entry/@xml:id)]]/tei:persName)
MRodz's avatar
MRodz committed
65
66
67
68
            }
        ));
        
declare variable $index-info:wrk-map :=
mrodzis's avatar
mrodzis committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    map:merge(
        (for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253t3.xml")//tei:item
            return 
                map:entry(string($entry/@xml:id), 
                    map { 
                        "regular-name"  : string-join($entry/tei:name[not(@type)], ", "),
                        "occs-in-nbs"   : ""
                    }
                ),
        for $person in doc("/db/sade-projects/textgrid/data/xml/data/253t3.xml")//tei:person
            return 
                map:entry(string($person/@xml:id), 
                    map { 
                        "regular-name"  : string-join($person/tei:persName[not(@type)], ", "),
                        "occs-in-nbs"   : "",
                        "part-of"       : string($person/ancestor::tei:item/tei:name[not(@type)])
                    }
                ))
    );     
MRodz's avatar
MRodz committed
88

mrodzis's avatar
mrodzis committed
89
90
91
92
93
94
95
96
97
(:~
 : Gets information about a given term.
 :
 : @author Michelle Weidling
 : @param $index-type the index type ("psn", "eve", ...)
 : @param $term the current term, e.g. plc:Lueneburg
 : @param $info the specific information to be retrieved, e.g. "regular-name"
 : @return the information asked
 :)
98
99
declare function index-info:get-info-about($index-type as xs:string, 
$term as xs:string, $info as xs:string) as xs:string* {
mrodzis's avatar
mrodzis committed
100
101
    local:get-main-entry($term, $index-type) 
    => map:get($info)
102
103
};

MRodz's avatar
MRodz committed
104

mrodzis's avatar
mrodzis committed
105
106
107
108
109
110
111
112
(:~
 : Selects the right entry on the first level of the map.
 :
 : @author Michelle Weidling
 : @param $ref the current term, e.g. plc:Lueneburg
 : @param $index-type the index type ("psn", "eve", ...)
 : @return a map with all available information about the given term
 :)
MRodz's avatar
MRodz committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
declare function local:get-main-entry($ref as xs:string, 
$index-type as xs:string) as map()* {
    let $key := substring-after($ref, ":")
    return 
        switch ($index-type)
            case "eve" return
                map:get($index-info:event-map, $key)
            case "org" return
                map:get($index-info:org-map, $key)                
            case "plc" return
                map:get($index-info:place-map, $key)
            case "psn" return
                map:get($index-info:psn-map, $key)             
            case "wrk" return
                map:get($index-info:wrk-map, $key)                
            default return ()
129
};