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" |
| 5 | xmlns:map="http://www.w3.org/2005/xpath-functions/map" exclude-result-prefixes="xs f map nkjp tei" |
| 6 | version="3.0" expand-text="yes"> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 7 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 8 | <xsl:param name="corpusID" as="xs:string"/> |
| 9 | <xsl:param name="docID" as="xs:string"/> |
| 10 | <xsl:param name="textID" as="xs:string"/> |
| 11 | |
| 12 | <xsl:param name="sourceDir" select="'test/resources/nkjp2korap_sample1/KOT/'" as="xs:string"/> |
bansp | f79443e | 2022-02-25 14:25:33 +0100 | [diff] [blame] | 13 | <!-- the select is a fallback, so that it's clear to the reviewer what I'm passing in the param --> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 14 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 15 | <xsl:variable name="targetTextDir" |
| 16 | select="'test/output/' || $corpusID || '/' || $docID || '/' || $textID || '/'" as="xs:string"/> |
| 17 | <xsl:variable name="targetCorpusDir" select="'test/output/' || $corpusID || '/'" as="xs:string"/> |
| 18 | |
| 19 | <xsl:variable name="systemDoctypeI5" |
| 20 | select="'http://corpora.ids-mannheim.de/idsxces1/DTD/ids.xcesdoc.dtd'" as="xs:string" |
| 21 | static="true"/> |
| 22 | |
| 23 | <xsl:variable name="publicDoctypeI5" select="'-//IDS//DTD IDS-XCES 1.0//EN'" as="xs:string" |
| 24 | static="true"/> |
| 25 | |
| 26 | <xsl:variable name="KorAP_namespace" select="'http://ids-mannheim.de/ns/KorAP'" static="true" |
| 27 | as="xs:string"/> |
| 28 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 29 | <xsl:variable name="KorAP-XML_version" select="'KorAP-0.4'" as="xs:string" static="true"/> |
| 30 | <!-- this is only a bit funny --> |
| 31 | |
| 32 | <xsl:variable name="compoundID" as="xs:string" |
| 33 | select="$corpusID || '_' || $docID || '.' || $textID"/> |
| 34 | <!-- this is what occurs in the text and data layers as @docid --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 35 | |
| 36 | <xsl:mode name="corpus" on-no-match="deep-skip"/> |
| 37 | <xsl:mode name="text" on-no-match="deep-skip"/> |
| 38 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 39 | <!-- <xsl:variable name="text_depth" as="xs:integer" select="xs:integer('2')" static="true"/> |
| 40 | <!-\- this magic number indicates the depth of the <TEI> element inside teiCorpus/TEI -\-> |
| 41 | --> |
| 42 | <xsl:function name="f:compute_nesting" as="xs:integer"> |
| 43 | <xsl:param name="node" as="node()"/> |
| 44 | <xsl:variable name="rel_depth" |
| 45 | select="count($node/ancestor-or-self::*[local-name(.) ne 'TEI'][local-name(.) ne 'teiCorpus'])" |
| 46 | as="xs:integer"/> |
| 47 | <!-- I think my skills are lacking --> |
| 48 | <xsl:sequence select="$rel_depth"/> |
| 49 | </xsl:function> |
| 50 | |
| 51 | <xsl:function name="f:calc_content_length" as="xs:integer"> |
| 52 | <xsl:param name="node" as="node()"/> |
| 53 | <xsl:choose> |
| 54 | <xsl:when test="$node/self::tei:text or $node/self::tei:body"> |
| 55 | <xsl:variable name="last_corresp" |
| 56 | select="$node/descendant::tei:p[last()]/descendant::tei:s[last()]/descendant::tei:seg[last()]/attribute::corresp" |
| 57 | as="attribute(corresp)"/> |
| 58 | <xsl:variable name="numbers" select="substring-after(substring-before($last_corresp,')'),',')"/> |
| 59 | <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/> |
| 60 | </xsl:when> |
| 61 | <xsl:when test="$node/self::tei:p"> |
| 62 | <xsl:variable name="last_corresp" |
| 63 | select="$node/descendant::tei:s[last()]/descendant::tei:seg[last()]/attribute::corresp" |
| 64 | as="attribute(corresp)"/> |
| 65 | <xsl:variable name="numbers" select="substring-after(substring-before($last_corresp,')'),',')"/> |
| 66 | <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/> |
| 67 | </xsl:when> |
| 68 | <xsl:when test="$node/self::tei:s"> |
| 69 | <xsl:variable name="last_corresp" |
| 70 | select="$node/descendant::tei:seg[last()]/attribute::corresp" |
| 71 | as="attribute(corresp)"/> |
| 72 | <xsl:variable name="numbers" select="substring-after(substring-before($last_corresp,')'),',')"/> |
| 73 | <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/> |
| 74 | </xsl:when> |
| 75 | <xsl:otherwise> |
| 76 | <xsl:variable name="numbers" select="substring-after(substring-before($node/@corresp,')'),',')"/> |
| 77 | <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/> |
| 78 | </xsl:otherwise> |
| 79 | </xsl:choose> |
| 80 | </xsl:function> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 81 | |
| 82 | <xsl:template name="xsl:initial-template"> |
| 83 | <xsl:variable name="text.xml" as="document-node()" select="doc($sourceDir || 'text.xml')"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 84 | <xsl:variable name="ann_morphosyntax.xml" as="document-node()" |
| 85 | select="doc($sourceDir || 'ann_morphosyntax.xml')"/> |
| 86 | <xsl:variable name="ann_segmentation.xml" as="document-node()" |
| 87 | select="doc($sourceDir || 'ann_segmentation.xml')"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 88 | |
| 89 | <xsl:call-template name="create_data"> |
| 90 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 91 | <xsl:with-param name="target" select="$targetTextDir || 'data.xml'" as="xs:string"/> |
| 92 | </xsl:call-template> |
| 93 | |
| 94 | <xsl:call-template name="create_struct"> |
| 95 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
| 96 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" |
| 97 | as="document-node()"/> |
| 98 | <xsl:with-param name="target" select="$targetTextDir || 'struct/structure.xml'" as="xs:string" |
| 99 | /> |
| 100 | </xsl:call-template> |
| 101 | |
| 102 | <xsl:call-template name="create_morpho"> |
| 103 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 104 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" |
| 105 | as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 106 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" |
| 107 | as="document-node()"/> |
| 108 | <xsl:with-param name="target" select="$targetTextDir || 'nkjp/morpho.xml'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 109 | </xsl:call-template> |
| 110 | |
| 111 | <xsl:call-template name="create_text_header"> |
| 112 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 113 | <xsl:with-param name="target" select="$targetTextDir || 'header.xml'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 114 | </xsl:call-template> |
| 115 | |
| 116 | <xsl:call-template name="create_corpus_header"> |
| 117 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 118 | <xsl:with-param name="target" select="$targetCorpusDir || 'header.xml'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 119 | </xsl:call-template> |
| 120 | </xsl:template> |
| 121 | |
| 122 | <!-- ************************** data.xml ******************* --> |
| 123 | |
| 124 | <xsl:template name="create_data"> |
| 125 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 126 | <xsl:param name="target" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 127 | <!-- create the data.xml file --> |
| 128 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 129 | xpath-default-namespace="{$KorAP_namespace}" href="{$target}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 130 | |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 131 | <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] | 132 | <xsl:element name="raw_text" namespace="{$KorAP_namespace}"> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 133 | <xsl:attribute name="docid" select="$compoundID"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 134 | <xsl:element name="metadata" namespace="{$KorAP_namespace}"> |
| 135 | <xsl:attribute name="file" select="'metadata.xml'"/> |
| 136 | </xsl:element> |
| 137 | |
| 138 | <xsl:element name="text" namespace="{$KorAP_namespace}"> |
bansp | f79443e | 2022-02-25 14:25:33 +0100 | [diff] [blame] | 139 | <xsl:value-of select="$text.xml//*[local-name() = 'ab']"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 140 | </xsl:element> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 141 | </xsl:element> |
bansp | f79443e | 2022-02-25 14:25:33 +0100 | [diff] [blame] | 142 | </xsl:result-document> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 143 | </xsl:template> |
| 144 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 145 | <!-- ************************** struct ******************* --> |
| 146 | |
| 147 | <xsl:template name="create_struct"> |
| 148 | <xsl:param name="text.xml" as="document-node()"/> |
| 149 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
| 150 | <xsl:param name="target" as="xs:string"/> |
| 151 | |
| 152 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 153 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 154 | <xsl:processing-instruction name="xml-model">href="span.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
| 155 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 156 | <xsl:attribute name="docid" select="$compoundID"/> |
| 157 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 158 | |
| 159 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
| 160 | <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="struct"/> |
| 161 | </xsl:element> |
| 162 | </xsl:element> |
| 163 | </xsl:result-document> |
| 164 | </xsl:template> |
| 165 | |
| 166 | <xsl:template match="tei:*" mode="struct"> |
| 167 | <xsl:param name="ini" as="xs:integer" required="no" select="0"/> |
| 168 | <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/> |
| 169 | <xsl:param name="index" as="xs:integer" required="no" select="1"/> |
| 170 | <!-- I have made a major mess here, but it works... it's so spread out |
| 171 | because I wanted to make sure to be able to look up the individual |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 172 | constituent values, should anything go wrong; optimization will come when it's worked against a larger dataset --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 173 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
| 174 | <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/> |
| 175 | <xsl:variable name="preceding-count" select="count($preceding)"/> |
| 176 | <xsl:variable name="outside-preceding-count" as="xs:integer"> |
| 177 | <xsl:choose> |
| 178 | <xsl:when test="self::tei:s or self::tei:p"> |
| 179 | <xsl:choose> |
| 180 | <xsl:when test="$preceding-count"> |
| 181 | <xsl:sequence select=" |
| 182 | sum(for $p in $preceding |
| 183 | return |
| 184 | count($p/descendant::*))"/> |
| 185 | </xsl:when> |
| 186 | <xsl:otherwise> |
| 187 | <xsl:sequence select="0"/> |
| 188 | </xsl:otherwise> |
| 189 | </xsl:choose> |
| 190 | </xsl:when> |
| 191 | <xsl:otherwise> |
| 192 | <xsl:sequence select="0"/> |
| 193 | </xsl:otherwise> |
| 194 | </xsl:choose> |
| 195 | </xsl:variable> |
| 196 | <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count" |
| 197 | as="xs:integer"/> |
| 198 | |
| 199 | <xsl:variable name="start" as="xs:integer"> |
| 200 | <xsl:choose> |
| 201 | <xsl:when test="self::tei:text or self::tei:body"> |
| 202 | <xsl:sequence select="0"/> |
| 203 | </xsl:when> |
| 204 | <xsl:when test="self::tei:p"> |
| 205 | <xsl:variable name="first_corresp" |
| 206 | select="descendant::tei:s[1]/descendant::tei:seg[1]/attribute::corresp" |
| 207 | as="attribute(corresp)"/> |
| 208 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 209 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 210 | </xsl:when> |
| 211 | <xsl:when test="self::tei:s"> |
| 212 | <xsl:variable name="first_corresp" |
| 213 | select="descendant::tei:seg[1]/attribute::corresp" |
| 214 | as="attribute(corresp)"/> |
| 215 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 216 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 217 | </xsl:when> |
| 218 | <xsl:when test="self::tei:seg"> |
| 219 | <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/> |
| 220 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 221 | </xsl:when> |
| 222 | </xsl:choose> |
| 223 | </xsl:variable> |
| 224 | <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)"> |
| 225 | </xsl:variable> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 226 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 227 | <xsl:element name="span" namespace="{$KorAP_namespace}"> |
| 228 | <xsl:attribute name="id" select="'s' || $my_index"/> |
| 229 | <xsl:attribute name="from" select="$start"/> |
| 230 | <xsl:attribute name="to" select="$end"/> |
| 231 | <xsl:attribute name="l" select="f:compute_nesting(.)"/> |
| 232 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 233 | <xsl:attribute name="type" select="'struct'"></xsl:attribute> <!-- STRUCT vs. LEX --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 234 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 235 | <xsl:attribute name="name" select="'name'"/> |
| 236 | <xsl:value-of select="local-name()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 237 | </xsl:element> |
| 238 | <xsl:if test="count(@*)"> |
| 239 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 240 | <xsl:attribute name="name" select="'attr'"/> |
| 241 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 242 | <xsl:attribute name="type" select="'attr'"/> |
| 243 | <xsl:for-each select="@*"> |
| 244 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 245 | <xsl:attribute name="name" select="local-name(.)"/> |
| 246 | <xsl:value-of select="."/> |
| 247 | </xsl:element> |
| 248 | </xsl:for-each> |
| 249 | </xsl:element> |
| 250 | </xsl:element> |
| 251 | </xsl:if> |
| 252 | </xsl:element> |
| 253 | </xsl:element> |
| 254 | <xsl:apply-templates mode="struct"> |
| 255 | <xsl:with-param name="ini" select="$start" as="xs:integer"/> |
| 256 | <xsl:with-param name="fin" select="$end" as="xs:integer"/> |
| 257 | <xsl:with-param name="index" select="$my_index"/> |
| 258 | </xsl:apply-templates> |
| 259 | </xsl:template> |
| 260 | |
| 261 | <!-- ************************** morpho ******************* --> |
| 262 | |
| 263 | <xsl:template name="create_morpho"> |
| 264 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 265 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 266 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 267 | <xsl:param name="target" as="xs:string"/> |
| 268 | |
| 269 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 270 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 271 | <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^] | 272 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 273 | <xsl:attribute name="docid" select="$compoundID"/> |
| 274 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 275 | |
| 276 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
| 277 | <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="morpho"> |
| 278 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/> |
| 279 | </xsl:apply-templates> |
| 280 | </xsl:element> |
| 281 | </xsl:element> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 282 | </xsl:result-document> |
| 283 | </xsl:template> |
| 284 | |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 285 | <xsl:template match="tei:*" mode="morpho"> |
| 286 | <xsl:param name="ini" as="xs:integer" required="no" select="0"/> |
| 287 | <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/> |
| 288 | <xsl:param name="index" as="xs:integer" required="no" select="1"/> |
| 289 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 290 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
| 291 | <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/> |
| 292 | <xsl:variable name="preceding-count" select="count($preceding)"/> |
| 293 | <xsl:variable name="outside-preceding-count" as="xs:integer"> |
| 294 | <xsl:choose> |
| 295 | <xsl:when test="self::tei:s or self::tei:p"> |
| 296 | <xsl:choose> |
| 297 | <xsl:when test="$preceding-count"> |
| 298 | <xsl:sequence select=" |
| 299 | sum(for $p in $preceding |
| 300 | return |
| 301 | count($p/descendant::*))"/> |
| 302 | </xsl:when> |
| 303 | <xsl:otherwise> |
| 304 | <xsl:sequence select="0"/> |
| 305 | </xsl:otherwise> |
| 306 | </xsl:choose> |
| 307 | </xsl:when> |
| 308 | <xsl:otherwise> |
| 309 | <xsl:sequence select="0"/> |
| 310 | </xsl:otherwise> |
| 311 | </xsl:choose> |
| 312 | </xsl:variable> |
| 313 | <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count" |
| 314 | as="xs:integer"/> |
| 315 | |
| 316 | <xsl:variable name="start" as="xs:integer"> |
| 317 | <xsl:choose> |
| 318 | <xsl:when test="self::tei:text or self::tei:body"> |
| 319 | <xsl:sequence select="0"/> |
| 320 | </xsl:when> |
| 321 | <xsl:when test="self::tei:p"> |
| 322 | <xsl:variable name="first_corresp" |
| 323 | select="descendant::tei:s[1]/descendant::tei:seg[1]/attribute::corresp" |
| 324 | as="attribute(corresp)"/> |
| 325 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 326 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 327 | </xsl:when> |
| 328 | <xsl:when test="self::tei:s"> |
| 329 | <xsl:variable name="first_corresp" |
| 330 | select="descendant::tei:seg[1]/attribute::corresp" |
| 331 | as="attribute(corresp)"/> |
| 332 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 333 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 334 | </xsl:when> |
| 335 | <!--<xsl:when test="self::tei:seg"> |
| 336 | <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/> |
| 337 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 338 | </xsl:when>--> |
| 339 | </xsl:choose> |
| 340 | </xsl:variable> |
| 341 | <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)"> |
| 342 | </xsl:variable> |
| 343 | |
| 344 | <xsl:apply-templates mode="morpho"> |
| 345 | <xsl:with-param name="ini" select="$start" as="xs:integer"/> |
| 346 | <xsl:with-param name="fin" select="$end" as="xs:integer"/> |
| 347 | <xsl:with-param name="index" select="$my_index"/> |
| 348 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/> |
| 349 | </xsl:apply-templates> |
| 350 | </xsl:template> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 351 | |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame^] | 352 | <xsl:template match="tei:seg" mode="morpho"> |
| 353 | <xsl:param name="ini" as="xs:integer" required="no" select="0"/> |
| 354 | <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/> |
| 355 | <xsl:param name="index" as="xs:integer" required="no" select="1"/> |
| 356 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 357 | <!-- I have made a major mess here, but it works... it's so spread out |
| 358 | because I wanted to make sure to be able to look up the individual |
| 359 | constituent values, should anything go wrong --> |
| 360 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
| 361 | <xsl:variable name="my_id" select="@xml:id" as="xs:string"/> |
| 362 | <xsl:variable name="my_morph-seg" as="node()" select="$ann_morphosyntax.xml//tei:seg[substring-after(@corresp,'#') eq $my_id]"/> |
| 363 | <xsl:variable name="my_disamb" select="$my_morph-seg//tei:fs/tei:f[@name eq 'disamb']" as="node()"/> |
| 364 | <xsl:variable name="my_choice-id" select="substring-after($my_disamb//tei:f[@name eq 'choice']/@fVal,'#')" as="xs:string"/> |
| 365 | <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()"/> |
| 366 | <xsl:variable name="chosen-msd" as="xs:string" select="$my_choice-lex/descendant::tei:symbol[@xml:id eq $my_choice-id]/@value"/> |
| 367 | <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/> |
| 368 | <xsl:variable name="preceding-count" select="count($preceding)"/> |
| 369 | <xsl:variable name="outside-preceding-count" as="xs:integer"> |
| 370 | <xsl:choose> |
| 371 | <xsl:when test="self::tei:s or self::tei:p"> |
| 372 | <xsl:choose> |
| 373 | <xsl:when test="$preceding-count"> |
| 374 | <xsl:sequence select=" |
| 375 | sum(for $p in $preceding |
| 376 | return |
| 377 | count($p/descendant::*))"/> |
| 378 | </xsl:when> |
| 379 | <xsl:otherwise> |
| 380 | <xsl:sequence select="0"/> |
| 381 | </xsl:otherwise> |
| 382 | </xsl:choose> |
| 383 | </xsl:when> |
| 384 | <xsl:otherwise> |
| 385 | <xsl:sequence select="0"/> |
| 386 | </xsl:otherwise> |
| 387 | </xsl:choose> |
| 388 | </xsl:variable> |
| 389 | <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count" |
| 390 | as="xs:integer"/> |
| 391 | |
| 392 | <xsl:variable name="start" as="xs:integer"> |
| 393 | <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/> |
| 394 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 395 | </xsl:variable> |
| 396 | <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)"> |
| 397 | </xsl:variable> |
| 398 | <xsl:element name="span" namespace="{$KorAP_namespace}"> |
| 399 | <xsl:attribute name="id" select="'s' || $my_index"/> |
| 400 | <xsl:attribute name="from" select="$start"/> |
| 401 | <xsl:attribute name="to" select="$end"/> |
| 402 | <xsl:attribute name="l" select="f:compute_nesting(.)"/> |
| 403 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 404 | <xsl:attribute name="type" select="'lex'"/> |
| 405 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 406 | <xsl:attribute name="name" select="'lex'"/> |
| 407 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 408 | <xsl:comment select="$my_morph-seg//tei:fs/tei:f[@name eq 'orth']/tei:string"/> |
| 409 | |
| 410 | |
| 411 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 412 | <xsl:attribute name="name" select="'lemma'"/> |
| 413 | <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'base']/tei:string"/> |
| 414 | </xsl:element> |
| 415 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 416 | <xsl:attribute name="name" select="'pos'"/> |
| 417 | <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'ctag']/tei:symbol/@value"/> |
| 418 | </xsl:element> |
| 419 | <xsl:if test="string-length($chosen-msd)"> |
| 420 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 421 | <xsl:attribute name="name" select="'msd'"/> |
| 422 | <xsl:value-of select="$chosen-msd"/> |
| 423 | </xsl:element> |
| 424 | </xsl:if> |
| 425 | <xsl:if test="$my_morph-seg//tei:fs/tei:f[@name eq 'nps']"> |
| 426 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 427 | <xsl:attribute name="name" select="'join'"/> |
| 428 | <xsl:value-of select="'left'"/> |
| 429 | </xsl:element> |
| 430 | </xsl:if> |
| 431 | </xsl:element> |
| 432 | </xsl:element> |
| 433 | </xsl:element> |
| 434 | </xsl:element> |
| 435 | <xsl:apply-templates mode="morpho"> |
| 436 | <xsl:with-param name="ini" select="$start" as="xs:integer"/> |
| 437 | <xsl:with-param name="fin" select="$end" as="xs:integer"/> |
| 438 | <xsl:with-param name="index" select="$my_index"/> |
| 439 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/> |
| 440 | </xsl:apply-templates> |
| 441 | </xsl:template> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 442 | <!-- ************************** TEXT header ******************* --> |
| 443 | |
| 444 | <xsl:template name="create_text_header"> |
| 445 | <xsl:param name="text.xml" as="document-node()"/> |
| 446 | <xsl:param name="target" as="xs:string"/> |
| 447 | |
| 448 | <!-- create the local header.xml file --> |
| 449 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 450 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 451 | |
| 452 | <idsHeader type="document" pattern="text" status="new" version="1.1" TEIform="teiHeader"> |
| 453 | <xsl:apply-templates select="$text.xml//tei:TEI/tei:teiHeader/tei:fileDesc" mode="text"/> |
| 454 | </idsHeader> |
| 455 | </xsl:result-document> |
| 456 | </xsl:template> |
| 457 | |
| 458 | <xsl:template match="tei:fileDesc" mode="text"> |
| 459 | <fileDesc> |
| 460 | <xsl:apply-templates mode="text"/> |
| 461 | </fileDesc> |
| 462 | </xsl:template> |
| 463 | |
| 464 | <xsl:template match="tei:title" mode="text"> |
| 465 | <t.title> |
| 466 | <xsl:apply-templates/> |
| 467 | </t.title> |
| 468 | </xsl:template> |
| 469 | |
| 470 | <xsl:template match="tei:titleStmt" mode="text"> |
| 471 | <titleStmt> |
| 472 | <textSigle> |
| 473 | <xsl:value-of select="$corpusID || '/' || $textID"/> |
| 474 | </textSigle> |
| 475 | <xsl:apply-templates mode="text"/> |
| 476 | </titleStmt> |
| 477 | </xsl:template> |
| 478 | |
| 479 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 480 | <!-- ************************** CORPUS header ******************* --> |
| 481 | <xsl:template name="create_corpus_header"> |
| 482 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 483 | <xsl:param name="target" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 484 | |
| 485 | <!-- create the corpus-level header.xml file --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 486 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" href="{$target}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 487 | |
| 488 | <!--doctype-public="{$publicDoctypeI5}" |
| 489 | doctype-system="{$systemDoctypeI5}"> |
| 490 | these are, sadly, useless |
| 491 | --> |
| 492 | |
| 493 | <idsHeader type="corpus" pattern="text" status="new" version="1.1" TEIform="teiHeader"> |
| 494 | <xsl:apply-templates select="$text.xml//tei:TEI/tei:teiHeader/tei:fileDesc" mode="corpus"/> |
| 495 | </idsHeader> |
| 496 | </xsl:result-document> |
| 497 | </xsl:template> |
| 498 | |
| 499 | <xsl:template match="tei:fileDesc" mode="corpus"> |
| 500 | <fileDesc> |
| 501 | <xsl:apply-templates mode="corpus"/> |
| 502 | </fileDesc> |
| 503 | </xsl:template> |
| 504 | |
| 505 | <xsl:template match="tei:title" mode="corpus"> |
| 506 | <c.title> |
| 507 | <xsl:apply-templates/> |
| 508 | </c.title> |
| 509 | </xsl:template> |
| 510 | |
| 511 | <xsl:template match="tei:titleStmt" mode="corpus"> |
| 512 | <titleStmt> |
| 513 | <korpusSigle> |
| 514 | <xsl:value-of select="$corpusID"/> |
| 515 | </korpusSigle> |
| 516 | <xsl:apply-templates mode="corpus"/> |
| 517 | </titleStmt> |
| 518 | </xsl:template> |
| 519 | |
| 520 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 521 | |
| 522 | |
| 523 | |
| 524 | <!-- this template can be called by the XSPEC test; TODO: find a way to call the main() template directly --> |
| 525 | <!-- I have not fully handled the param transmission, which would have to be kludged in just for the sake of XSPec, |
| 526 | because I'm disabling this for now, due to XSpec design issues; relevant links, a.o.: |
| 527 | |
| 528 | https://stackoverflow.com/questions/64933277/what-is-the-cause-of-error-cannot-execute-xslresult-document-while-evaluating |
| 529 | https://www.balisage.net/Proceedings/vol25/html/Galtman01/BalisageVol25-Galtman01.html |
| 530 | |
| 531 | In short: the internal design of XSpec forces kludges when one wants to use xsl:result-document in their stylesheets. But I don't |
| 532 | want to be strangled by kludges at the beginning of work, I've already lost quite a bit of time on this investigation, |
| 533 | I will therefore "just code" and then can think of externalizing bits of templates if we want to play with tests. For now, |
| 534 | 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. |
| 535 | |
| 536 | --> |
| 537 | <!--<xsl:template name="test_full"> |
| 538 | <xsl:param name="corpusID"/> |
| 539 | <xsl:param name="docID"/> |
| 540 | <xsl:param name="textID"/> |
| 541 | <xsl:call-template name="xsl:initial-template"/> |
| 542 | </xsl:template>--> |
| 543 | |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 544 | </xsl:stylesheet> |