Debian Codegraph @

JMdict/jmdict_e2tei.xsl

raw
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
4 xmlns="http://www.tei-c.org/ns/1.0"
5 xmlns:xs="http://www.w3.org/2001/XMLSchema"
6 xmlns:xd="http://www.pnp-software.com/XSLTdoc" exclude-result-prefixes="xs xd">
7 <!-- JMdict_e to Freedict TEI only ! -->
8 <xsl:output
9 method="xml"
10 version="1.0"
11 encoding="UTF-8"
12 indent="yes"
13 doctype-system="freedict-P5.dtd"
14 />
15
16 <xd:doc type="stylesheet">
17 <xd:short>Transformation file to convert the JMdict into TEI P5 Freedict file</xd:short>
18 <xd:detail>
19 <p>The Japanese Multilingual Dictionary (jmdict) is a free xml database by Jim Breens et al.
20 (http://www.edrdg.org/jmdict/j_jmdict.html)</p>
21 <p>This stylesheet aims to convert this multilingual resource into a bilingual Freedict file.
22 JMdict and TEI P5 DTD are quite different, so the xml elements of JMdict have been turned into TEI elements.
23 Following the pretty good JMdict DTD comments, here is how I tried to fit the TEI pattern
24 (http://www.tei-c.org/release/doc/tei-p5-doc/fr/html/DI.html): <list>
25 <item>ant => ref type="ant"</item>
26 <item>dial => usg type="geo"</item>
27 <item>field => usg type="dom"</item>
28 <item>gloss => cit type="trans"/quote</item>
29 <item>k_ele => form type="k_ele"</item>
30 <item>keb => orth</item>
31 <item>ke_inf => lbl type="ke_inf"</item>
32 <item>ke_pri => usg type="pri"</item>
33 <item>lsource => lang</item>
34 <item>misc => note</item>
35 <item>pos => note type="pos"</item>
36 <item>pri => pri</item>
37 <item>reb => orth</item>
38 <item>r_ele => form type="r_ele</item>
39 <item>re_inf => lbl typ="re_inf"</item>
40 <item>re_nokanji => type="re_nokanji"</item>
41 <item>re_pri => usg type="pri"</item>
42 <item>re_restr => lbl type="re_restr"</item>
43 <item>s_inf => note type="sense"</item>
44 <item>stagk => note type="stagk"</item>
45 <item>stagr => note type="stagr"</item>
46 <item>xref => ref</item>
47 </list>
48 </p>
49 </xd:detail>
50 <xd:author>Denis ARNAUD</xd:author>
51 <xd:copyright>the author(s), 2016; license: GPL v3 or any later version
52 (http://www.gnu.org/licenses/gpl.html).</xd:copyright>
53 </xd:doc>
54
55 <!-- template JMdict -->
56 <xsl:template match="JMdict">
57 <TEI xmlns="http://www.tei-c.org/ns/1.0" version="5.0">
58 <text><body><xsl:text>&#xa;</xsl:text>
59 <xsl:for-each select="entry">
60 <entry xml:id='a{ent_seq}'>
61 <xsl:apply-templates select="k_ele"/>
62 <xsl:apply-templates select="r_ele"/>
63 <xsl:apply-templates select="info"/>
64 <xsl:apply-templates select="sense"/>
65 </entry><xsl:text>&#xa;</xsl:text>
66 </xsl:for-each>
67 </body>
68 </text></TEI>
69 </xsl:template>
70
71 <!--template K_ELE -->
72 <xsl:template match="k_ele"><form type="k_ele"><xsl:apply-templates/></form><xsl:text>&#xa;</xsl:text></xsl:template>
73
74 <!--template R_ELE -->
75 <xsl:template match="r_ele"><form type="r_ele"><xsl:apply-templates/></form></xsl:template>
76
77 <!--template SENSE -->
78 <xsl:template match="sense">
79 <sense><xsl:apply-templates/></sense>
80 </xsl:template>
81
82 <!--template POS -->
83 <xsl:template match="pos"><note type="pos"><xsl:value-of select="."/></note></xsl:template>
84
85 <!--template XREF -->
86 <xsl:template match="xref">
87 <ref><xsl:value-of select="."/></ref>
88 </xsl:template>
89
90 <!--template ANT -->
91 <xsl:template match="ant">
92 <ref type="ant"><xsl:value-of select="."/></ref>
93 </xsl:template>
94
95 <!--template GLOSS -->
96 <xsl:template match="gloss">
97 <xsl:element name="cit">
98 <xsl:attribute name="type">
99 <xsl:text>trans</xsl:text>
100 </xsl:attribute>
101 <quote><xsl:apply-templates/></quote>
102 <xsl:if test="@g_gend">
103 <xsl:element name="gen"><xsl:value-of select="@g_gend" /></xsl:element>
104 </xsl:if>
105 </xsl:element>
106 </xsl:template>
107
108 <!--template RE_NOKANJI -->
109 <xsl:template match="re_nokanji"><lbl type="re_nokanji"><xsl:value-of select="."/></lbl></xsl:template>
110
111 <!--template RE_PRI -->
112 <xsl:template match="re_pri"><usg type="re_pri"><xsl:value-of select="."/></usg></xsl:template>
113
114 <!--template RE_INF -->
115 <xsl:template match="re_inf"><lbl type="re_inf"><xsl:value-of select="."/></lbl></xsl:template>
116
117 <!--template RE_RESTR -->
118 <xsl:template match="re_restr"><lbl type="re_restr"><xsl:value-of select="."/></lbl></xsl:template>
119
120 <!--template KE_INF -->
121 <xsl:template match="ke_inf"><lbl type="ke_inf"><xsl:value-of select="."/></lbl></xsl:template>
122 <!--template KE_PRI -->
123 <xsl:template match="ke_pri"><usg type="pri"><xsl:value-of select="."/></usg></xsl:template>
124 <!--template KEB -->
125 <xsl:template match="keb"><orth><xsl:value-of select="."/></orth></xsl:template>
126 <!--template REB -->
127 <xsl:template match="reb"><orth><xsl:value-of select="."/></orth></xsl:template>
128 <!--template STAGK -->
129 <xsl:template match="stagk"><note type="stagk"><xsl:value-of select="."/></note></xsl:template>
130 <!--template STAGR -->
131 <xsl:template match="stagr"><note type="stagr"><xsl:value-of select="."/></note></xsl:template>
132 <!--template FIELD -->
133 <xsl:template match="field"><usg type="dom"><xsl:value-of select="."/></usg></xsl:template>
134 <!--template MISC -->
135 <xsl:template match="misc"><note><xsl:value-of select="."/></note></xsl:template>
136 <!--template DIAL -->
137 <xsl:template match="dial"><usg type="geo"><xsl:value-of select="."/></usg></xsl:template>
138 <!--template PRI -->
139 <xsl:template match="pri"><pri><xsl:value-of select="."/></pri></xsl:template>
140 <!--template S_INF -->
141 <xsl:template match="s_inf"><note type="sense"><xsl:value-of select="."/></note></xsl:template>
142
143 <!--template LSOURCE -->
144 <xsl:template match="lsource">
145 <xsl:element name="lang">
146 <xsl:if test="@xml:lang">
147 <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang" /></xsl:attribute>
148 </xsl:if>
149 <xsl:if test="@ls_type">
150 <xsl:attribute name="split"><xsl:value-of select="@ls_type" /></xsl:attribute>
151 </xsl:if>
152 <xsl:if test="@ls_wasei">
153 <xsl:attribute name="orig">ls_wasei</xsl:attribute>
154 </xsl:if>
155 <xsl:apply-templates/>
156 </xsl:element>
157 </xsl:template>
158
159 <!--Divers caractères : — - ― • ◊ ● ○ ♦ -->
160 </xsl:stylesheet>