index-info.xqm 5.68 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
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, ", "),
mrodzis's avatar
mrodzis committed
48
                "subref-of"     : string-join($entry/parent::tei:place/tei:placeName, ", ")
49
50
51
            }
        ));

MRodz's avatar
MRodz committed
52
declare variable $index-info:psn-map :=
mrodzis's avatar
mrodzis committed
53
    map:merge(for $entry in doc("/db/sade-projects/textgrid/data/xml/data/253sx.xml")//*[self::tei:person or self::tei:personGrp]
mrodzis's avatar
mrodzis committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        let $same-as := $entry/ancestor::tei:listPerson//tei:person[not(@xml:id)][descendant::tei:ptr[contains(@target, $entry/@xml:id)]]/tei:persName
(:        let $works-created-ids := $entry//tei:link[@corresp = "http://purl.org/dc/terms/creator"]/@target/string():)
(:        let $works-created :=:)
(:            for $id in $works-created-ids:)
(:                let $id :=:)
(:                    if(matches($id, " ")) then:)
(:                        substring-before($id, " "):)
(:                        => substring-after(":"):)
(:                    else:)
(:                        substring-after($id, ":"):)
(:                    return:)
(:                        doc("/db/sade-projects/textgrid/data/xml/data/253t3.xml")//tei:item[@xml:id = $id]/tei:name:)
(:        let $works-created := string-join($works-created, "++"):)
        
        return
MRodz's avatar
MRodz committed
69
70
        map:entry(string($entry/@xml:id), 
            map { 
mrodzis's avatar
mrodzis committed
71
72
73
74
                "regular-name"          : string-join($entry/tei:persName[not(@type)], ", "),
                "birth"                 : string($entry/tei:birth),
                "death"                 : string($entry/tei:death),
                "occupation"            : string($entry/tei:occupation),
75
                "relation-to-fontane"   : string($entry/tei:state/tei:desc),
mrodzis's avatar
mrodzis committed
76
77
                "same-as"               : string-join($same-as, "+")
(:                "creator-of"            : string($works-created):)
MRodz's avatar
MRodz committed
78
79
80
81
            }
        ));
        
declare variable $index-info:wrk-map :=
mrodzis's avatar
mrodzis committed
82
83
84
85
86
    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 { 
mrodzis's avatar
mrodzis committed
87
                        "regular-name"  : string-join($entry/tei:name[not(@type)], ", ")
mrodzis's avatar
mrodzis committed
88
89
90
91
92
93
94
95
96
97
98
                    }
                ),
        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)], ", "),
                        "part-of"       : string($person/ancestor::tei:item/tei:name[not(@type)])
                    }
                ))
    );     
MRodz's avatar
MRodz committed
99

mrodzis's avatar
mrodzis committed
100
101
102
103
104
105
106
107
108
(:~
 : 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
 :)
109
110
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
111
112
    local:get-main-entry($term, $index-type) 
    => map:get($info)
113
114
};

MRodz's avatar
MRodz committed
115

mrodzis's avatar
mrodzis committed
116
117
118
119
120
121
122
123
(:~
 : 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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 ()
140
};