root / tmp / org.txm.oriflamms.rcp / bin / oriflamms-tokenize-words.xsl @ 476
History | View | Annotate | Download (8.5 kB)
1 |
<?xml version="1.0"?> |
---|---|
2 |
<xsl:stylesheet xmlns:edate="http://exslt.org/dates-and-times" |
3 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0" |
4 |
xmlns:xd="http://www.pnp-software.com/XSLTdoc" |
5 |
xmlns:txm="http://textometrie.org/1.0" |
6 |
exclude-result-prefixes="tei edate xd txm" version="2.0"> |
7 |
|
8 |
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="no"/> |
9 |
|
10 |
<xd:doc type="stylesheet"> |
11 |
<xd:short> |
12 |
Cette feuille XSLT permet de pré-tokeniser par mot des fichiers au format |
13 |
XML-TEI Oriflamms brut |
14 |
</xd:short> |
15 |
<xd:detail> |
16 |
This stylesheet is free software; you can redistribute it and/or |
17 |
modify it under the terms of the GNU Lesser General Public |
18 |
License as published by the Free Software Foundation; either |
19 |
version 3 of the License, or (at your option) any later version. |
20 |
|
21 |
This stylesheet is distributed in the hope that it will be useful, |
22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
24 |
Lesser General Public License for more details. |
25 |
|
26 |
You should have received a copy of GNU Lesser Public License with |
27 |
this stylesheet. If not, see http://www.gnu.org/licenses/lgpl.html |
28 |
</xd:detail> |
29 |
<xd:author>Alexei Lavrentiev alexei.lavrentev@ens-lyon.fr</xd:author> |
30 |
<xd:copyright>2014, CNRS / ICAR (Équipe CACTUS)</xd:copyright> |
31 |
</xd:doc> |
32 |
|
33 |
<!-- <xsl:template match="/"> |
34 |
<xsl:apply-templates/> |
35 |
</xsl:template> |
36 |
--> |
37 |
|
38 |
<xsl:template match="*"> |
39 |
<xsl:copy> |
40 |
<xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()"/> |
41 |
</xsl:copy> |
42 |
</xsl:template> |
43 |
|
44 |
<xsl:template match="comment()|processing-instruction()|text()"> |
45 |
<xsl:copy/> |
46 |
</xsl:template> |
47 |
|
48 |
<!-- On supprime les attributs par défaut de la DTD TEI --> |
49 |
|
50 |
<xsl:template match="@*"> |
51 |
<xsl:choose> |
52 |
<xsl:when test="matches(name(.),'^(part|instant|anchored|full)$')"/> |
53 |
<xsl:otherwise><xsl:copy/></xsl:otherwise> |
54 |
</xsl:choose> |
55 |
</xsl:template> |
56 |
|
57 |
<!-- on on ajoute l'info sur la tokenisation par TXM dans le header --> |
58 |
|
59 |
<xsl:template match="/*/tei:teiHeader/tei:fileDesc/tei:titleStmt"> |
60 |
<xsl:copy> |
61 |
<xsl:apply-templates select="@*|node()"/> |
62 |
<respStmt xmlns="http://www.tei-c.org/ns/1.0"> |
63 |
<resp xmlns="http://www.tei-c.org/ns/1.0">Tokénisation des mots et/ou des caractères</resp> |
64 |
<name xmlns="http://www.tei-c.org/ns/1.0" xml:id="TXM">Logiciel TXM (http://textometrie.ens-lyon.fr)</name> |
65 |
</respStmt> |
66 |
</xsl:copy> |
67 |
</xsl:template> |
68 |
|
69 |
|
70 |
<xsl:template match="/*/tei:teiHeader"> |
71 |
<xsl:copy> |
72 |
<xsl:apply-templates select="@*|node()"/> |
73 |
<xsl:if test="not(tei:revisionDesc)"> |
74 |
<revisionDesc xmlns="http://www.tei-c.org/ns/1.0"> |
75 |
<xsl:call-template name="change-txm"></xsl:call-template> |
76 |
</revisionDesc> |
77 |
</xsl:if> |
78 |
</xsl:copy> |
79 |
</xsl:template> |
80 |
|
81 |
<xsl:template match="/*/tei:teiHeader//tei:revisionDesc"> |
82 |
<xsl:copy> |
83 |
<xsl:apply-templates select="@*|node()"/> |
84 |
<xsl:call-template name="change-txm"/> |
85 |
</xsl:copy> |
86 |
</xsl:template> |
87 |
|
88 |
<xsl:template name="change-txm"> |
89 |
<change when="{format-date(current-date(),'[Y]-[M01]-[D01]')}" who="#TXM" xmlns="http://www.tei-c.org/ns/1.0">Tokenisation des mots</change> |
90 |
</xsl:template> |
91 |
|
92 |
<xsl:template match="tei:w|tei:pc"> |
93 |
<xsl:copy-of select="."/> |
94 |
</xsl:template> |
95 |
|
96 |
<xsl:template match="tei:text//text()"> |
97 |
<xsl:choose> |
98 |
<!--<xsl:when test="not(ancestor::tei:text/tei:body/tei:div1/tei:p)"><xsl:copy/></xsl:when>--> |
99 |
<xsl:when test="matches(.,'^\s*$')"><xsl:copy/></xsl:when> |
100 |
<xsl:when test="matches(local-name(parent::*),'^(abbr|expan|sic|corr)$')"><xsl:copy/></xsl:when> |
101 |
<xsl:when test="ancestor::*/@ana[contains(.,'ori:align-no')]"><xsl:copy/></xsl:when> |
102 |
<xsl:when test="ancestor::tei:note"><xsl:copy/></xsl:when> |
103 |
<xsl:when test="ancestor::tei:witDetail"><xsl:copy/></xsl:when> |
104 |
<xsl:when test="parent::tei:hi and matches(.,'\w+') and not(matches(.,'\s')) and not(preceding-sibling::* or following-sibling::*)"><xsl:copy/></xsl:when> |
105 |
<xsl:when test="parent::tei:am|parent::tei:ex"><xsl:copy/></xsl:when> |
106 |
<!--<xsl:when test="parent::tei:rdg[not(matches(@wit,'^#?A'))]"><xsl:copy/></xsl:when>--> |
107 |
<xsl:when test="ancestor::tei:pc|ancestor::tei:w"><xsl:copy/></xsl:when> |
108 |
<xsl:otherwise> |
109 |
<xsl:analyze-string select="." regex="\w+|\p{{P}}+|\s+"> |
110 |
<xsl:matching-substring> |
111 |
<xsl:choose> |
112 |
<xsl:when test="matches(.,'^\w+$')"><w xmlns="http://www.tei-c.org/ns/1.0"><xsl:value-of select="."/></w></xsl:when> |
113 |
<!-- <xsl:when test="matches(.,'^\p{P}+$')"><orig xmlns="http://www.tei-c.org/ns/1.0"><pc xmlns="http://www.tei-c.org/ns/1.0"><xsl:value-of select="."/></pc></orig></xsl:when>--> |
114 |
<xsl:when test="matches(.,'^\p{P}+$')"><pc xmlns="http://www.tei-c.org/ns/1.0"><xsl:value-of select="."/></pc></xsl:when> |
115 |
<xsl:otherwise><xsl:copy/></xsl:otherwise> |
116 |
</xsl:choose> |
117 |
</xsl:matching-substring> |
118 |
<xsl:non-matching-substring> |
119 |
<xsl:comment>Type de caractère non reconnu</xsl:comment><xsl:copy/> |
120 |
</xsl:non-matching-substring> |
121 |
</xsl:analyze-string> |
122 |
</xsl:otherwise> |
123 |
</xsl:choose> |
124 |
</xsl:template> |
125 |
|
126 |
<xsl:template match="tei:choice"> |
127 |
<xsl:choose> |
128 |
<xsl:when test="descendant::tei:pc"> |
129 |
<pc xmlns="http://www.tei-c.org/ns/1.0"> |
130 |
<xsl:apply-templates select="descendant::tei:pc[1]/@*"/> |
131 |
<xsl:copy> |
132 |
<xsl:apply-templates/> |
133 |
</xsl:copy> |
134 |
</pc> |
135 |
</xsl:when> |
136 |
<xsl:when test="descendant::tei:w"> |
137 |
<xsl:copy> |
138 |
<xsl:apply-templates select="@*"/> |
139 |
<xsl:apply-templates/> |
140 |
</xsl:copy> |
141 |
</xsl:when> |
142 |
<xsl:when test="ancestor::tei:pc|ancestor::tei:w"> |
143 |
<xsl:copy-of select="."/> |
144 |
</xsl:when> |
145 |
<xsl:otherwise><w xmlns="http://www.tei-c.org/ns/1.0"><xsl:copy-of select="."/></w></xsl:otherwise> |
146 |
</xsl:choose> |
147 |
</xsl:template> |
148 |
|
149 |
|
150 |
|
151 |
<!-- <xsl:template match="tei:pc[ancestor::tei:choice]"> |
152 |
<xsl:apply-templates/> |
153 |
</xsl:template> |
154 |
--> |
155 |
|
156 |
<xsl:template match="tei:choice/tei:orig[child::tei:pc]|tei:choice/tei:reg[child::tei:pc]"> |
157 |
<xsl:copy> |
158 |
<xsl:apply-templates select="@*"/> |
159 |
<xsl:value-of select="normalize-space(.)"/> |
160 |
</xsl:copy> |
161 |
</xsl:template> |
162 |
|
163 |
|
164 |
<!-- <xsl:template match="tei:hi[matches(.,'\w+') and not(matches(.,'\s')) and not(descendant::tei:w) and not(ancestor::*/@ana[contains(.,'ori:align-no')])]|tei:am|tei:ex"> --> |
165 |
|
166 |
<!--<xsl:template match="*[ancestor::tei:text and descendant::text()[matches(.,'\w')] and not(descendant::text()[matches(.,'\S\s|\s\S|\p{P}')])]">--> |
167 |
|
168 |
|
169 |
<xsl:template match="*[matches(.,'\w+') |
170 |
and ancestor::tei:text |
171 |
and not(matches(local-name(),'^(front|body|back|div.*|head|closer|p|ab|lg|l|.*[Nn]ame|num|cell|row|q|w|pc|title|term|emph|note|witDetail|foreign|ref|app|lem|rdg)$')) |
172 |
and not(matches(local-name(parent::*),'^(choice|subst|app)$')) |
173 |
and not(descendant::text()[matches(.,'\S\s|\s\S|\p{P}')]) |
174 |
and not(descendant::tei:w or descendant::tei:pc) |
175 |
and not(ancestor::*/@ana[contains(.,'ori:align-no')])]|tei:am|tei:ex"> |
176 |
<w xmlns="http://www.tei-c.org/ns/1.0"><xsl:copy-of select="."/></w> |
177 |
</xsl:template> |
178 |
|
179 |
<!-- <xsl:template match="*[matches(local-name(),'[Nn]ame$') and not(descendant::text()[matches(.,'\S\s|\s\S|\p{P}')])]"> --> |
180 |
|
181 |
|
182 |
<xsl:template match="*[matches(local-name(),'^.*[Nn]ame$') |
183 |
and ancestor::tei:text |
184 |
and not(descendant::*[matches(local-name(),'^(.*[Nn]ame|w|pc|num|term|ref)$')]) |
185 |
and not(descendant::text()[matches(.,'\S\s|\s\S|\p{P}')])]"> |
186 |
<xsl:copy> |
187 |
<xsl:apply-templates select="@*"/> |
188 |
<!-- <xsl:for-each select="child::text()"> |
189 |
<xsl:value-of select="concat('[',.,']')"/> |
190 |
</xsl:for-each>--> |
191 |
<w xmlns="http://www.tei-c.org/ns/1.0"> |
192 |
<xsl:for-each select="child::node()"> |
193 |
<xsl:copy-of select="."/> |
194 |
</xsl:for-each> |
195 |
</w> |
196 |
</xsl:copy> |
197 |
|
198 |
</xsl:template> |
199 |
|
200 |
|
201 |
<!--<xsl:template match="tei:sic[not(parent::tei:choice or descendant::tei:w or ancestor::*/@ana[contains(.,'ori:align-no')])]|tei:corr[not(parent::tei:choice or descendant::tei:w or ancestor::*/@ana[contains(.,'ori:align-no')])]"> |
202 |
<w xmlns="http://www.tei-c.org/ns/1.0"><xsl:copy-of select="."/></w> |
203 |
</xsl:template>--> |
204 |
|
205 |
</xsl:stylesheet> |