-
Notifications
You must be signed in to change notification settings - Fork 53
/
parlamint2release.xsl
530 lines (490 loc) · 22.3 KB
/
parlamint2release.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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<?xml version="1.0"?>
<!-- Prepare a ParlaMint corpus for a release, i.e. fix known and automatically fixable errors in the source corpus -->
<!-- The script can be used for both corpora in original langauge(s) or for its MTed variant -->
<!-- Input is either lingustically analysed (.TEI.ana) or "plain text" (.TEI) corpus root file XIncluding the corpus components
Note that .TEI still needs access to .TEI.ana as that it where it takes its word extents
Output is the corresponding .TEI / TEI.ana corpus root and corpus components, in the dicrectory given in the outDir parameter
If .TEI is processed, the corresponding TEI.ana directory should be given in the anaDir parameter
STDERR gives a detailed log of changes.
Changes to root file:
- delete old and now redundant pubPlace
- insert textClass if missing
- fix some corpus-dependent (GB) orgs and affiliations
- fix sprurious spaces in text content (multiple, leading and trailing spaces)
Changes to component files:
- add meeting reference to corpus specific parliamentary body of the meeting, if missing
- change div/@type for divs without utterances
- remove empty notes
- assign IDs to segments without them
- in .ana remove body name tag if name contains no words
- in .ana change tag from <w> to <pc> for punctuation
- in .ana change UPoS tag from - to X
- in .ana change lemma tag from _ to normalised form or wordform
- in .ana change root syntactic dependency to dep, if node is not sentence root
- in .ana change <PAD> syntactic dependency to dep
- fix sprurious spaces in text content (multiple, leading and trailing spaces)
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:mk="http://ufal.mff.cuni.cz/matyas-kopp"
xmlns:et="http://nl.ijs.si/et"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsl tei et mk xs xi"
version="2.0">
<xsl:import href="parlamint-lib.xsl"/>
<!-- Directories must have absolute paths or relative to the location of this script -->
<xsl:param name="outDir">.</xsl:param>
<xsl:param name="anaDir">.</xsl:param>
<!-- Type of corpus is 'txt' or 'ana' -->
<xsl:param name="type">
<xsl:choose>
<xsl:when test="contains(/tei:teiCorpus/@xml:id, '.ana')">ana</xsl:when>
<xsl:otherwise>txt</xsl:otherwise>
</xsl:choose>
</xsl:param>
<!-- County code take from the teiCorpus ID, country name from main English title -->
<xsl:param name="country-code" select="replace(/tei:teiCorpus/@xml:id,
'.*?-([^._]+).*', '$1')"/>
<xsl:param name="country-name" select="replace(/tei:teiCorpus/tei:teiHeader/
tei:fileDesc/tei:titleStmt/
tei:title[@type='main' and @xml:lang='en'],
'([^ ]+) .*', '$1')"/>
<!-- Is this an MTed corpus? Set $mt to name of MTed language (or to empty, if not MTed) -->
<xsl:param name="mt">
<xsl:if test="matches($country-code, '-[a-z]{2,3}$')">
<xsl:value-of select="replace($country-code, '.+-([a-z]{2,3})$', '$1')"/>
</xsl:if>
</xsl:param>
<xsl:output method="xml" indent="yes"/>
<xsl:preserve-space elements="catDesc seg"/>
<!-- Input directory -->
<xsl:variable name="inDir" select="replace(base-uri(), '(.*)/.*', '$1')"/>
<!-- The name of the corpus directory to output to, i.e. "ParlaMint-XX" -->
<xsl:variable name="corpusDir" select="replace(base-uri(),
'.*?([^/]+)/[^/]+\.[^/]+$', '$1')"/>
<!-- note's content that do not produce warning -->
<xsl:variable name="allowedNotes" select="tokenize('.. ... .... … ? !')"/>
<!-- Output root file -->
<xsl:variable name="outRoot">
<xsl:value-of select="$outDir"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$corpusDir"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="replace(base-uri(), '.*/(.+)$', '$1')"/>
</xsl:variable>
<!-- Gather URIs of component xi + files and map to new files, incl. .ana files -->
<xsl:variable name="docs">
<xsl:for-each select="//xi:include">
<item>
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="ancestor::tei:teiHeader">factorised</xsl:when>
<xsl:otherwise>component</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xi-orig>
<xsl:value-of select="@href"/>
</xi-orig>
<url-orig>
<xsl:value-of select="concat($inDir, '/', @href)"/>
</url-orig>
<url-new>
<xsl:value-of select="concat($outDir, '/', $corpusDir, '/', @href)"/>
</url-new>
<url-ana>
<xsl:value-of select="concat($anaDir, '/')"/>
<xsl:choose>
<xsl:when test="$type = 'ana'">
<xsl:value-of select="@href"/>
</xsl:when>
<xsl:when test="$type = 'txt'">
<xsl:value-of select="replace(@href, '\.xml', '.ana.xml')"/>
</xsl:when>
</xsl:choose>
</url-ana>
</item>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<xsl:message select="concat('INFO Starting to process ', tei:teiCorpus/@xml:id)"/>
<!-- Process component files -->
<xsl:for-each select="$docs//tei:item">
<xsl:variable name="this" select="tei:xi-orig"/>
<xsl:message select="concat('INFO Processing ', $this)"/>
<xsl:result-document href="{tei:url-new}">
<xsl:choose>
<!-- Process factorised parts of corpus root teiHeader as if they were root -->
<xsl:when test="@type = 'factorised'">
<xsl:apply-templates mode="root" select="document(tei:url-orig)"/>
</xsl:when>
<!-- Process component -->
<xsl:when test="@type = 'component'">
<xsl:apply-templates mode="comp" select="document(tei:url-orig)/tei:TEI"/>
</xsl:when>
</xsl:choose>
</xsl:result-document>
</xsl:for-each>
<!-- Output Root file -->
<xsl:message select="concat('INFO processing root ', tei:teiCorpus/@xml:id)"/>
<xsl:result-document href="{$outRoot}">
<xsl:apply-templates mode="root"/>
</xsl:result-document>
</xsl:template>
<xsl:template match="* | @*">
<xsl:message terminate="yes">All templates must have mode comp or root!</xsl:message>
</xsl:template>
<!-- Finalizing root file -->
<xsl:template mode="root" match="*">
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:apply-templates mode="root"/>
</xsl:copy>
</xsl:template>
<xsl:template mode="root" match="@*">
<xsl:copy/>
</xsl:template>
<xsl:template mode="root" match="tei:teiCorpus">
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:apply-templates mode="root" select="tei:*"/>
<xsl:for-each select="xi:include">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template mode="root" match="tei:revisionDesc">
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<change when="{$today-iso}">parlamint2release script: Fix some identifiable erros for the release.</change>
<xsl:apply-templates mode="root" select="*"/>
</xsl:copy>
</xsl:template>
<!-- Remove the two "speaker" parties from GB, i.e.
<org role="politicalParty" xml:id="party.S">
<orgName full="yes">Speaker</orgName>
<orgName full="init">S</orgName>
</org>
<org role="politicalParty" xml:id="party.LS">
<orgName full="yes">Lord Speaker</orgName>
<orgName full="init">LS</orgName>
</org>
-->
<xsl:template mode="root" match="tei:org[@role='politicalParty']">
<xsl:if test="$country-code != 'GB' or (@xml:id != 'party.S' and @xml:id != 'party.LS')">
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:apply-templates mode="root"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template mode="root" match="tei:idno">
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:choose>
<!-- AT: <idno type="parlament.gv.at" xml:lang="de">https://www.parlament.gv.at/WWER/PAD_01018/index.shtml</idno> -->
<xsl:when test="contains(@type, 'parlament')">
<xsl:attribute name="type">URI</xsl:attribute>
<xsl:attribute name="subtype">parliament</xsl:attribute>
<xsl:message select="concat('WARN ', ancestor-or-self::tei:*[@xml:id][1]/@xml:id,
': fixing idno (sub)type for parliament for ', .)"/>
</xsl:when>
<xsl:when test="contains(., 'wikipedia') and not(@type = 'URI' and @subtype = 'wikimedia')">
<xsl:attribute name="type">URI</xsl:attribute>
<xsl:attribute name="subtype">wikimedia</xsl:attribute>
<xsl:message select="concat('WARN ', ancestor-or-self::tei:*[@xml:id][1]/@xml:id,
': fixing idno (sub)type for wikipedia for ', .)"/>
</xsl:when>
</xsl:choose>
<xsl:value-of select="normalize-space(.)"/>
</xsl:copy>
</xsl:template>
<xsl:template mode="root" match="tei:meeting">
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:if test="not(contains(@ana, 'parla.upper') or contains(@ana, 'parla.lower') or contains(@ana, 'parla.committee'))">
<!-- In NO corpus each meeting contains yearFrom-yearTo info, which we need -->
<xsl:variable name="toYear-NO" select="substring-after(., '-')"/>
<xsl:choose>
<xsl:when test="$country-code = 'GB' and
contains(/tei:TEI/tei:teiHeader//tei:titleStmt
/tei:title[@type='main'],
'Commons')">
<xsl:attribute name="ana" select="normalize-space(concat('#parla.upper #parla.lower ', @ana))"/>
</xsl:when>
<!-- Quasi-bicameral to 2009, then unicameral -->
<xsl:when test="$country-code = 'NO' and $toYear-NO <= '2009'">
<xsl:attribute name="ana" select="normalize-space(concat('#parla.upper #parla.lower ', @ana))"/>
</xsl:when>
<xsl:when test="$country-code = 'NO'">
<xsl:attribute name="ana" select="normalize-space(concat('#parla.uni ', @ana))"/>
</xsl:when>
</xsl:choose>
<xsl:apply-templates mode="root"/>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template mode="root" match="tei:affiliation[@role='member']">
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:if test="$country-code = 'GB' and (@ref = '#party.S' or @ref = '#party.LS')">
<xsl:attribute name="role">speaker</xsl:attribute>
<xsl:attribute name="ref">
<xsl:if test="@ref = '#party.S'">#parla.lower</xsl:if>
<xsl:if test="@ref = '#party.LS'">#parla.upper</xsl:if>
</xsl:attribute>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template mode="root" match="text()">
<xsl:choose>
<xsl:when test="not(../tei:*)">
<xsl:if test="starts-with(., '\s') or ends-with(., '\s')">
<xsl:message select="concat('WARN ', ancestor-or-self::tei:*[@xml:id][1]/@xml:id,
': removing spurious space from ', .)"/>
</xsl:if>
<xsl:value-of select="normalize-space(.)"/>
</xsl:when>
<xsl:when test="preceding-sibling::tei:* and following-sibling::tei:*">
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="preceding-sibling::tei:*">
<xsl:if test="ends-with(., '\s')">
<xsl:message select="concat('WARN ', /tei:*/@xml:id,
': removing trailing space from ', .)"/>
</xsl:if>
<xsl:value-of select="replace(., '\s+$', '')"/>
</xsl:when>
<xsl:when test="following-sibling::tei:*">
<xsl:if test="starts-with(., '\s')">
<xsl:message select="concat('WARN ', /tei:*/@xml:id,
': removing starting space from ', .)"/>
</xsl:if>
<xsl:value-of select="replace(., '^\s+', '')"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes" select="concat('FATAL ', /tei:*/@xml:id,
': strange situation with ', .)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Finalizing component files -->
<xsl:template mode="comp" match="*">
<xsl:copy>
<xsl:apply-templates mode="comp" select="@*"/>
<xsl:apply-templates mode="comp"/>
</xsl:copy>
</xsl:template>
<xsl:template mode="comp" match="@*">
<xsl:copy/>
</xsl:template>
<!-- Set correct ID of component -->
<xsl:template mode="comp" match="tei:TEI/@xml:id">
<xsl:variable name="id" select="replace(base-uri(), '^.*?([^/]+)\.xml$', '$1')"/>
<xsl:attribute name="xml:id" select="$id"/>
<xsl:if test=". != $id">
<xsl:message select="concat('WARN ', @xml:id, ': fixing TEI/@xml:id to ', $id)"/>
</xsl:if>
</xsl:template>
<xsl:template mode="comp" match="text()">
<xsl:apply-templates mode="root" select="."/>
</xsl:template>
<!-- Some specific corpora are missing reference to the parliamentary body of the meeting, add it -->
<!-- Note that add-common-content takes care of this too in a more general setting -->
<xsl:template mode="comp" match="tei:meeting">
<xsl:copy>
<xsl:apply-templates mode="comp" select="@*"/>
<xsl:variable name="ana" select="replace(@ana, 'parla\.meeting\.committee', 'parla.committee')"/>
<xsl:attribute name="ana">
<!-- BE uses their own special category for commitee meetings, change to common category -->
<xsl:if test="not(contains($ana, 'parla.upper') or contains($ana, 'parla.lower') or contains($ana, 'parla.committee'))">
<xsl:variable name="title" select="/tei:TEI/tei:teiHeader//tei:titleStmt/
tei:title[@type='main']
[ancestor-or-self::tei:*[@xml:lang][1]/@xml:lang='en']"/>
<xsl:variable name="body">
<xsl:choose>
<xsl:when test="$country-code = 'GB' and contains($title, 'Commons')">#parla.lower</xsl:when>
<xsl:when test="$country-code = 'GB' and contains($title, 'Lords')">#parla.upper</xsl:when>
<xsl:when test="contains($title, 'Lower House')">#parla.lower</xsl:when>
<xsl:when test="contains($title, 'Upper House')">#parla.upper</xsl:when>
<!-- Should be taken care of by add-commmon-content -->
<xsl:otherwise><xsl:text></xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="normalize-space($body)">
<xsl:message select="concat('WARN ', /tei:*/@xml:id,
': inserting ', $body, ' into meeting/@ana ', $ana)"/>
<xsl:value-of select="concat($body, ' ')"/>
</xsl:if>
</xsl:if>
<xsl:value-of select="$ana"/>
</xsl:attribute>
<xsl:apply-templates mode="comp"/>
</xsl:copy>
</xsl:template>
<!-- Change div/@type="debateSection" to "commentSection" if div contains no utterances -->
<xsl:template mode="comp" match="tei:div[@type='debateSection'][not(tei:u)]">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': no utterances in div/@type=debateSection, ',
'replacing with commentSection')"/>
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:attribute name="type">commentSection</xsl:attribute>
<xsl:apply-templates mode="comp"/>
</xsl:copy>
</xsl:template>
<!-- Remove empty notes -->
<xsl:template mode="comp" match="tei:note[not(normalize-space(.))]">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': removing empty note in ', ancestor-or-self::tei:*[@xml:id][1]/@xml:id)"/>
</xsl:template>
<!-- Normalize nonempty notes and (description of) incidents -->
<xsl:template mode="comp" match="tei:note[normalize-space(.) and not(./element())] | tei:desc">
<xsl:variable name="textIn" select="normalize-space(.)"/>
<xsl:variable name="textOut" select="mk:normalize-note($textIn)"/>
<xsl:if test="$textIn != $textOut">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': de-bracketing ',
parent::tei:*/local-name(),'/',local-name(),
' "',$textIn,'"')"/>
</xsl:if>
<xsl:if test="not(normalize-space( replace($textOut, '[^\p{Lu}\p{Lt}\p{Ll}0-9]',' ')))
and not($allowedNotes[. = normalize-space($textOut)])">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': ',
parent::tei:*/local-name(),'/',local-name(),
' in ',ancestor-or-self::tei:*[@xml:id][1]/@xml:id,' has strange content "',$textIn,'"')"/>
</xsl:if>
<xsl:copy>
<xsl:apply-templates mode="root" select="@*"/>
<xsl:value-of select="$textOut"/>
</xsl:copy>
</xsl:template>
<xsl:template mode="comp" match="tei:note[./element()] ">
<xsl:variable name="textIn" select="normalize-space(.)"/>
<xsl:variable name="textOut" select="mk:normalize-note($textIn)"/>
<xsl:if test="$textIn != $textOut">
<!-- Comments can contain mixed content (text - time - text) -->
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': for ', ancestor-or-self::tei:*[@xml:id][1]/@xml:id,
' skipping comment normalization ', normalize-space(.))"/>
</xsl:if>
<xsl:copy>
<xsl:apply-templates mode="comp" select="@*"/>
<xsl:apply-templates mode="comp"/>
</xsl:copy>
</xsl:template>
<!-- Give IDs to segs without them (if u has ID, otherwise complain) -->
<xsl:template mode="comp" match="tei:seg[not(@xml:id)]">
<xsl:copy>
<xsl:apply-templates mode="comp" select="@*"/>
<xsl:choose>
<xsl:when test="parent::tei:u/@xml:id">
<xsl:attribute name="xml:id">
<xsl:value-of select="parent::tei:u/@xml:id"/>
<xsl:text>.</xsl:text>
<xsl:number/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:message select="concat('ERROR ', /tei:TEI/@xml:id,
': seg without ID but utterance also has no ID!')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates mode="comp"/>
</xsl:copy>
</xsl:template>
<!-- Bug where a name contains no words, but only a transcriber comment: remove <name> tag -->
<xsl:template mode="comp" match="tei:body//tei:name[not(tei:w)]">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': removing name tag as name ', normalize-space(.),
' contains no words for ', ancestor-or-self::tei:*[@xml:id][1]/@xml:id)"/>
<xsl:apply-templates mode="comp"/>
</xsl:template>
<!-- Processing tools also make various formal mistakes on words, here we try to fix them -->
<xsl:template mode="comp" match="tei:w">
<xsl:choose>
<!-- Bug where punctuation is encoded as a word: change <w> to <pc> -->
<xsl:when test="contains(@msd, 'UPosTag=PUNCT') and matches(., '^\p{P}+$')">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': changing word ', ., ' to punctuation for ', @xml:id)"/>
<pc>
<xsl:apply-templates mode="comp" select="@*[name() != 'lemma']"/>
<xsl:apply-templates mode="comp"/>
</pc>
</xsl:when>
<!-- Bug where syntactic word contains just one word: remove outer word and preserve annotations -->
<xsl:when test="tei:w[tei:w] and not(tei:w[tei:*[2]])">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': removing useless syntactic word ', @xml:id)"/>
<xsl:copy>
<xsl:apply-templates mode="comp" select="tei:w/@*[name() != 'norm']"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates mode="comp" select="@*"/>
<xsl:apply-templates mode="comp"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Bug where UPosTag is set to "-": change to "X" -->
<xsl:template mode="comp" match="tei:w/@msd[contains(., 'UPosTag=-')]">
<xsl:attribute name="msd">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': changing UPosTag=- to UPosTag=X for ', ../@xml:id)"/>
<xsl:value-of select="replace(., 'UPosTag=-', 'UPosTag=X')"/>
</xsl:attribute>
</xsl:template>
<!-- Bug where word lemma is set to "_": chang to @norm, if it exists, else to text() of the word -->
<xsl:template mode="comp" match="tei:w/@lemma[. = '_']">
<xsl:attribute name="lemma">
<xsl:choose>
<xsl:when test="../@norm">
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': changing _ lemma to @norm ', ../@norm, ' in ', ../@xml:id)"/>
<xsl:value-of select="../@norm"/>
</xsl:when>
<xsl:otherwise>
<xsl:message select="concat('WARN ', /tei:TEI/@xml:id,
': changing _ lemma to token ', ../text(), ' in ', ../@xml:id)"/>
<xsl:value-of select="../text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<!-- Bug in STANZA, sometimes several tokens have root dependency -->
<!-- We set those that have root but do not point to sentence ID to "dep" -->
<xsl:template mode="comp" match="tei:linkGrp[@type = 'UD-SYN']/tei:link[@ana='ud-syn:root']">
<xsl:copy>
<xsl:variable name="root-ref" select="concat('#', ancestor::tei:s/@xml:id)"/>
<xsl:attribute name="ana">
<xsl:choose>
<xsl:when test="$root-ref = substring-before(@target, ' ')">ud-syn:root</xsl:when>
<xsl:otherwise>
<xsl:message select="concat('WARN ', ancestor::tei:s/@xml:id,
': replacing ud-syn:root with ud-syn:dep for non-root dependency')"/>
<xsl:text>ud-syn:dep</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates mode="root" select="@target"/>
</xsl:copy>
</xsl:template>
<!-- Bug in STANZA, sometimes synt. relation is "<PAD>" -->
<!-- We set it to general dependency "dep" -->
<xsl:template mode="comp" match="tei:linkGrp[@type = 'UD-SYN']/tei:link[@ana='ud-syn:<PAD>']">
<xsl:copy>
<xsl:attribute name="ana">
<xsl:message select="concat('WARN ', ancestor::tei:s/@xml:id,
': replacing ud-syn:<PAD> with ud-syn:dep')"/>
<xsl:text>ud-syn:dep</xsl:text>
</xsl:attribute>
<xsl:apply-templates mode="comp" select="@target"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>