-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathparlamint2xmlvert.xsl
410 lines (386 loc) · 17 KB
/
parlamint2xmlvert.xsl
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?xml version="1.0"?>
<!-- Transform one ParlaMint file to CQP vertical format.
Note that the output is still in XML, and needs another polish. -->
<!-- Needs the file with corpus teiHeader as the value of the "meta" parameter (cf. parlamint-lib.xsl) -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:et="http://nl.ijs.si/et"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xi="http://www.w3.org/2001/XInclude"
exclude-result-prefixes="fn et tei xs xi"
version="2.0">
<xsl:import href="parlamint-lib.xsl"/>
<xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>
<!-- Do we want the syntactic dependency and head attributes? -->
<xsl:param name="nosyntax"/>
<!-- String to put at the start and end of "incidents", i.e. transcriber notes -->
<xsl:param name="note-open">[</xsl:param>
<xsl:param name="note-close">]</xsl:param>
<xsl:param name="country-code" select="replace(/tei:TEI/@xml:id,
'.*?-([^._]+).*', '$1')"/>
<xsl:template match="@*"/>
<xsl:template match="text()"/>
<xsl:template match="tei:*">
<xsl:message>
<xsl:text>WARN: unexpected element </xsl:text>
<xsl:value-of select="name()"/>
<xsl:value-of select="concat(' in ', ancestor::tei:TEI/@xml:id, ' : ', @xml:id)"/>
</xsl:message>
</xsl:template>
<xsl:template match="tei:TEI">
<xsl:message select="concat('INFO: Converting ', @xml:id, ' to vertical')"/>
<xsl:apply-templates select="tei:text/tei:body/tei:div[tei:u]/tei:*"/>
</xsl:template>
<xsl:template match="tei:div/tei:u">
<xsl:variable name="speech_id" select="replace(@xml:id, '\.ana', '')"/>
<xsl:variable name="lang">
<xsl:call-template name="u-langs"/>
</xsl:variable>
<!-- Topics are given only in IS and DK corpora -->
<xsl:variable name="topic">
<xsl:choose>
<xsl:when test="$country-code = 'DK'">
<!-- E.g.
<u who="#HaarderBertel" xml:id="ParlaMint-DK_20141007120002" ana="#chair #domain.other">
+
<taxonomy xmlns="http://www.tei-c.org/ns/1.0" xml:id="ParlaMint-DK-taxonomy-domains" xml:lang="mul">
<desc xml:lang="en"><term>Policy domains</term> in the ParlaMint-DK corpus</desc>
<desc xml:lang="da"><term>Politiske emneområder</term> i ParlaMint-DK</desc>
<category xml:id="domain.Agriculture">
<catDesc xml:lang="en"><term>Agriculture</term>: comprises Agriculture, Fisheries, Food, Consumer, and Animal welfare</catDesc>
<catDesc xml:lang="da"><term>Landbrug</term>: omfatter Landbrug, Fiskeri, Fødevarer, Forbruger, og Dyrevelfærd</catDesc>
</category>
etc.
= (dk):
<speech id="ParlaMint-DK_20141007120002" ... topic="Folketingsanliggender">
-->
<xsl:variable name="topics">
<xsl:for-each select="tokenize(@ana, ' ')">
<xsl:sort select="."/>
<xsl:variable name="topic" select="key('idr', ., $rootHeader)"/>
<!-- Topic names are stored in DK "domains" taxonomy -->
<xsl:if test="$topic/ancestor::tei:taxonomy/contains(@xml:id, 'taxonomy-domains')">
<xsl:value-of select="et:l10n($corpus-language, $topic/tei:catDesc/tei:term)"/>
<xsl:value-of select="$multi-separator"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="et:tsv-value(replace($topics, '.$', ''))"/>
</xsl:when>
<xsl:when test="$country-code = 'IS'">
<!-- IS has first a pointer to (debate) "topics", and from there to categories (topics proper) -->
<xsl:variable name="IS-topics">
<xsl:for-each select="tokenize(@ana, ' ')">
<xsl:value-of select="key('idr', ., $rootHeader)
[contains(ancestor::tei:taxonomy/@xml:id, 'parla.topics')]/@ana"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="topics">
<xsl:for-each select="distinct-values(tokenize(normalize-space($IS-topics), ' '))">
<xsl:sort select="."/>
<!-- Localisation of the term in category description -->
<xsl:value-of select="et:l10n($corpus-language, key('idr', ., $rootHeader)/tei:catDesc/tei:term)"/>
<xsl:value-of select="$multi-separator"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="et:tsv-value(replace($topics, '.$', ''))"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<speech id="{$speech_id}" text_id="{$text_id}"
subcorpus="{$subcorpus}" lang="{$lang}" body="{$body}"
term="{$term}" session="{$session}" meeting="{$meeting}" sitting="{$sitting}" agenda="{$agenda}"
date="{$at-date}" title="{$title}">
<xsl:attribute name="speaker_role" select="et:u-role(@ana)"/>
<xsl:if test="normalize-space($topic)">
<xsl:attribute name="topic" select="$topic"/>
</xsl:if>
<!-- Sentiment is given currently only in SI corpus -->
<xsl:if test="$country-code = 'SI'">
<xsl:attribute name="senti_3">
<xsl:call-template name="senti">
<xsl:with-param name="type">3</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="senti_6">
<xsl:call-template name="senti">
<xsl:with-param name="type">6</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="senti_n">
<xsl:call-template name="senti">
<xsl:with-param name="type">n</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="@who">
<xsl:variable name="speaker" select="key('idr', @who, $rootHeader)"/>
<xsl:if test="not($speaker/@xml:id)">
<xsl:message select="concat('ERROR: cannot find person ', @who, ' in ', $text_id)"/>
</xsl:if>
<xsl:attribute name="speaker_id" select="$speaker/@xml:id"/>
<xsl:attribute name="speaker_name" select="et:format-name-chrono(
$speaker//tei:persName,
$at-date)"/>
<xsl:attribute name="speaker_mp" select="et:speaker-mp($speaker)"/>
<xsl:attribute name="speaker_minister" select="et:speaker-minister($speaker)"/>
<xsl:attribute name="speaker_party" select="et:speaker-party($speaker, 'abb')"/>
<xsl:attribute name="speaker_party_name" select="et:speaker-party($speaker, 'yes')"/>
<xsl:attribute name="party_status" select="et:party-status($speaker)"/>
<xsl:attribute name="party_orientation" select="et:party-orientation($speaker)"/>
<xsl:attribute name="speaker_gender" select="et:tsv-value($speaker/tei:sex/@value)"/>
<xsl:attribute name="speaker_birth" select="et:tsv-value(replace($speaker/tei:birth/@when, '-.+', ''))"/>
</xsl:when>
<!-- No @who, legit if speaker is unknown -->
<xsl:otherwise>
<xsl:attribute name="speaker_id">-</xsl:attribute>
<xsl:attribute name="speaker_name">-</xsl:attribute>
<xsl:attribute name="speaker_mp">-</xsl:attribute>
<xsl:attribute name="speaker_minister">-</xsl:attribute>
<xsl:attribute name="speaker_party">-</xsl:attribute>
<xsl:attribute name="speaker_party_name">-</xsl:attribute>
<xsl:attribute name="party_status">-</xsl:attribute>
<xsl:attribute name="party_orientation">-</xsl:attribute>
<!-- Unlike elsewhere, we set the gender and U(known), to be same is speeches by speaker with U gender -->
<xsl:attribute name="speaker_gender">U</xsl:attribute>
<xsl:attribute name="speaker_birth">-</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</speech>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="tei:pb"/>
<!-- Conflate head, note, gap and all "incidents" into <note> -->
<xsl:template match="tei:head | tei:note | tei:gap | tei:vocal | tei:incident | tei:kinesic">
<note>
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="self::tei:head">head</xsl:when>
<xsl:when test="self::tei:note[@type]">
<xsl:value-of select="@type"/>
</xsl:when>
<xsl:when test="self::tei:note">-</xsl:when>
<xsl:when test="@type">
<xsl:value-of select="concat(name(), ':', @type)"/>
</xsl:when>
<xsl:when test="@reason">
<xsl:value-of select="concat(name(), '::', @reason)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(name(), ':-')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="normalize-space(.)"/>
</xsl:attribute>
</note>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="tei:seg">
<p id="{@xml:id}">
<xsl:variable name="lang-code" select="ancestor-or-self::tei:*[@xml:lang][1]/@xml:lang"/>
<xsl:attribute name="lang" select="et:l10n($corpus-language,
$rootHeader//tei:langUsage/tei:language[@ident = $lang-code])"/>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</p>
<xsl:text> </xsl:text>
</xsl:template>
<!-- MWEs with semantic information -->
<xsl:template match="tei:phr[@type = 'sem']">
<xsl:copy>
<xsl:attribute name="usas_tags" select="et:sem('usas', .)"/>
<xsl:attribute name="usas_cats" select="et:sem('ids', .)"/>
<xsl:attribute name="usas_glosses" select="et:sem('glosses', .)"/>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:copy>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="tei:name">
<xsl:choose>
<xsl:when test="ancestor::tei:name">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@type"/>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:copy>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Used by CZ, currently ignored -->
<xsl:template match="tei:date | tei:time |
tei:num | tei:unit |
tei:email | tei:ref">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="tei:s">
<xsl:copy>
<xsl:attribute name="id" select="@xml:id"/>
<!-- Sentiment is given currently only in SI corpus -->
<xsl:if test="$country-code = 'SI'">
<xsl:attribute name="senti_3">
<xsl:call-template name="senti">
<xsl:with-param name="type">3</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="senti_6">
<xsl:call-template name="senti">
<xsl:with-param name="type">6</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="senti_n">
<xsl:call-template name="senti">
<xsl:with-param name="type">n</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</xsl:copy>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="tei:linkGrp"/>
<!-- We have do deal with syntactic words, e.g.:
<w xml:id="u1.p1.s1.w18">abych
<w xml:id="u1.p1.s1.w19" lemma="aby" msd="UPosTag=SCONJ" norm="aby"/>
<w xml:id="u1.p1.s1.w20" lemma="být" msd="UPosTag=AUX|Mood=Cnd" norm="bych"/>
</w>
<link ana="ud-syn:punct" target="#u1.p1.s1.w21 #u1.p1.s1.w17"/>
<link ana="ud-syn:mark" target="#u1.p1.s1.w21 #u1.p1.s1.w19"/>
<link ana="ud-syn:aux" target="#u1.p1.s1.w21 #u1.p1.s1.w20"/>
Solution:
- introduce normalised column (multi valued)
- make all attributes multivalued
In theory there is also:
<w norm="najlepši" lemma="lep">
<w>nar</w>
<w>lepši</w>
</w>
We do not cover this case!
-->
<!-- TOKENS -->
<xsl:template match="tei:pc | tei:w">
<!-- Output token -->
<xsl:value-of select="concat(normalize-space(.),'	')"/>
<xsl:choose>
<!-- For normalized words e.g.
<w xml:id="u1.p1.s1.w18">abych
<w xml:id="u1.p1.s1.w19" lemma="aby" msd="UPosTag=SCONJ" norm="aby"/>
<w xml:id="u1.p1.s1.w20" lemma="být" msd="UPosTag=AUX|Mood=Cnd" norm="bych"/>
</w>
-->
<xsl:when test="normalize-space(text()[1]) and (tei:w or tei:pc)">
<xsl:variable name="norms">
<xsl:for-each select="tei:w | tei:pc">
<xsl:value-of select="@norm"/>
<xsl:text>|</xsl:text>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="concat(replace($norms, '\|$', ''),'	')"/>
<xsl:variable name="toks">
<xsl:for-each select="tei:w | tei:pc">
<list>
<xsl:for-each select="tokenize(et:output-annotations(.), '	')">
<item>
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</list>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="et:join-annotations($toks)"/>
<xsl:if test="not(normalize-space($nosyntax))">
<xsl:variable name="deps">
<xsl:for-each select="tei:w | tei:pc">
<list>
<xsl:variable name="annots">
<xsl:call-template name="deps">
<xsl:with-param name="id" select="@xml:id"/>
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="tokenize($annots, '	')">
<item>
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</list>
</xsl:for-each>
</xsl:variable>
<xsl:text>	</xsl:text>
<xsl:value-of select="et:join-annotations($deps)"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(., '	', et:output-annotations(.))"/>
<xsl:if test="not(normalize-space($nosyntax))">
<xsl:text>	</xsl:text>
<xsl:call-template name="deps"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:if test="@join = 'right' or @join='both' or
following::tei:*[self::tei:w or self::tei:pc][1]/@join = 'left' or
following::tei:*[self::tei:w or self::tei:pc][1]/@join = 'both'">
<g/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
<!-- NAMED TEMPLATES -->
<xsl:template name="deps">
<xsl:param name="type">UD-SYN</xsl:param>
<xsl:param name="id" select="@xml:id"/>
<xsl:variable name="s" select="ancestor::tei:s"/>
<xsl:choose>
<xsl:when test="$s/tei:linkGrp[@type=$type]">
<!-- We need to take only the first link, in case of errros in linkGrp (two links with same token in FI) -->
<xsl:variable name="link"
select="$s/tei:linkGrp[@type=$type]/tei:link
[ends-with(@target, concat(' #', $id))][1]"/>
<xsl:choose>
<xsl:when test="not(normalize-space($link/@ana))">
<xsl:message>
<xsl:text>ERROR: no syntactic link for token </xsl:text>
<xsl:value-of select="concat(ancestor::tei:TEI/@xml:id, ':', @xml:id)"/>
</xsl:message>
<xsl:text>-	-	-	-	-</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- Syntactic relation is the English term in the UD-SYN taxonomy -->
<xsl:variable name="relation" select="substring-after($link/@ana, ':')"/>
<xsl:value-of select="et:l10n($corpus-language, key('id', $relation, $rootHeader)/tei:catDesc)/tei:term"/>
<xsl:variable name="target" select="key('id', replace($link/@target,'#(.+?) #.*', '$1'))"/>
<xsl:choose>
<xsl:when test="$target/self::tei:s">
<xsl:text>	-	-	-	-</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('	', et:output-annotations($target))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>ERROR: no linkGroup for sentence </xsl:text>
<xsl:value-of select="ancestor::tei:s/@xml:id"/>
</xsl:message>
<xsl:text>	-	-	-	-</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>