Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 3 | xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:nkjp="http://www.nkjp.pl/ns/1.0" |
| 4 | xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:f="func" |
Piotr Banski | f8af3a9 | 2022-05-23 03:20:10 +0200 | [diff] [blame] | 5 | xmlns:fn="http://www.w3.org/2005/xpath-functions" |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 6 | xmlns:xi="http://www.w3.org/2001/XInclude" |
| 7 | xmlns:map="http://www.w3.org/2005/xpath-functions/map" exclude-result-prefixes="xs f fn map nkjp tei xi" |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 8 | version="3.0" expand-text="yes"> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 9 | |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 10 | |
| 11 | <!-- PARAMETERS --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 12 | |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 13 | <xsl:param name="sourceDir" select="'test/resources/nkjp2korap_sample2'" as="xs:string"/> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 14 | <!-- the directory containing NKJP files, in the form of a collection of text-level dirs |
| 15 | (that is how we know both the $corpusID and the $docID) --> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 16 | |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 17 | <xsl:param name="targetDir" select="'test/output'" as="xs:string"/> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 18 | <!-- where the corpus/document/text/annotations hierarchy is going to be created --> |
bansp | f2b24e6 | 2022-03-28 18:12:08 +0200 | [diff] [blame] | 19 | |
| 20 | <xsl:param name="skip_docID" as="xs:string"> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 21 | <!--<xsl:value-of select="''"/>--> |
| 22 | <xsl:value-of select="'HellerPodgladanie,IsakowiczZaleskiMoje,KolakowskiOco,MysliwskiKamien,WilkWilczy,ZycieWarszawy_Zycie'"/> |
bansp | b599253 | 2022-03-29 15:55:44 +0200 | [diff] [blame] | 23 | </xsl:param> |
| 24 | <!-- comma-separated list of document IDs to be skipped from processing |
bansp | f2b24e6 | 2022-03-28 18:12:08 +0200 | [diff] [blame] | 25 | example: HellerPodgladanie,KOT |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 26 | no functionality beyond string identity is supported |
| 27 | (this is just for testing) --> |
bansp | b599253 | 2022-03-29 15:55:44 +0200 | [diff] [blame] | 28 | |
Piotr Banski | 1ae16bd | 2022-05-25 15:59:40 +0200 | [diff] [blame] | 29 | <xsl:param name="SHOW_ORTH_IN_STRUCT" as="xs:boolean" select="true()"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 30 | <!-- for debugging structure.xml production --> |
| 31 | |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 32 | |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 33 | <!-- VARIABLES (= constants...) --> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 34 | |
| 35 | <xsl:variable name="corpusID" as="xs:string" select="'NKJP'" static="yes"/> |
| 36 | <xsl:variable name="docID" as="xs:string" select="'NKJP'" static="yes"/> |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 37 | |
| 38 | <xsl:variable name="targetCorpusDir_slashed" select="$targetDir || '/' || $corpusID || '/'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 39 | |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 40 | <xsl:variable name="systemDoctypeI5" as="xs:string" |
| 41 | select="'http://corpora.ids-mannheim.de/I5/DTD/i5.dtd'" static="true"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 42 | |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 43 | <xsl:variable name="publicDoctypeI5" as="xs:string" static="true" |
| 44 | select="'-//IDS//DTD I5 1.0//EN'"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 45 | |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 46 | <xsl:variable name="KorAP_namespace" static="true" as="xs:string" |
| 47 | select="'http://ids-mannheim.de/ns/KorAP'"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 48 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 49 | <xsl:variable name="KorAP-XML_version" select="'KorAP-0.4'" as="xs:string" static="true"/> |
| 50 | <!-- this is only a bit funny --> |
| 51 | |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 52 | <xsl:variable name="collection_params" as="xs:string" static="yes" |
| 53 | select="'recurse=yes;validation=strip;select=text.xml;content-type=application/xml;on-error=warning;xinclude=yes'" |
| 54 | /> |
| 55 | <!-- see https://www.saxonica.com/documentation11/index.html#!sourcedocs/collections/collection-directories --> |
| 56 | |
| 57 | <xsl:variable name="collection_of_text" select="collection($sourceDir || '?' || $collection_params)" as="document-node()+"/> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 58 | |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 59 | <!-- MODES --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 60 | |
| 61 | <xsl:mode name="corpus" on-no-match="deep-skip"/> |
| 62 | <xsl:mode name="text" on-no-match="deep-skip"/> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 63 | <xsl:mode name="header-text" on-no-match="text-only-copy"/> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 64 | <xsl:mode name="copy" on-no-match="shallow-copy"/> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 65 | <xsl:mode use-accumulators="#all"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 66 | |
Piotr Banski | e1ac520 | 2022-05-30 21:25:21 +0200 | [diff] [blame] | 67 | <xsl:accumulator name="element-index" as="xs:integer" initial-value="0"> |
| 68 | <xsl:accumulator-rule match="tei:*[ancestor-or-self::tei:text]" select="$value + 1" phase="start"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 69 | </xsl:accumulator> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 70 | |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 71 | |
| 72 | |
| 73 | <!--I think I may be able to actually merge the two accumulators, but let's see--> |
| 74 | <xsl:accumulator name="morpho-offsets" as="map(xs:string, item()+)+" initial-value="(map{'null':(0,0)})"> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 75 | |
| 76 | <xsl:accumulator-rule match="tei:body/tei:p" phase="start"> |
| 77 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 78 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 79 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 80 | </xsl:variable> |
| 81 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 82 | <xsl:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + 1"/> |
| 83 | <!-- for paragraphs, it's in either being initial or not --> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 84 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 85 | <xsl:sequence select=" |
| 86 | $value, |
| 87 | map { |
| 88 | string(@xml:id): ($preceding_index,$our_base) |
| 89 | }"/> |
| 90 | </xsl:accumulator-rule> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 91 | <!-- this is morpho-offsets --> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 92 | <xsl:accumulator-rule match="tei:s" phase="start"> |
| 93 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 94 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 95 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 96 | </xsl:variable> |
Piotr Banski | 92791a2 | 2022-05-26 01:41:10 +0200 | [diff] [blame] | 97 | <xsl:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + xs:integer(f:is_preceded_by_ws(.,true()))"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 98 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 99 | <xsl:sequence select=" |
| 100 | $value, |
| 101 | map { |
| 102 | string(@xml:id): ($preceding_index,$our_base) |
| 103 | }"/> |
| 104 | </xsl:accumulator-rule> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 105 | <!-- this is morpho-offsets --> |
| 106 | |
| 107 | <!-- I want something that won't be matched in other layers, for efficiency - that |
| 108 | may allow me to merge the accumulators, eventually; |
| 109 | but I also want to filter out the rejected tokenization alternatives already here --> |
| 110 | <xsl:accumulator-rule match="tei:seg[tei:fs[@type eq 'morph' and tei:f[@name eq 'disamb']]]" phase="end"> |
| 111 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 112 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 113 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 114 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 115 | </xsl:variable> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 116 | <xsl:variable name="our_base" as="xs:integer" select="$preceding_index + xs:integer(f:is_preceded_by_ws(.,true()))"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 117 | |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 118 | <xsl:sequence select=" |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 119 | $value, |
| 120 | map { |
| 121 | string(@xml:id): ($our_base,$our_base + string-length(tei:fs/tei:f[@name eq 'orth']/tei:string)) |
| 122 | }"/> |
| 123 | |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 124 | </xsl:accumulator-rule> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 125 | <!-- this is morpho-offsets --> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 126 | <xsl:accumulator-rule match="tei:s" phase="end"> |
| 127 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 128 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 129 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 130 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 131 | </xsl:variable> |
| 132 | <xsl:variable name="our_base" as="xs:integer"> |
| 133 | <xsl:variable name="incomplete" select="map:find($value,string(@xml:id))(1)" as="xs:integer+"/> |
| 134 | <xsl:sequence select="$incomplete[2]"/> |
| 135 | </xsl:variable> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 136 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 137 | <xsl:sequence select=" |
| 138 | $value, |
| 139 | map { |
| 140 | string(@xml:id): ($our_base,$preceding_index) |
| 141 | }"/> |
| 142 | </xsl:accumulator-rule> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 143 | <!-- this is morpho-offsets --> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 144 | <xsl:accumulator-rule match="tei:body/tei:p" phase="end"> |
| 145 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 146 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 147 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
| 148 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 149 | </xsl:variable> |
| 150 | <xsl:variable name="our_base" as="xs:integer"> |
| 151 | <xsl:variable name="incomplete" select="map:find($value,string(@xml:id))(1)" as="xs:integer+"/> |
| 152 | <xsl:sequence select="$incomplete[2]"/> |
| 153 | </xsl:variable> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 154 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 155 | <xsl:sequence select=" |
| 156 | $value, |
| 157 | map { |
| 158 | string(@xml:id): ($our_base,$preceding_index) |
| 159 | }"/> |
| 160 | </xsl:accumulator-rule> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 161 | </xsl:accumulator> |
| 162 | |
| 163 | |
| 164 | |
| 165 | <xsl:accumulator name="segmentation-offsets" as="map(xs:string, item()+)+" initial-value="(map{'null':(0,0)})"> |
| 166 | |
| 167 | <xsl:accumulator-rule match="tei:body/tei:p" phase="start"> |
| 168 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 169 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 170 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
| 171 | </xsl:variable> |
| 172 | |
| 173 | <xsl:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + 1"/> |
| 174 | <!-- for paragraphs, it's in either being initial or not --> |
| 175 | |
| 176 | <xsl:sequence select=" |
| 177 | $value, |
| 178 | map { |
| 179 | string(@xml:id): ($preceding_index,$our_base) |
| 180 | }"/> |
| 181 | </xsl:accumulator-rule> |
| 182 | |
| 183 | <xsl:accumulator-rule match="tei:s" phase="start"> |
| 184 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 185 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 186 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
| 187 | </xsl:variable> |
| 188 | <xsl:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + xs:integer(f:is_preceded_by_ws(.,true()))"/> |
| 189 | |
| 190 | <xsl:sequence select=" |
| 191 | $value, |
| 192 | map { |
| 193 | string(@xml:id): ($preceding_index,$our_base) |
| 194 | }"/> |
| 195 | </xsl:accumulator-rule> |
| 196 | |
| 197 | <xsl:accumulator-rule match="tei:w[parent::tei:seg[count(@nkjp:rejected) eq 0]]" phase="end"> |
| 198 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 199 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 200 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
| 201 | </xsl:variable> |
| 202 | <xsl:variable name="our_base" as="xs:integer" select="$preceding_index + xs:integer(f:is_preceded_by_ws(parent::tei:seg,true()))"/> |
| 203 | |
| 204 | <xsl:sequence select=" |
| 205 | $value, |
| 206 | map { |
| 207 | string(parent::tei:seg/@xml:id): ($our_base,$our_base + string-length()) |
| 208 | }"/> |
| 209 | </xsl:accumulator-rule> |
| 210 | |
| 211 | <xsl:accumulator-rule match="tei:s" phase="end"> |
| 212 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 213 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 214 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
| 215 | |
| 216 | </xsl:variable> |
| 217 | <xsl:variable name="our_base" as="xs:integer"> |
| 218 | <xsl:variable name="incomplete" select="map:find($value,string(@xml:id))(1)" as="xs:integer+"/> |
| 219 | <xsl:sequence select="$incomplete[2]"/> |
| 220 | </xsl:variable> |
| 221 | |
| 222 | <xsl:sequence select=" |
| 223 | $value, |
| 224 | map { |
| 225 | string(@xml:id): ($our_base,$preceding_index) |
| 226 | }"/> |
| 227 | </xsl:accumulator-rule> |
| 228 | |
| 229 | <xsl:accumulator-rule match="tei:body/tei:p" phase="end"> |
| 230 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 231 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 232 | <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/> |
| 233 | |
| 234 | </xsl:variable> |
| 235 | <xsl:variable name="our_base" as="xs:integer"> |
| 236 | <xsl:variable name="incomplete" select="map:find($value,string(@xml:id))(1)" as="xs:integer+"/> |
| 237 | <xsl:sequence select="$incomplete[2]"/> |
| 238 | </xsl:variable> |
| 239 | |
| 240 | <xsl:sequence select=" |
| 241 | $value, |
| 242 | map { |
| 243 | string(@xml:id): ($our_base,$preceding_index) |
| 244 | }"/> |
| 245 | </xsl:accumulator-rule> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 246 | |
| 247 | <xsl:accumulator-rule match="tei:body" phase="end"> |
| 248 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 249 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 250 | <xsl:sequence select="map:get($the_tail, map:keys($the_tail)[1])[2]"/> |
| 251 | </xsl:variable> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 252 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 253 | <xsl:sequence select=" |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 254 | $value, |
| 255 | map { |
| 256 | string(@xml:id): (0, $preceding_index) |
| 257 | }"/> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 258 | </xsl:accumulator-rule> |
| 259 | |
| 260 | <xsl:accumulator-rule match="tei:text" phase="end"> |
| 261 | <xsl:variable name="preceding_index" as="xs:integer"> |
| 262 | <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/> |
| 263 | <xsl:sequence select="map:get($the_tail, map:keys($the_tail)[1])[2]"/> |
| 264 | </xsl:variable> |
| 265 | |
| 266 | <xsl:sequence select=" |
| 267 | $value, |
| 268 | map { |
| 269 | string(@xml:id): (0, $preceding_index) |
| 270 | }"/> |
| 271 | </xsl:accumulator-rule> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 272 | </xsl:accumulator> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 273 | |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 274 | <!-- FUNCTIONS --> |
| 275 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 276 | <xsl:function name="f:compute_nesting" as="xs:integer"> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 277 | <xsl:param name="node" as="element()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 278 | <xsl:variable name="rel_depth" |
| 279 | select="count($node/ancestor-or-self::*[local-name(.) ne 'TEI'][local-name(.) ne 'teiCorpus'])" |
| 280 | as="xs:integer"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 281 | <xsl:sequence select="$rel_depth"/> |
| 282 | </xsl:function> |
| 283 | |
Piotr Banski | 92791a2 | 2022-05-26 01:41:10 +0200 | [diff] [blame] | 284 | <xsl:function name="f:is_preceded_by_ws" as="xs:boolean"> |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 285 | <xsl:param name="node" as="element()"/> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 286 | <xsl:param name="suppress_initial" as="xs:boolean"/> |
Piotr Banski | 4f4c2d2 | 2022-05-19 01:44:32 +0200 | [diff] [blame] | 287 | |
Piotr Banski | 92791a2 | 2022-05-26 01:41:10 +0200 | [diff] [blame] | 288 | <xsl:choose> |
| 289 | <xsl:when test="local-name($node) eq 'seg'"> |
| 290 | <xsl:choose> |
| 291 | <xsl:when test="$node/@nkjp:nps"> |
| 292 | <xsl:sequence select="fn:false()"/> |
| 293 | </xsl:when> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 294 | <xsl:when test="$node/tei:fs/tei:f[@name eq 'nps']"> |
| 295 | <!--added for traversing ann_morphosyntax--> |
| 296 | <xsl:sequence select="fn:false()"/> |
| 297 | </xsl:when> |
Piotr Banski | 92791a2 | 2022-05-26 01:41:10 +0200 | [diff] [blame] | 298 | <xsl:when |
| 299 | test="$node/ancestor::tei:s[count(preceding-sibling::tei:s) eq 0] and $node/ancestor::tei:p[count(preceding-sibling::tei:p) eq 0] and not($node/preceding::tei:seg[count(@nkjp:rejected) eq 0])"> |
| 300 | <xsl:sequence select="fn:false()"/> |
| 301 | <!-- the otherwise very costly check for preceding segs fires only if the first two are true, so it will have minimal search space --> |
| 302 | </xsl:when> |
| 303 | <xsl:when |
| 304 | test="$suppress_initial and $node/ancestor::tei:s/descendant::tei:seg[count(@nkjp:rejected) eq 0][1]/@xml:id eq $node/@xml:id"> |
| 305 | <!-- I forget how node identity works now, so let me just compare the IDs --> |
| 306 | <xsl:sequence select="fn:false()"/> |
| 307 | </xsl:when> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 308 | <xsl:when |
| 309 | test="$suppress_initial and $node/ancestor::tei:s/descendant::tei:seg[tei:fs/tei:f[@name eq 'disamb']][1]/@xml:id eq $node/@xml:id"> |
| 310 | <!--added for traversing ann_morphosyntax--> |
| 311 | <xsl:sequence select="fn:false()"/> |
| 312 | </xsl:when> |
Piotr Banski | 92791a2 | 2022-05-26 01:41:10 +0200 | [diff] [blame] | 313 | <xsl:otherwise> |
| 314 | <xsl:sequence select="fn:true()"/> |
| 315 | </xsl:otherwise> |
| 316 | </xsl:choose> |
| 317 | </xsl:when> |
| 318 | <xsl:when test="local-name($node) eq 's'"> |
| 319 | <xsl:choose> |
| 320 | <xsl:when test="exists($node/preceding-sibling::tei:s)"> |
| 321 | <xsl:sequence select="fn:true()"/> |
| 322 | </xsl:when> |
| 323 | <xsl:otherwise> |
| 324 | <xsl:sequence |
| 325 | select="not($suppress_initial) and exists($node/ancestor::tei:p[1]/preceding-sibling::tei:p)" |
| 326 | /> |
| 327 | </xsl:otherwise> |
| 328 | </xsl:choose> |
| 329 | |
| 330 | </xsl:when> |
| 331 | <xsl:when test="local-name($node) eq 'p'"> |
| 332 | <xsl:sequence select="exists($node/preceding-sibling::tei:p)"/> |
| 333 | </xsl:when> |
| 334 | <xsl:otherwise> |
| 335 | <xsl:message terminate="yes" |
| 336 | select="'Wrong argument passed to f:is_preceded_by_ws(): ' || local-name($node) || ' Only p, s, seg are allowed.'" |
| 337 | /> |
| 338 | </xsl:otherwise> |
| 339 | </xsl:choose> |
| 340 | </xsl:function> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 341 | |
bansp | b599253 | 2022-03-29 15:55:44 +0200 | [diff] [blame] | 342 | <!-- UTILITY TEMPLATES --> |
| 343 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 344 | <xsl:template match="@default" mode="#all"/> |
bansp | 97ba7ce | 2022-03-26 05:14:06 +0100 | [diff] [blame] | 345 | <!-- this is to delete some auto-inserted attribute throughout --> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 346 | |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 347 | <xsl:template match="tei:w" mode="#all"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 348 | <!-- NKJP-SGJP has apparently resigned from standoff representations by adding <w> everywhere; |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 349 | we reach for them, but from the level of <seg>, so we don't need to process <w> separately --> |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 350 | |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 351 | <!-- fall-thru, skipping the potential <paren> element and filtering out the bad guys --> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 352 | <xsl:template match="tei:choice" mode="struct"> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 353 | <xsl:apply-templates select="descendant::tei:seg[count(@nkjp:rejected) eq 0]" mode="struct"/> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 354 | </xsl:template> |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 355 | <xsl:template match="tei:choice" mode="morpho"> |
| 356 | <xsl:apply-templates select="descendant::tei:seg[count(@nkjp:rejected) eq 0]" mode="morpho"/> |
| 357 | </xsl:template> |
bansp | b599253 | 2022-03-29 15:55:44 +0200 | [diff] [blame] | 358 | |
| 359 | <!-- MAIN PROCESSING --> |
| 360 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 361 | <xsl:template name="xsl:initial-template"> |
bansp | f2b24e6 | 2022-03-28 18:12:08 +0200 | [diff] [blame] | 362 | <xsl:variable name="IDs_to_skip" select="tokenize($skip_docID,',')" as="xs:string*"/> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 363 | |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 364 | <!-- we only want to call the template below once, and we process a random NKJP corpus file for that purpose, |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 365 | because all we need is the main corpus header, and we can (should) get to that from any NKJP corpus document --> |
| 366 | <xsl:call-template name="create_corpus_header"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 367 | <xsl:with-param name="text.xml" select="$collection_of_text[1]" as="document-node()"/> |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 368 | <xsl:with-param name="target" select="$targetCorpusDir_slashed || 'header.xml'" as="xs:string"/> |
| 369 | </xsl:call-template> |
| 370 | |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 371 | <xsl:for-each select="$collection_of_text"> |
| 372 | <xsl:variable name="my_dir" as="xs:string" select="replace(base-uri(),'/text\.xml','')"/> |
| 373 | <xsl:variable name="my_textID" as="xs:string" select="tokenize($my_dir,'/')[last()]"/> |
| 374 | <xsl:variable name="ann_morphosyntax.uri" select="$my_dir || '/ann_morphosyntax.xml'" as="xs:string"/> |
| 375 | <xsl:variable name="ann_segmentation.uri" select="$my_dir || '/ann_segmentation.xml'" as="xs:string"/> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 376 | <xsl:variable name="ann_named.uri" select="$my_dir || '/ann_named.xml'" as="xs:string"/> |
| 377 | <xsl:variable name="ann_groups.uri" select="$my_dir || '/ann_groups.xml'" as="xs:string"/> |
| 378 | <xsl:variable name="ann_words.uri" select="$my_dir || '/ann_words.xml'" as="xs:string"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 379 | |
bansp | f2b24e6 | 2022-03-28 18:12:08 +0200 | [diff] [blame] | 380 | <xsl:choose> |
| 381 | <xsl:when test="$my_textID = $IDs_to_skip"/> |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 382 | <!-- this is a utility step, for when we want to ignore some texts for any reason (debugging, selective update) --> |
bansp | f2b24e6 | 2022-03-28 18:12:08 +0200 | [diff] [blame] | 383 | <xsl:otherwise> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 384 | |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 385 | <xsl:call-template name="process_single_sample"> |
bansp | f2b24e6 | 2022-03-28 18:12:08 +0200 | [diff] [blame] | 386 | <xsl:with-param name="text.xml" as="document-node()" select="."/> |
| 387 | <xsl:with-param name="ann_morphosyntax.xml" as="document-node()" |
| 388 | select="doc($ann_morphosyntax.uri)"/> |
| 389 | <xsl:with-param name="ann_segmentation.xml" as="document-node()" |
| 390 | select="doc($ann_segmentation.uri)"/> |
| 391 | <xsl:with-param name="my_textID" select="$my_textID" as="xs:string"/> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 392 | <!-- the following parameters may happen to be null --> |
| 393 | <xsl:with-param name="ann_named.xml" as="document-node()*" |
| 394 | select="if(fn:doc-available($ann_named.uri)) then doc($ann_named.uri) else ()"/> |
| 395 | <xsl:with-param name="ann_groups.xml" as="document-node()*" |
| 396 | select="if(fn:doc-available($ann_groups.uri)) then doc($ann_groups.uri) else ()"/> |
| 397 | <xsl:with-param name="ann_words.xml" as="document-node()*" |
| 398 | select="if(fn:doc-available($ann_words.uri)) then doc($ann_words.uri) else ()"/> |
| 399 | |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 400 | </xsl:call-template> |
bansp | f2b24e6 | 2022-03-28 18:12:08 +0200 | [diff] [blame] | 401 | </xsl:otherwise> |
| 402 | </xsl:choose> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 403 | </xsl:for-each> |
bansp | 8f6700b | 2022-03-27 05:27:09 +0200 | [diff] [blame] | 404 | </xsl:template> |
| 405 | |
| 406 | <xsl:template name="process_single_sample"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 407 | <xsl:param name="text.xml" as="document-node()"/> |
| 408 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 409 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
bansp | d1bf1db | 2022-04-04 02:16:24 +0200 | [diff] [blame] | 410 | <xsl:param name="my_textID" as="xs:string" select="'0-BAD_textID'"/> |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 411 | <!-- empty textID should never happen, but if it does, it will be signalled at the top of the output --> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 412 | <xsl:param name="ann_named.xml" as="document-node()*"/> |
| 413 | <xsl:param name="ann_groups.xml" as="document-node()*"/> |
| 414 | <xsl:param name="ann_words.xml" as="document-node()*"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 415 | |
| 416 | <xsl:variable name="targetBaseDir" as="xs:string" select="$targetCorpusDir_slashed || $docID || '/' || $my_textID"/> |
| 417 | |
| 418 | <xsl:variable name="compoundID" as="xs:string" |
| 419 | select="$corpusID || '_' || $docID || '.' || $my_textID"/> |
| 420 | <!-- this is what occurs in the text and data layers as @docid --> |
| 421 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 422 | <xsl:call-template name="create_data"> |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 423 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" as="document-node()"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 424 | <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/> |
| 425 | <xsl:with-param name="target" select="$targetBaseDir || '/data.xml'" as="xs:string"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 426 | </xsl:call-template> |
| 427 | |
Piotr Banski | 4f4c2d2 | 2022-05-19 01:44:32 +0200 | [diff] [blame] | 428 | <xsl:call-template name="create_struct"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 429 | <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 430 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" |
| 431 | as="document-node()"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 432 | <xsl:with-param name="target" select="$targetBaseDir || '/struct/structure.xml'" as="xs:string" |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 433 | /> |
| 434 | </xsl:call-template> |
Piotr Banski | 92791a2 | 2022-05-26 01:41:10 +0200 | [diff] [blame] | 435 | |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 436 | <xsl:call-template name="create_morpho"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 437 | <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 438 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" |
| 439 | as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 440 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" |
| 441 | as="document-node()"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 442 | <xsl:with-param name="target" select="$targetBaseDir || '/nkjp/morpho.xml'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 443 | </xsl:call-template> |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 444 | |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 445 | <xsl:call-template name="create_text_header"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 446 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 447 | <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/> |
| 448 | <xsl:with-param name="target" select="$targetBaseDir || '/header.xml'" as="xs:string"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 449 | </xsl:call-template> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 450 | |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 451 | <xsl:if test="$ann_named.xml"> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 452 | <xsl:variable name="rev_lookup-seq" as="map(*)+"> |
| 453 | <xsl:for-each |
| 454 | select="$ann_named.xml//tei:seg/tei:ptr"> |
| 455 | <xsl:variable name="trg" as="xs:string" select="fn:substring-before(@target, '#')"/> |
| 456 | <!-- caution: as of 01-June-2022, some of the pointers are malformed (missing '#' when referencing locally). |
| 457 | so we need to act around it but also sustainably - in case that error gets corrected --> |
| 458 | |
| 459 | <xsl:if test="fn:string-length($trg) and $trg eq 'ann_morphosyntax.xml'"> |
| 460 | <xsl:sequence> |
| 461 | <xsl:map-entry key="fn:substring-after(fn:string(@target), '#')" select="fn:current()" |
| 462 | /> |
| 463 | </xsl:sequence> |
| 464 | </xsl:if> |
| 465 | </xsl:for-each> |
| 466 | </xsl:variable> |
| 467 | <xsl:variable name="rev_lookup" as="map(*)" select="map:merge($rev_lookup-seq,map{'duplicates':'combine'})"/> |
| 468 | |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 469 | <xsl:call-template name="create_named"> |
| 470 | <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 471 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" |
| 472 | as="document-node()"/> |
| 473 | <xsl:with-param name="ann_named.xml" select="$ann_named.xml" |
| 474 | as="document-node()"/> |
| 475 | <xsl:with-param name="target" select="$targetBaseDir || '/nkjp/named.xml'" as="xs:string"/> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 476 | <xsl:with-param name="rev_lookup" select="$rev_lookup" as="map(*)"/> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 477 | </xsl:call-template> |
| 478 | </xsl:if> |
| 479 | |
| 480 | <xsl:if test="$ann_words.xml and $ann_groups.xml"> |
| 481 | <xsl:call-template name="create_groups"> |
| 482 | <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/> |
| 483 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" |
| 484 | as="document-node()"/> |
| 485 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" |
| 486 | as="document-node()"/> |
| 487 | <xsl:with-param name="ann_words.xml" select="$ann_words.xml" |
| 488 | as="document-node()"/> |
| 489 | <xsl:with-param name="ann_groups.xml" select="$ann_groups.xml" |
| 490 | as="document-node()"/> |
| 491 | <xsl:with-param name="target" select="$targetBaseDir || '/nkjp/groups.xml'" as="xs:string"/> |
| 492 | </xsl:call-template> |
| 493 | </xsl:if> |
| 494 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 495 | </xsl:template> |
| 496 | |
| 497 | <!-- ************************** data.xml ******************* --> |
| 498 | |
| 499 | <xsl:template name="create_data"> |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 500 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 501 | <xsl:param name="compoundID" as="xs:string"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 502 | <xsl:param name="target" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 503 | <!-- create the data.xml file --> |
| 504 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 505 | xpath-default-namespace="{$KorAP_namespace}" href="{$target}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 506 | |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 507 | <xsl:processing-instruction name="xml-model">href="text.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 508 | <xsl:element name="raw_text" namespace="{$KorAP_namespace}"> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 509 | <xsl:attribute name="docid" select="$compoundID"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 510 | <xsl:element name="metadata" namespace="{$KorAP_namespace}"> |
| 511 | <xsl:attribute name="file" select="'metadata.xml'"/> |
| 512 | </xsl:element> |
| 513 | |
| 514 | <xsl:element name="text" namespace="{$KorAP_namespace}"> |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 515 | <xsl:variable name="content" as="xs:string+"> |
Piotr Banski | 4f4c2d2 | 2022-05-19 01:44:32 +0200 | [diff] [blame] | 516 | <xsl:for-each select="$ann_segmentation.xml/tei:teiCorpus/tei:TEI/tei:text/tei:body/tei:p/tei:s//tei:seg[count(@nkjp:rejected) eq 0]"> |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 517 | <xsl:sequence select=" |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 518 | if (f:is_preceded_by_ws(.,false())) then |
bansp | 9dc1000 | 2022-05-17 22:33:34 +0200 | [diff] [blame] | 519 | ' ' |
| 520 | else |
| 521 | '', ./tei:w"/> |
| 522 | </xsl:for-each> |
| 523 | </xsl:variable> |
| 524 | <xsl:value-of select="string-join($content)"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 525 | </xsl:element> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 526 | </xsl:element> |
bansp | f79443e | 2022-02-25 14:25:33 +0100 | [diff] [blame] | 527 | </xsl:result-document> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 528 | </xsl:template> |
| 529 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 530 | <!-- ************************** struct ******************* --> |
| 531 | |
| 532 | <xsl:template name="create_struct"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 533 | <xsl:param name="compoundID" as="xs:string"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 534 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
| 535 | <xsl:param name="target" as="xs:string"/> |
Piotr Banski | 4f4c2d2 | 2022-05-19 01:44:32 +0200 | [diff] [blame] | 536 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 537 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 538 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 539 | <xsl:processing-instruction name="xml-model">href="span.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
| 540 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 541 | <xsl:attribute name="docid" select="$compoundID"/> |
| 542 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 543 | |
| 544 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 545 | <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="struct"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 546 | </xsl:element> |
| 547 | </xsl:element> |
| 548 | </xsl:result-document> |
| 549 | </xsl:template> |
| 550 | |
| 551 | <xsl:template match="tei:*" mode="struct"> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 552 | <xsl:variable name="offsets" as="xs:integer+"> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 553 | <xsl:sequence select="map:get(fn:accumulator-after('segmentation-offsets')[last()], string(@xml:id))"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 554 | </xsl:variable> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 555 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 556 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
Piotr Banski | e1ac520 | 2022-05-30 21:25:21 +0200 | [diff] [blame] | 557 | <xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 558 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 559 | <xsl:element name="span" namespace="{$KorAP_namespace}"> |
| 560 | <xsl:attribute name="id" select="'s' || $my_index"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 561 | <xsl:attribute name="from" select="$offsets[1]"/> |
| 562 | <xsl:attribute name="to" select="$offsets[2]"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 563 | <xsl:attribute name="l" select="f:compute_nesting(.)"/> |
Piotr Banski | 09096ee | 2022-05-25 13:41:03 +0200 | [diff] [blame] | 564 | <xsl:if test="local-name() eq 'seg' and $SHOW_ORTH_IN_STRUCT"> |
| 565 | <xsl:comment><xsl:value-of select="fn:normalize-space(.)"/></xsl:comment> |
| 566 | </xsl:if> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 567 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 568 | <xsl:attribute name="type" select="'struct'"></xsl:attribute> <!-- STRUCT vs. LEX for morpho --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 569 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 570 | <xsl:attribute name="name" select="'name'"/> |
| 571 | <xsl:value-of select="local-name()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 572 | </xsl:element> |
| 573 | <xsl:if test="count(@*)"> |
| 574 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 575 | <xsl:attribute name="name" select="'attr'"/> |
| 576 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 577 | <xsl:attribute name="type" select="'attr'"/> |
| 578 | <xsl:for-each select="@*"> |
| 579 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 580 | <xsl:attribute name="name" select="local-name(.)"/> |
| 581 | <xsl:value-of select="."/> |
| 582 | </xsl:element> |
| 583 | </xsl:for-each> |
| 584 | </xsl:element> |
| 585 | </xsl:element> |
| 586 | </xsl:if> |
| 587 | </xsl:element> |
| 588 | </xsl:element> |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 589 | <xsl:apply-templates mode="struct"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 590 | </xsl:template> |
| 591 | |
| 592 | <!-- ************************** morpho ******************* --> |
| 593 | |
| 594 | <xsl:template name="create_morpho"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 595 | <xsl:param name="compoundID" as="xs:string"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 596 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 597 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 598 | <xsl:param name="target" as="xs:string"/> |
| 599 | |
| 600 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 601 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 602 | <xsl:processing-instruction name="xml-model">href="span.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 603 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 604 | <xsl:attribute name="docid" select="$compoundID"/> |
| 605 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 606 | |
| 607 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
| 608 | <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="morpho"> |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 609 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()" tunnel="yes"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 610 | </xsl:apply-templates> |
| 611 | </xsl:element> |
| 612 | </xsl:element> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 613 | </xsl:result-document> |
| 614 | </xsl:template> |
| 615 | |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 616 | <xsl:template match="tei:seg" mode="morpho"> |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 617 | <xsl:param name="ann_morphosyntax.xml" as="document-node()" tunnel="yes"/> |
| 618 | <!-- it's so spread out because I wanted to make sure to be able to look up the individual |
| 619 | constituent values, should anything go wrong; it might get compacted at some point, but |
| 620 | the increase in efficiency will probably be minimal, compared to the decrease of readability --> |
| 621 | <xsl:variable name="offsets" as="xs:integer+"> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 622 | <xsl:sequence select="map:get(fn:accumulator-after('segmentation-offsets')[last()], string(@xml:id))"/> |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 623 | </xsl:variable> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 624 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
| 625 | <xsl:variable name="my_id" select="@xml:id" as="xs:string"/> |
| 626 | <xsl:variable name="my_morph-seg" as="node()" select="$ann_morphosyntax.xml//tei:seg[substring-after(@corresp,'#') eq $my_id]"/> |
| 627 | <xsl:variable name="my_disamb" select="$my_morph-seg//tei:fs/tei:f[@name eq 'disamb']" as="node()"/> |
| 628 | <xsl:variable name="my_choice-id" select="substring-after($my_disamb//tei:f[@name eq 'choice']/@fVal,'#')" as="xs:string"/> |
| 629 | <xsl:variable name="my_choice-lex" select="$my_morph-seg//tei:f[@name eq 'interps']/tei:fs[@type eq 'lex'][descendant::tei:symbol[@xml:id eq $my_choice-id]]" as="node()"/> |
| 630 | <xsl:variable name="chosen-msd" as="xs:string" select="$my_choice-lex/descendant::tei:symbol[@xml:id eq $my_choice-id]/@value"/> |
Piotr Banski | e1ac520 | 2022-05-30 21:25:21 +0200 | [diff] [blame] | 631 | <xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 632 | |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 633 | <xsl:element name="span" namespace="{$KorAP_namespace}"> |
Piotr Banski | a51907c | 2022-05-25 15:09:41 +0200 | [diff] [blame] | 634 | <xsl:attribute name="id" select="'m' || $my_index"/> |
| 635 | <xsl:attribute name="from" select="$offsets[1]"/> |
| 636 | <xsl:attribute name="to" select="$offsets[2]"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 637 | <xsl:attribute name="l" select="f:compute_nesting(.)"/> |
| 638 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 639 | <xsl:attribute name="type" select="'lex'"/> |
| 640 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 641 | <xsl:attribute name="name" select="'lex'"/> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 642 | <xsl:comment select="(if(@nkjp:nps) then ' ' else '_') || $my_morph-seg//tei:fs/tei:f[@name eq 'orth']/tei:string"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 643 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 644 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 645 | <xsl:attribute name="name" select="'lemma'"/> |
| 646 | <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'base']/tei:string"/> |
| 647 | </xsl:element> |
| 648 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 649 | <xsl:attribute name="name" select="'pos'"/> |
| 650 | <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'ctag']/tei:symbol/@value"/> |
| 651 | </xsl:element> |
| 652 | <xsl:if test="string-length($chosen-msd)"> |
| 653 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 654 | <xsl:attribute name="name" select="'msd'"/> |
| 655 | <xsl:value-of select="$chosen-msd"/> |
| 656 | </xsl:element> |
| 657 | </xsl:if> |
| 658 | <xsl:if test="$my_morph-seg//tei:fs/tei:f[@name eq 'nps']"> |
| 659 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 660 | <xsl:attribute name="name" select="'join'"/> |
| 661 | <xsl:value-of select="'left'"/> |
| 662 | </xsl:element> |
| 663 | </xsl:if> |
| 664 | </xsl:element> |
| 665 | </xsl:element> |
| 666 | </xsl:element> |
| 667 | </xsl:element> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 668 | </xsl:template> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 669 | |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 670 | <!-- ************************** named entities ******************* --> |
| 671 | |
| 672 | <xsl:template name="create_named"> |
| 673 | <xsl:param name="compoundID" as="xs:string"/> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 674 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 675 | <xsl:param name="ann_named.xml" as="document-node()"/> |
| 676 | <xsl:param name="target" as="xs:string"/> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 677 | <xsl:param name="rev_lookup" as="map(*)"/> |
| 678 | |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 679 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 680 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 681 | <xsl:processing-instruction name="xml-model">href="span.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
| 682 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 683 | <xsl:attribute name="docid" select="$compoundID"/> |
| 684 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 685 | |
| 686 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 687 | <xsl:apply-templates select="$ann_morphosyntax.xml//tei:text" mode="named"> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 688 | <xsl:with-param name="ann_named.xml" select="$ann_named.xml" as="document-node()" tunnel="yes"/> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 689 | <xsl:with-param name="rev_lookup" select="$rev_lookup" as="map(*)" tunnel="yes"/> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 690 | </xsl:apply-templates> |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 691 | </xsl:element> |
| 692 | </xsl:element> |
| 693 | </xsl:result-document> |
| 694 | </xsl:template> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 695 | |
| 696 | <xsl:template match="tei:seg" mode="named"/> |
| 697 | |
| 698 | <xsl:template match="tei:seg[tei:fs[tei:f[@name eq 'disamb']]]" mode="named"> |
| 699 | <xsl:param name="ann_named.xml" as="document-node()" tunnel="yes"/> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 700 | <xsl:param name="rev_lookup" as="map(*)" tunnel="yes"/> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 701 | |
| 702 | <xsl:variable name="offsets" as="xs:integer+"> |
| 703 | <xsl:sequence select="map:get(fn:accumulator-after('morpho-offsets')[last()], string(@xml:id))"/> |
| 704 | </xsl:variable> |
| 705 | |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 706 | <xsl:variable name="ptr" select="map:get($rev_lookup,fn:string(@xml:id))" as="element(tei:ptr)*"/> |
| 707 | <!-- it's an element, because we need to see where it stands in a sequence... --> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 708 | |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 709 | <xsl:if test="$ptr"> |
| 710 | <xsl:variable name="my_id" select="@xml:id" as="xs:string"/> |
| 711 | <xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/> |
| 712 | |
| 713 | <xsl:element name="span" namespace="{$KorAP_namespace}"> |
| 714 | <xsl:attribute name="id" select="'n' || $my_index"/> |
| 715 | <xsl:attribute name="from" select="$offsets[1]"/> |
| 716 | <xsl:attribute name="to" select="$offsets[2]"/> |
| 717 | <xsl:attribute name="l" select="f:compute_nesting(.)"/> |
| 718 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 719 | <xsl:attribute name="type" select="'ne'"/> |
| 720 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 721 | <xsl:attribute name="name" select="'ne'"/> |
| 722 | <xsl:comment select=" |
| 723 | (if (tei:fs/tei:f[@name eq 'nps']) then |
| 724 | ' ' |
| 725 | else |
| 726 | '_') || tei:fs/tei:f[@name eq 'orth']/tei:string"/> |
| 727 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 728 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 729 | <xsl:attribute name="name" select="'complex-ent'"/> |
| 730 | <xsl:for-each select="$ptr"> |
| 731 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 732 | <xsl:attribute name="type" select="'complex-ent'"/> |
| 733 | <xsl:for-each select="parent::tei:seg/tei:fs[1]/tei:f"> |
| 734 | <xsl:if test="@name eq 'type' or @name eq 'subtype'"> |
| 735 | <xsl:copy-of select="." copy-namespaces="no"/> |
| 736 | </xsl:if> |
| 737 | </xsl:for-each> |
| 738 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 739 | <xsl:attribute name="name" select="'nkjp-named'"/> |
| 740 | <xsl:copy-of select="parent::tei:seg/tei:fs[1]" copy-namespaces="no"/> |
| 741 | </xsl:element> |
| 742 | </xsl:element> |
| 743 | </xsl:for-each> |
| 744 | |
| 745 | </xsl:element> |
| 746 | |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 747 | </xsl:element> |
| 748 | </xsl:element> |
| 749 | </xsl:element> |
| 750 | </xsl:element> |
Piotr Banski | 763b41f | 2022-06-02 01:13:23 +0200 | [diff] [blame^] | 751 | </xsl:if> |
Piotr Banski | 65a6d0b | 2022-05-31 17:23:08 +0200 | [diff] [blame] | 752 | </xsl:template> |
| 753 | |
Piotr Banski | c5950ce | 2022-05-27 15:07:08 +0200 | [diff] [blame] | 754 | |
| 755 | <!-- ************************** syntactic chunks ******************* --> |
| 756 | |
| 757 | <xsl:template name="create_groups"> |
| 758 | <xsl:param name="compoundID" as="xs:string"/> |
| 759 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
| 760 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 761 | <xsl:param name="ann_words.xml" as="document-node()"/> |
| 762 | <xsl:param name="ann_groups.xml" as="document-node()"/> |
| 763 | <xsl:param name="target" as="xs:string"/> |
| 764 | |
| 765 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 766 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 767 | <xsl:processing-instruction name="xml-model">href="span.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
| 768 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 769 | <xsl:attribute name="docid" select="$compoundID"/> |
| 770 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 771 | |
| 772 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
| 773 | <!--<xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="groups"> |
| 774 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()" tunnel="yes"/> |
| 775 | <xsl:with-param name="ann_words.xml" select="$ann_words.xml" as="document-node()" tunnel="yes"/> |
| 776 | <xsl:with-param name="ann_groups.xml" select="$ann_groups.xml" as="document-node()" tunnel="yes"/> |
| 777 | </xsl:apply-templates>--> |
| 778 | </xsl:element> |
| 779 | </xsl:element> |
| 780 | </xsl:result-document> |
| 781 | </xsl:template> |
| 782 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 783 | <!-- ************************** TEXT header ******************* --> |
| 784 | |
| 785 | <xsl:template name="create_text_header"> |
| 786 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 787 | <xsl:param name="compoundID" as="xs:string"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 788 | <xsl:param name="target" as="xs:string"/> |
| 789 | |
| 790 | <!-- create the local header.xml file --> |
| 791 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 792 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 793 | |
| 794 | <idsHeader type="document" pattern="text" status="new" version="1.1" TEIform="teiHeader"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 795 | <xsl:apply-templates select="$text.xml//tei:TEI/tei:teiHeader/tei:*" mode="text"> |
| 796 | <xsl:with-param name="compoundID" as="xs:string" select="$compoundID" tunnel="yes"/> |
| 797 | </xsl:apply-templates> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 798 | </idsHeader> |
| 799 | </xsl:result-document> |
| 800 | </xsl:template> |
| 801 | |
| 802 | <xsl:template match="tei:fileDesc" mode="text"> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 803 | <xsl:element name="{local-name()}"> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 804 | <xsl:apply-templates mode="text"/> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 805 | </xsl:element> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 806 | </xsl:template> |
| 807 | |
| 808 | <xsl:template match="tei:title" mode="text"> |
| 809 | <t.title> |
| 810 | <xsl:apply-templates/> |
| 811 | </t.title> |
| 812 | </xsl:template> |
| 813 | |
| 814 | <xsl:template match="tei:titleStmt" mode="text"> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 815 | <xsl:param name="compoundID" as="xs:string" tunnel="yes"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 816 | <titleStmt> |
| 817 | <textSigle> |
bansp | e726b4a | 2022-03-28 05:47:45 +0200 | [diff] [blame] | 818 | <xsl:value-of select="$compoundID"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 819 | </textSigle> |
| 820 | <xsl:apply-templates mode="text"/> |
| 821 | </titleStmt> |
| 822 | </xsl:template> |
| 823 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 824 | <xsl:template match="tei:publicationStmt" mode="text"> |
| 825 | <xsl:element name="{local-name()}"> |
| 826 | <xsl:apply-templates mode="text"/> |
| 827 | </xsl:element> |
| 828 | </xsl:template> |
| 829 | |
| 830 | <xsl:template match="tei:availability" mode="text"> |
| 831 | <xsl:element name="{local-name()}"> |
| 832 | <xsl:apply-templates mode="text" select="@* | *"/> |
| 833 | </xsl:element> |
| 834 | </xsl:template> |
| 835 | |
| 836 | <xsl:template match="tei:profileDesc" mode="text"> |
| 837 | <xsl:element name="{local-name()}"> |
| 838 | <xsl:apply-templates mode="text"/> |
| 839 | </xsl:element> |
| 840 | </xsl:template> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 841 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 842 | <xsl:template match="tei:textClass" mode="text"> |
| 843 | <xsl:element name="{local-name()}"> |
| 844 | <xsl:apply-templates mode="text" select="@* | *"/> |
| 845 | </xsl:element> |
| 846 | </xsl:template> |
| 847 | |
| 848 | <xsl:template match="tei:catRef" mode="text corpus"> |
| 849 | <xsl:element name="{local-name()}"> |
| 850 | <xsl:apply-templates mode="text" select="@* | *"/> |
| 851 | </xsl:element> |
| 852 | </xsl:template> |
| 853 | |
| 854 | <xsl:template match="@status | @scheme | @target | @type | @xml:id[ancestor::tei:classDecl] | @xml:lang" mode="text corpus"> |
| 855 | <xsl:copy-of select="."/> |
| 856 | </xsl:template> |
| 857 | |
| 858 | <xsl:template match="tei:p" mode="text corpus"> |
| 859 | <xsl:element name="{local-name()}"> |
| 860 | <xsl:apply-templates mode="header-text"/> |
| 861 | </xsl:element> |
| 862 | </xsl:template> |
| 863 | |
| 864 | |
| 865 | <!-- OPTIMIZATION has to take modes into account --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 866 | <!-- ************************** CORPUS header ******************* --> |
| 867 | <xsl:template name="create_corpus_header"> |
| 868 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 869 | <xsl:param name="target" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 870 | |
| 871 | <!-- create the corpus-level header.xml file --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 872 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" href="{$target}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 873 | |
| 874 | <!--doctype-public="{$publicDoctypeI5}" |
| 875 | doctype-system="{$systemDoctypeI5}"> |
| 876 | these are, sadly, useless |
| 877 | --> |
| 878 | |
| 879 | <idsHeader type="corpus" pattern="text" status="new" version="1.1" TEIform="teiHeader"> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 880 | <xsl:apply-templates select="$text.xml/tei:teiCorpus/tei:teiHeader/tei:*" mode="corpus"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 881 | </idsHeader> |
| 882 | </xsl:result-document> |
| 883 | </xsl:template> |
| 884 | |
| 885 | <xsl:template match="tei:fileDesc" mode="corpus"> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 886 | <xsl:element name="{local-name()}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 887 | <xsl:apply-templates mode="corpus"/> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 888 | </xsl:element> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 889 | </xsl:template> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 890 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 891 | |
| 892 | <xsl:template match="tei:title" mode="corpus"> |
| 893 | <c.title> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 894 | <xsl:apply-templates mode="corpus" select="@*"/> |
| 895 | <xsl:apply-templates mode="header-text"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 896 | </c.title> |
| 897 | </xsl:template> |
| 898 | |
| 899 | <xsl:template match="tei:titleStmt" mode="corpus"> |
| 900 | <titleStmt> |
| 901 | <korpusSigle> |
| 902 | <xsl:value-of select="$corpusID"/> |
| 903 | </korpusSigle> |
| 904 | <xsl:apply-templates mode="corpus"/> |
| 905 | </titleStmt> |
| 906 | </xsl:template> |
| 907 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 908 | <xsl:template match="tei:publicationStmt" mode="corpus"> |
| 909 | <xsl:element name="{local-name()}"> |
| 910 | <xsl:apply-templates mode="corpus"/> |
| 911 | </xsl:element> |
| 912 | </xsl:template> |
| 913 | |
| 914 | <xsl:template match="tei:availability" mode="corpus"> |
| 915 | <xsl:element name="{local-name()}"> |
| 916 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 917 | </xsl:element> |
| 918 | </xsl:template> |
| 919 | |
| 920 | <xsl:template match="tei:encodingDesc" mode="corpus"> |
| 921 | <xsl:element name="{local-name()}"> |
| 922 | <xsl:apply-templates mode="corpus"/> |
| 923 | </xsl:element> |
| 924 | </xsl:template> |
| 925 | |
| 926 | <xsl:template match="tei:classDecl | tei:taxonomy | tei:category | tei:taxonomy/tei:bibl" mode="corpus"> |
| 927 | <xsl:element name="{local-name()}"> |
| 928 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 929 | </xsl:element> |
| 930 | </xsl:template> |
| 931 | |
| 932 | <xsl:template match="tei:bibl/tei:title | tei:edition | tei:desc" mode="corpus"> |
| 933 | <xsl:element name="{local-name()}"> |
| 934 | <xsl:apply-templates mode="corpus" select="@*"/> |
| 935 | <xsl:apply-templates mode="header-text"/> |
| 936 | </xsl:element> |
| 937 | </xsl:template> |
| 938 | <!-- |
| 939 | <xsl:template match="tei:textClass" mode="corpus"> |
| 940 | <xsl:element name="{local-name()}"> |
| 941 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 942 | </xsl:element> |
| 943 | </xsl:template> |
| 944 | |
| 945 | <xsl:template match="tei:catRef" mode="corpus"> |
| 946 | <xsl:element name="{local-name()}"> |
| 947 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 948 | </xsl:element> |
| 949 | </xsl:template> |
| 950 | --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 951 | |
| 952 | |
| 953 | |
| 954 | <!-- this template can be called by the XSPEC test; TODO: find a way to call the main() template directly --> |
| 955 | <!-- I have not fully handled the param transmission, which would have to be kludged in just for the sake of XSPec, |
| 956 | because I'm disabling this for now, due to XSpec design issues; relevant links, a.o.: |
| 957 | |
| 958 | https://stackoverflow.com/questions/64933277/what-is-the-cause-of-error-cannot-execute-xslresult-document-while-evaluating |
| 959 | https://www.balisage.net/Proceedings/vol25/html/Galtman01/BalisageVol25-Galtman01.html |
| 960 | |
| 961 | In short: the internal design of XSpec forces kludges when one wants to use xsl:result-document in their stylesheets. But I don't |
| 962 | want to be strangled by kludges at the beginning of work, I've already lost quite a bit of time on this investigation, |
| 963 | I will therefore "just code" and then can think of externalizing bits of templates if we want to play with tests. For now, |
| 964 | I don't want to have to handle context items is a special way inside variables, etc., because I'm not sure it's worth it. |
| 965 | |
| 966 | --> |
| 967 | <!--<xsl:template name="test_full"> |
| 968 | <xsl:param name="corpusID"/> |
| 969 | <xsl:param name="docID"/> |
| 970 | <xsl:param name="textID"/> |
| 971 | <xsl:call-template name="xsl:initial-template"/> |
| 972 | </xsl:template>--> |
| 973 | |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 974 | </xsl:stylesheet> |
Piotr Banski | 6a4a252 | 2022-05-24 01:16:47 +0200 | [diff] [blame] | 975 | |
Piotr Banski | fdc858a | 2022-05-25 02:40:32 +0200 | [diff] [blame] | 976 | <!-- template for serializing maps in messages <xsl:message select="('map:',serialize($map, map{'method':'adaptive'}))"/> --> |