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