This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathling.xquery
305 lines (299 loc) · 17.6 KB
/
ling.xquery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
xquery version "3.0";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
(: Local function written by David J. Birnbaum (www.obdurodon.org) :)
declare namespace djb = "www.obdurodon.org";
declare function djb:locus($from as node(), $to as node())
{
(if ($from eq $to)
then
$from/string()
else
if (substring($from, 1, string-length($from) - 1) eq substring($to, 1, string-length($to) - 1))
then
concat($from, '-v')
else
concat($from, '-', $to))
};
declare variable $search := request:get-parameter("phenomenon", ());
let $values := tokenize($search, ',')
let $songs := collection('/db/variatio/edition')//tei:div[@type eq 'poem']
let $readings := $songs//tei:rdg
let $ling-features := doc('/db/variatio/ancillary/feature-library.xml')//tei:fs[tei:f[@name eq 'taxonomy']/tei:fs[@type eq 'linguistic']]
let $poets := doc('/db/variatio/ancillary/corpus-autores.xml')//tei:person
return
<div
class="multiple">
<section
class="phenom">
{
for $result in $values
return
(<h2><span
class="pt" id="graf{$result}">{transform:transform($ling-features[@xml:id = $result]//tei:string[@xml:lang eq 'pt']/text(), 'xmldb:exist:///db/variatio/xslt/string.xsl', ())}</span>
<span
class="gl" id="grafo{$result}">{transform:transform($ling-features[@xml:id = $result]//tei:string[@xml:lang eq 'gl']/text(), 'xmldb:exist:///db/variatio/xslt/string.xsl', ())}</span><span
class="en" id="graphs{$result}">{transform:transform($ling-features[@xml:id = $result]//tei:string[@xml:lang eq 'en']/text(), 'xmldb:exist:///db/variatio/xslt/string.xsl', ())}</span></h2>,
<h3><span
class="pt">Testemunho</span><span
class="gl">Testemuño</span><span
class="en">Witness</span></h3>,
<svg
xmlns="http://www.w3.org/2000/svg"
width="950"
height="100">
{
let $fen := $readings[some $ana in tokenize(@ana, '\s+') satisfies $ana = concat('#', $result)]
for $wit at $pos in
for $i in distinct-values($fen/tokenize(./@wit, '\s+'))
order by count($fen[./tokenize(@wit, '\s+') = $i]) descending
return
$i
let $count := count($fen[contains(@wit, $wit)])
let $sum := count($fen)
let $percentage := round-half-to-even((100 * $count div $sum), 2)
order by $count descending
return
<g>
<rect
fill="blue"
height="22"
width="{$count * 6.5}"
x="70"
y="{$pos * 22}"
stroke="#EAE5C5"
/>
<text
fill="black"
font-size="12"
x="{80 + $count * 6.5}"
y="{$pos * 22 + 14}"
>{' (' || $percentage || '%)'}</text>
<text
fill="black"
x="10"
y="{$pos * 20 + 18}"
>Ms. {substring($wit, 2)}</text>
{
let $hand := $songs[.//tei:rdg[. intersect $fen[contains(@wit, $wit)]]]/tei:head//tei:rdg[@wit = $wit]/@hand
let $distinctHands := distinct-values($hand)
for $h in 1 to count($distinctHands)
let $x := count($songs[tei:head//tei:rdg[@wit = $wit][@hand = $distinctHands[position() lt $h]]]
//tei:rdg[. intersect $fen][contains(@wit, $wit)])
let $div := $songs[tei:head//tei:rdg[@wit = $wit][@hand = $distinctHands[$h]]][.//tei:rdg[. intersect $fen]]
let $conta := count($div//tei:rdg[. intersect $fen[contains(@wit, $wit)]])
order by $h descending
return
<g>
<rect
fill="#2B3966"
height="22"
width="{$conta * 6.5}"
x="{$x * 6.5 + 70}"
y="{$pos * 22}"
stroke="#EAE5C5"
stroke-width="2"/>
<text
fill="white"
font-size="10.5"
x="{($x * 6.5 + 68) + (($conta * 6.5) div 2)}"
y="{$pos * 22 + 12}">{substring($distinctHands[$h], 2)}</text>
</g>
}
</g>
}</svg>,
<h3 id="lg{$result}"><span
class="pt gl" id="lingua{$result}">Período</span><span
class="en">Period</span></h3>,
<svg id="ling{$result}"
xmlns="http://www.w3.org/2000/svg"
width="950"
height="100">
{
let $fen := $readings[some $ana in tokenize(@ana, '\s+') satisfies $ana = concat('#', $result)]
for $period at $pos in
for $i in distinct-values($poets[@xml:id = $fen/ancestor::tei:div[1]//tei:name/substring(@ref, 2)]/tei:floruit/@period)
order by count($fen[ancestor::tei:div[1]//tei:name/substring(@ref, 2) = $poets/tei:floruit[@period = $i]/../@xml:id]) descending
return
$i
let $count := count($fen[ancestor::tei:div[1]//tei:name/substring(@ref, 2) = $poets/tei:floruit[@period = $period]/../@xml:id])
let $sum := count($fen)
let $percentage := round-half-to-even((100 * $count div $sum), 2)
order by $count descending
return
<g>
<rect
fill="#2B3966"
height="22"
width="{$count * 6.5}"
x="70"
y="{$pos * 22}"
stroke="#EAE5C5"
stroke-width="2"/>
<text
fill="black"
font-size="12"
x="{80 + $count * 6.5}"
y="{$pos * 22 + 14}"
>{' (' || $percentage || '%)'}</text>
<text
fill="black"
x="10"
y="{$pos * 20 + 18}"
>Per. {$period}</text>
</g>
}</svg>,
<table
class="sortable">
<thead>
<tr
class="head">
<th><span
class="pt gl">Fenómeno</span><span
class="en">Phenomenon</span>
</th>
<th><span
class="pt">Testemunho</span><span class="gl">Testemuño</span><span
class="en">Witness</span>
</th>
<th><span
class="pt">Localização</span><span class="gl">Localización</span><span
class="en">Location</span>
</th>
<th><span
class="pt gl">Copista</span><span
class="en">Copyist</span>
</th>
<th><span
class="pt gl">Autor</span><span
class="en">Author</span>
</th>
<th><span
class="pt gl">Período</span><span
class="en">Period</span>
</th>
<th><span
class="pt gl">Cantiga</span><span
class="en">Song</span>
</th>
<th><span
class="pt gl">V.</span><span
class="en">L.</span>
</th>
</tr>
</thead>
<tbody>
{
for $fen in $readings[some $ana in tokenize(@ana, '\s+') satisfies $ana = concat('#', $result)]
let $rdg :=
<parameters>
<param
name="rdg"
value="{$fen}"/>
<param
name="ana"
value="{$result}"/>
</parameters>
let $author := $poets[@xml:id = $fen/ancestor::tei:div[1]//tei:name/substring(@ref, 2)]
return
<tr>
<td class="intro"><a
href="http://gl-pt.obdurodon.org/edition.php?&song[]={$fen/ancestor::tei:div[1]/substring(@corresp, 2)}&line={$fen/ancestor::tei:l/@n/string()}"
target="_blank">{transform:transform($fen/.., 'xmldb:exist:///db/variatio/xslt/ex.xsl', ($rdg))}</a></td>
<td>{
(if ($fen/contains(@wit, ' ')) then
<ul>{
for $wit in tokenize($fen/@wit, '\s+')
order by $wit
return
<li>{substring($wit, 2)}</li>
}</ul>
else
$fen/substring(@wit, 2)
)
}</td>
<td>{
(if (contains($fen/@wit, ' ')) then
<ul>{
for $wit in tokenize($fen/@wit, '\s+')
order by $wit
return
<li>{djb:locus($fen/ancestor::tei:div[1]/tei:head//tei:rdg[@wit = $wit]/tei:locus/@from, $fen/ancestor::tei:div[1]/tei:head//tei:rdg[@wit = $wit]/tei:locus/@to)
}</li>
}</ul>
else
djb:locus($fen/ancestor::tei:div[1]/tei:head//tei:rdg[@wit = $fen/@wit]/tei:locus/@from, $fen/ancestor::tei:div[1]/tei:head//tei:rdg[@wit = $fen/@wit]/tei:locus/@to))
}</td>
<td>{
(if (contains($fen/@wit, ' ')) then
<ul>{
for $wit in tokenize($fen/@wit, '\s+')
order by $wit
return
<li>{$fen/ancestor::tei:div[1]/tei:head//tei:rdg[@wit = $wit]/substring(@hand, 2)}</li>
}</ul>
else
$fen/ancestor::tei:div[1]/tei:head//tei:rdg[@wit = $fen/@wit]/substring(@hand, 2))
}</td>
<td>{$author/tei:persName/string()}</td>
<td>{$author/tei:floruit/@from || '-' || $author/tei:floruit/@to || ' (' || $author/tei:floruit/@period || ')'}</td>
<td>{$fen/ancestor::tei:div[1]/string-join(descendant::tei:title//tei:idno, ', ')}</td>
<td>{$fen/ancestor::tei:l/@n/string()}</td>
</tr>
}
</tbody>
</table>)
}
</section>
<aside
id="summary">
<h3><span class="pt">Conteúdos</span><span class="en">Contents</span><span class="gl">Contidos</span></h3>
<div class="en">
<ul>
{
for $result in $values
return
<li>{transform:transform($ling-features[@xml:id = $result]//tei:string[@xml:lang eq 'en']/text(), 'xmldb:exist:///db/variatio/xslt/string.xsl', ())}
<ul>
<li><a
href="#graphs{$result}">Graph</a></li>
<li><a
href="#ling{$result}">Table</a></li>
</ul>
</li>
}
</ul>
</div>
<div class="pt">
<ul>
{
for $result in $values
return
<li>{transform:transform($ling-features[@xml:id = $result]//tei:string[@xml:lang eq 'pt']/text(), 'xmldb:exist:///db/variatio/xslt/string.xsl', ())}
<ul>
<li><a
href="#graf{$result}">Gráficas</a></li>
<li><a
href="#lingua{$result}">Tabela</a></li>
</ul>
</li>
}
</ul>
</div>
<div class="gl">
<ul>
{
for $result in $values
return
<li>{transform:transform($ling-features[@xml:id = $result]//tei:string[@xml:lang eq 'gl']/text(), 'xmldb:exist:///db/variatio/xslt/string.xsl', ())}
<ul>
<li><a
href="#grafo{$result}">Gráficas</a></li>
<li><a
href="#lg{$result}">Táboa</a></li>
</ul>
</li>
}
</ul>
</div>
</aside>
</div>