-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrhyme-test_2016-05-14.xsl
604 lines (602 loc) · 31.4 KB
/
rhyme-test_2016-05-14.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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:djb="http://www.obdurodon.org" xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all" version="2.0">
<!--
Filename: rhyme.xsl
Developer: djb 2015-05-15
Repo: http://github.com/djbpitt/poetry
Synopsis:
Normal input is XML document with <poem> -> <stanza> -> <line>, where line has <stress> and text() nodes
Add rhyme scheme annotation and line number within stanza to XML input
May be run against itself to identify rhyme scheme in included $poem variable
Identifies only exact rhyme; intended for postprocessing to identify inexact rhyme
Notes:
Regex based on:
http://akhmatova.obdurodon.org/resources.html
http://dh.obdurodon.org/drupal/iterating-over-transformations-without-you-know-hitting-go-million-times
Thanks to WP for the "visitor pattern" pointer
License: GNU AGPLv3
Visitor pattern steps
=====================
djb:prepareWords() : Flatten
Convert stressed vowels to uppercase and remove stress tags
Convert other text to lowercase
Strip punctuation
Normalize white space
djb:proclitics() : Merge proclitics with bases
djb:enclitics() : Merge enclitics with bases
djb:tsa() : Convert ть?ся$ to тса
djb:palatalize() : Capitalize all palatalized consonants (including unpaired)
djb:jot() : Normalize /j/
Insert Й before softening vowels after vowels, hard or soft sign, and (except in anlaut) и
Convert softening vowels to non-softening
Strip hard and soft signs
djb:romanize() : Romanize now that all information is represented by the segment
djb:finalDevoice() : Devoice obstruents in auslaut
djb:regressiveDevoice() : Regressive devoicing of obstruents and /v/
/v/ is easier to handle if we do devoicing first
djb:regressiveVoice() : Regressive voicing of obstruents, including /v/
djb:palatalAssimilation() : Regressive palatalization (Wade, section 6, p. 9)
djb:consonantCleanup() : c > ts, sč to šč, degeminate
djb:vowelReducation() : unstressed non-high vowels are i after soft consonants and i < e, a < o after hard
djb:stripSpaces() : remove all spaces
djb:rhymeString() : extract rhyme string (last stressed vowel, all following, supporting C for open masculine)
To do eventually:
Final -ogo/-ego (before stripping spaces), except:
(ne)?mnogo, strogo, ubogo, razlogo, otlogo, pologo, segodnja
Č > š: что(б?ы)?, конечн.*, нарочн.*, очечник.*, прачечн.*, скучно, яичниц.*, ильиничн.*, саввичн.*, никитичн.*
Idiosyncrasies: solnc.*, zdravstvuj.*, čuvstv*, zvezdn.*, landšaft.*, pozdno, prazdnik.*, serdc.*, grustn.*,
izvestn.*, lestn.*, mestn.*, okrestnost.*, častn.*, sčastliv.*
-->
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="poem" as="element(poem)">
<poem>
<stanza>
<line>"Мой д<stress>я</stress>дя с<stress>а</stress>мых ч<stress>е</stress>стных
пр<stress>а</stress>вил,</line>
<line>Когд<stress>а</stress> не в ш<stress>у</stress>тку
занем<stress>о</stress>г,</line>
<line>Он уваж<stress>а</stress>ть себ<stress>я</stress>
заст<stress>а</stress>вил</line>
<line>И л<stress>у</stress>чше в<stress>ы</stress>думать не
м<stress>о</stress>г.</line>
<line>Ег<stress>о</stress> прим<stress>е</stress>р друг<stress>и</stress>м
на<stress>у</stress>ка;</line>
<line>Но, б<stress>о</stress>же м<stress>о</stress>й, как<stress>а</stress>я
ск<stress>у</stress>ка</line>
<line>С больн<stress>ы</stress>м сид<stress>е</stress>ть и д<stress>е</stress>нь и
н<stress>о</stress>чь,</line>
<line>Не отход<stress>я</stress> ни ш<stress>а</stress>гу
пр<stress>о</stress>чь!</line>
<line>Как<stress>о</stress>е н<stress>и</stress>зкое
ков<stress>а</stress>рство</line>
<line>Полу-жив<stress>о</stress>го забавл<stress>я</stress>ть,</line>
<line>Ем<stress>у</stress> под<stress>у</stress>шки
поправл<stress>я</stress>ть,</line>
<line>Печ<stress>а</stress>льно поднос<stress>и</stress>ть
лек<stress>а</stress>рство,</line>
<line>Вздых<stress>а</stress>ть и д<stress>у</stress>мать про
себ<stress>я</stress>:</line>
<line>Когд<stress>а</stress> же ч<stress>о</stress>рт возьм<stress>ё</stress>т
теб<stress>я</stress>!"</line>
</stanza>
<stanza>
<line>Так д<stress>у</stress>мал молод<stress>о</stress>й
пов<stress>е</stress>са,</line>
<line>Лет<stress>я</stress> в пыл<stress>и</stress> на
почтов<stress>ы</stress>х,</line>
<line>Всев<stress>ы</stress>шней в<stress>о</stress>лею
Зев<stress>е</stress>са</line>
<line>Насл<stress>е</stress>дник вс<stress>е</stress>х сво<stress>и</stress>х
родн<stress>ы</stress>х.</line>
<line>Друзь<stress>я</stress> Людм<stress>и</stress>лы и
Русл<stress>а</stress>на!</line>
<line>С гер<stress>о</stress>ем моег<stress>о</stress>
ром<stress>а</stress>на</line>
<line>Без предисл<stress>о</stress>вий, с<stress>е</stress>й же
ч<stress>а</stress>с</line>
<line>Позв<stress>о</stress>льте познак<stress>о</stress>мить
в<stress>а</stress>с:</line>
<line>Он<stress>е</stress>гин, д<stress>о</stress>брый м<stress>о</stress>й
при<stress>я</stress>тель,</line>
<line>Род<stress>и</stress>лся на брег<stress>а</stress>х
Нев<stress>ы</stress>,</line>
<line>Где, м<stress>о</stress>жет б<stress>ы</stress>ть, род<stress>и</stress>лись
в<stress>ы</stress></line>
<line>Или блист<stress>а</stress>ли, м<stress>о</stress>й
чит<stress>а</stress>тель;</line>
<line>Там н<stress>е</stress>когда гул<stress>я</stress>л и
<stress>я</stress>:</line>
<line>Но вр<stress>е</stress>ден с<stress>е</stress>вер для
мен<stress>я</stress>.</line>
</stanza>
</poem>
</xsl:variable>
<xsl:variable name="alphabet"
select="tokenize('a b c d e f g h i j k l m n o p q r s t u v w x y z', ' ')"
as="xs:string+"/>
<xsl:variable name="genders" select="tokenize('m f d h', ' ')" as="xs:string+"/>
<xsl:template match="/">
<xsl:apply-templates select="$poem"/>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- "Visitor" pattern; perform operations in this order -->
<xsl:variable name="operations" as="element()+">
<djb:prepareWords/>
<djb:proclitics/>
<djb:enclitics/>
<djb:tsa/>
<djb:palatalize/>
<djb:jot/>
<djb:romanize/>
<djb:finalDevoice/>
<djb:regressiveDevoice/>
<djb:regressiveVoice/>
<djb:palatalAssimilation/>
<djb:consonantCleanup/>
<djb:vowelReduction/>
<djb:stripSpaces/>
<djb:rhymeString/>
<djb:signOff/>
</xsl:variable>
<!-- Process stanzas here -->
<xsl:template match="stanza">
<stanza>
<!-- Group lines by rhyme strings and assign alphabetic letters in order -->
<xsl:variable name="processed" as="element(line)+">
<xsl:apply-templates select="line"/>
</xsl:variable>
<xsl:variable name="outputLines" as="element(line)+">
<xsl:for-each-group select="$processed" group-by="@rhymeString">
<xsl:variable name="offset" as="xs:integer" select="position()"/>
<xsl:variable name="posttonic" as="xs:string"
select="replace(current-grouping-key(), '[^aeiou]+', '')"/>
<xsl:variable name="gender" as="xs:string"
select="$genders[position() eq string-length($posttonic) + 1]"/>
<xsl:variable name="letter" as="xs:string"
select="$alphabet[position() eq $offset]"/>
<xsl:variable name="renderedLetter" as="xs:string">
<xsl:choose>
<xsl:when test="$gender eq 'm'">
<xsl:value-of select="$letter"/>
</xsl:when>
<xsl:when test="$gender eq 'f'">
<xsl:value-of select="upper-case($letter)"/>
</xsl:when>
<xsl:when test="$gender eq 'd'">
<xsl:value-of select="concat(upper-case($letter), '′')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(upper-case($letter), '′′')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="current-group()">
<line letter="{$renderedLetter}">
<xsl:apply-templates select="@* | node()"/>
</line>
</xsl:for-each>
</xsl:for-each-group>
</xsl:variable>
<xsl:for-each select="$outputLines">
<xsl:sort select="number(@position)"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</stanza>
</xsl:template>
<!-- Process lines here -->
<xsl:template match="line">
<!-- Get the rhyme string -->
<xsl:variable name="rhymeString" as="xs:string">
<xsl:apply-templates select="$operations[1]" mode="operate">
<xsl:with-param name="input" select="."/>
<xsl:with-param name="remaining" select="remove($operations, 1)"/>
</xsl:apply-templates>
</xsl:variable>
<!-- Add line order and rhyme string to line -->
<line position="{position()}" rhymeString="{$rhymeString}">
<xsl:apply-templates/>
</line>
</xsl:template>
<!-- djb:prepareWords
Convert stressed vowels to uppercase and remove <stress> tags
Lowercase everything else
Strip punctuation
Input is <line>, output is string, all subsequent operations are on strings
-->
<xsl:template match="djb:prepareWords" mode="operate">
<xsl:param name="input" as="element(line)" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="withWhiteSpace" as="xs:string+">
<xsl:apply-templates select="$input" mode="#current"/>
</xsl:variable>
<xsl:variable name="result" as="xs:string" select="string-join($withWhiteSpace, '')"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<xsl:template match="stress" mode="operate">
<xsl:value-of select="upper-case(.)"/>
</xsl:template>
<xsl:template match="line/text()" mode="operate">
<xsl:value-of select="replace(lower-case(.), '\p{P}', '')"/>
</xsl:template>
<!-- djb:proclitics: Merge proclitics with bases -->
<xsl:include href="proclitic_inc.xsl"/>
<xsl:template match="djb:proclitics" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result" select="djb:proclitic($input, 1)" as="xs:string+"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:enclitics: Merge enclitics with bases -->
<xsl:include href="enclitic_inc.xsl"/>
<xsl:template match="djb:enclitics" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result" select="djb:enclitic($input, 1)" as="xs:string+"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:tsa: Convert ть?ся$ to тса -->
<xsl:template match="djb:tsa" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result" select="replace($input, 'ться$', 'тса')" as="xs:string+"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:palatalize: Capitalize all palatalized consonants (including unpaired) -->
<xsl:template match="djb:palatalize" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="$input" regex="([бвгдзклмнпрстфх])([яеиёюЯЕИЁЮь])">
<xsl:matching-substring>
<xsl:sequence select="concat(upper-case(regex-group(1)), regex-group(2))"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:sequence select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result" as="xs:string"
select="translate(string-join($result1, ''), 'чйщ', 'ЧЙЩ')"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:jot() : Normalize /j/
Insert Й before softening vowels after vowels, hard or soft sign, and (except in anlaut) и
Convert softening vowels to non-softening
Strip hard and soft signs
-->
<xsl:template match="djb:jot" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<!-- $result1 processes softening vowels after vowels and signs, but not in anlaut-->
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="$input" regex="([аэыоюяеиёюАЭЫОУЯЕИЁЮьъ])([яеиёюЯЕИЁЮ])">
<xsl:matching-substring>
<xsl:value-of select="concat(regex-group(1), 'Й', regex-group(2))"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<!-- $result2 processes softening vowels except и in anlaut-->
<xsl:variable name="result2" as="xs:string+">
<xsl:analyze-string select="string-join($result1, '')" regex="( |^)([яеёюЯЕЁЮ])">
<xsl:matching-substring>
<xsl:value-of select="concat(regex-group(1), 'Й', regex-group(2))"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<!-- $result3 conflates softening vowels into regular ones and strips hard and soft signs-->
<xsl:variable name="result3" as="xs:string">
<xsl:value-of
select="translate(string-join($result2, ''), 'яеиёюЯЕИЁЮьъ', 'аэыоуАЭЫОУ')"/>
</xsl:variable>
<xsl:variable name="result" select="string-join($result3, '')" as="xs:string"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:romanize: Romanize now that all information is encoded in the segment -->
<xsl:template match="djb:romanize" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result"
select="replace(translate($input, 'абвгджзклмнопрстуфхцшыэАБВГДЖЗЙКЛМНОПРСТУФХЦЧШЩЫЭ', 'abvgdžzklmnoprstufxcšieABVGDŽZJKLMNOPRSTUFXCČŠQIE'), 'Q', 'ŠČ')"
as="xs:string"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:finalDevoice: Devoice obstruents in auslaut -->
<xsl:template match="djb:finalDevoice" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="$input" regex="([bvgdžzBVGDZ])( |$)">
<xsl:matching-substring>
<xsl:value-of
select="concat(translate(regex-group(1), 'bvgdžzBVGDZ', 'pfktšsPFKTS'), regex-group(2))"
/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result" select="string-join($result1, '')" as="xs:string"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:regressiveDevoice: Regressive devoicing of obstruents, including /v/ -->
<xsl:template match="djb:regressiveDevoice" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="$input"
regex="([bvgdžzBVGDZpfktšsPFKTSkcČ]+)([pfktšsPFKTSkcČ])">
<xsl:matching-substring>
<xsl:value-of
select="concat(translate(regex-group(1), 'bvgdžzBVGDZ', 'pfktšsPFKTS'), regex-group(2))"
/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result" select="string-join($result1, '')" as="xs:string"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:regressiveVoice: Regressive devoicing of obstruents, including /v/
ɣ (LC) = U+0263, Ɣ (UC) = U+0194
ʒ (LC) = U+0292, Ʒ (UC) = U+01B7
ǯ (LC) = U+01EF, Ǯ (UC) = U+01EE
-->
<xsl:template match="djb:regressiveVoice" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="$input" regex="([bvgdžzBVGDZpfktšsPFKTSkcČ]+)([bgdžzBGDZ])">
<xsl:matching-substring>
<xsl:value-of
select="concat(translate(regex-group(1), 'pfktšsPFKTSxcČ', 'bvgdžzBVGDZɣʒǮ'), regex-group(2))"
/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result" select="string-join($result1, '')" as="xs:string"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:palatalAssimilation: Regressive palatalization assimilation
šc has already been split, so requires special treatment
-->
<xsl:template match="djb:palatalAssimilation" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result3" as="xs:string+">
<xsl:analyze-string select="$input" regex="[tdn]+[TDNSZČL]+">
<xsl:matching-substring>
<xsl:value-of select="upper-case(.)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result2" as="xs:string+">
<xsl:analyze-string select="string-join($result3, '')" regex="[tdnTDNSZČL]+ŠČ">
<xsl:matching-substring>
<xsl:value-of select="upper-case(.)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="string-join($result2, '')" regex="[tdnsz]+[TDNSZL]+">
<xsl:matching-substring>
<xsl:value-of select="upper-case(.)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result" select="string-join($result1, '')"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:consonantCleanup() : c > ts, sč to šč, degeminate -->
<xsl:template match="djb:consonantCleanup" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result3" as="xs:string+">
<xsl:analyze-string select="$input" regex="c">
<xsl:matching-substring>
<xsl:text>ts</xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result2" as="xs:string+">
<xsl:analyze-string select="string-join($result3, '')" regex="sČ">
<xsl:matching-substring>
<xsl:text>ŠČ</xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="$result2" regex="(.)\1">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result" as="xs:string" select="string-join($result1, '')"/>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:vowelReduction() : unstressed non-high vowels are i after soft consonants and i < e, a < o after hard -->
<xsl:template match="djb:vowelReduction" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result1" as="xs:string+">
<xsl:analyze-string select="$input" regex="([BVGDJZKLMNPRSTFXČ])([eao])">
<xsl:matching-substring>
<xsl:value-of select="concat(regex-group(1), 'i')"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="result" as="xs:string">
<xsl:value-of select="translate(string-join($result1, ''), 'eo', 'ia')"/>
</xsl:variable>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:rhymeString(): rhyme string is last stressed vowel, all following, supporting C for open masculine -->
<xsl:template match="djb:stripSpaces" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result" as="xs:string">
<xsl:value-of select="translate($input, ' ', '')"/>
</xsl:variable>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:rhymeString(): rhyme string is last stressed vowel, all following, supporting C for open masculine -->
<xsl:template match="djb:rhymeString" mode="operate">
<xsl:param name="input" as="xs:string" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result" as="xs:string">
<xsl:analyze-string select="$input" regex="(.)([AEIOU])([^AEIOU]*)$">
<xsl:matching-substring>
<xsl:value-of
select="
concat(if (regex-group(3) eq '') then
regex-group(1)
else
(), regex-group(2), if (regex-group(3) ne '') then
regex-group(3)
else
())"
/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:apply-templates select="$remaining[1]" mode="#current">
<xsl:with-param name="input" select="$result"/>
<xsl:with-param name="remaining" select="remove($remaining, 1)"/>
</xsl:apply-templates>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
<!-- djb:signOff (last): Signal end of operations -->
<xsl:template match="djb:signOff" mode="operate">
<xsl:param name="input" as="xs:string+" required="yes"/>
<xsl:param name="remaining" as="element()*"/>
<xsl:variable name="result" as="xs:string+" select="$input"/>
<xsl:if test="empty($remaining)">
<xsl:sequence select="$result"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>