forked from clarin-eric/ParlaMint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparlamint2meta.xsl
More file actions
203 lines (195 loc) · 7.29 KB
/
parlamint2meta.xsl
File metadata and controls
203 lines (195 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?xml version="1.0"?>
<!-- Transform one ParlaMint file to a TSV file with its metadata. -->
<!-- Includes header row, cf. template for tei:TEI -->
<!-- Needs the file with corpus teiHeader giving the speaker, party etc. info as the "hdr" parameter -->
<!-- Imports the script for vertical file generation, as they share much code -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:et="http://nl.ijs.si/et"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xi="http://www.w3.org/2001/XInclude"
exclude-result-prefixes="fn et tei xs xi"
version="2.0">
<xsl:import href="parlamint2xmlvert.xsl"/>
<xsl:output method="text" encoding="utf-8"/>
<!-- Store sub title, if it exists, otherwise main title -->
<xsl:variable name="title">
<xsl:variable name="titles" select="/tei:TEI/tei:teiHeader/tei:fileDesc/
tei:titleStmt/tei:title"/>
<xsl:choose>
<xsl:when test="$titles[@type='sub']
[ancestor-or-self::tei:*[@xml:lang][1][@xml:lang='en']]">
<xsl:value-of select="$titles[@type='sub']
[ancestor-or-self::tei:*[@xml:lang][1][@xml:lang='en']]
[1]"/>
</xsl:when>
<xsl:when test="$titles[@type='sub']">
<xsl:value-of select="$titles[@type='sub'][1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$titles[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Typically $date-from and $date-to are identical, but not necessarily -->
<xsl:variable name="date-from">
<xsl:variable name="d" select="/tei:TEI/tei:teiHeader//tei:settingDesc//tei:date"/>
<xsl:choose>
<xsl:when test="$d/@when">
<xsl:value-of select="$d/@when"/>
</xsl:when>
<xsl:when test="$d/@from">
<xsl:value-of select="$d/@from"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
<xsl:text>FATAL: Can't find TEI date-from in settingDesc of input file </xsl:text>
<xsl:value-of select="/tei:TEI/@xml:id"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="date-to">
<xsl:variable name="d" select="/tei:TEI/tei:teiHeader//tei:settingDesc//tei:date"/>
<xsl:choose>
<xsl:when test="$d/@when">
<xsl:value-of select="$d/@when"/>
</xsl:when>
<xsl:when test="$d/@to">
<xsl:value-of select="$d/@to"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
<xsl:text>FATAL: Can't find TEI date-to in settingDesc of input file </xsl:text>
<xsl:value-of select="/tei:TEI/@xml:id"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- House, term, session, meeting, sitting, agenda -->
<xsl:variable name="house">
<xsl:call-template name="house"/>
</xsl:variable>
<xsl:variable name="term">
<xsl:call-template name="meeting">
<xsl:with-param name="ref">parla.term</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="session">
<xsl:call-template name="meeting">
<xsl:with-param name="ref">parla.session</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="meeting">
<xsl:call-template name="meeting">
<xsl:with-param name="ref">parla.meeting</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="sitting">
<xsl:call-template name="meeting">
<xsl:with-param name="ref">parla.sitting</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="agenda">
<xsl:call-template name="meeting">
<xsl:with-param name="ref">parla.agenda</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<!-- COVID / reference subcorpus -->
<xsl:variable name="subcorpus">
<xsl:for-each select="tokenize(tei:TEI/@ana, ' ')">
<xsl:if test="key('idr', ., $teiHeader)/
ancestor::tei:taxonomy/tei:desc/tei:term = 'Subcorpora'">
<xsl:value-of select="key('idr', ., $teiHeader)//tei:catDesc
[ancestor-or-self::tei:*[@xml:lang][1][@xml:lang='en']]
/tei:term"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:template match="tei:TEI">
<xsl:text>ID	</xsl:text>
<xsl:text>Title	</xsl:text>
<xsl:text>From	</xsl:text>
<xsl:text>To	</xsl:text>
<xsl:text>House	</xsl:text>
<xsl:text>Term	</xsl:text>
<xsl:text>Session	</xsl:text>
<xsl:text>Meeting	</xsl:text>
<xsl:text>Sitting	</xsl:text>
<xsl:text>Agenda	</xsl:text>
<xsl:text>Subcorpus	</xsl:text>
<xsl:text>Speaker_role	</xsl:text>
<xsl:text>Speaker_type	</xsl:text>
<xsl:text>Speaker_party	</xsl:text>
<xsl:text>Speaker_party_name	</xsl:text>
<xsl:text>Party_status	</xsl:text>
<xsl:text>Speaker_name	</xsl:text>
<xsl:text>Speaker_gender	</xsl:text>
<xsl:text>Speaker_birth</xsl:text>
<!--xsl:text>Tokens</xsl:text-->
<xsl:text> </xsl:text>
<xsl:apply-templates select=".//tei:u"/>
</xsl:template>
<xsl:template match="tei:u">
<!-- Text metadata -->
<xsl:value-of select="concat(@xml:id, '	')"/>
<xsl:value-of select="concat($title, '	')"/>
<xsl:value-of select="concat($date-from, '	')"/>
<xsl:value-of select="concat($date-to, '	')"/>
<xsl:value-of select="concat($house, '	')"/>
<xsl:value-of select="concat($term, '	')"/>
<xsl:value-of select="concat($session, '	')"/>
<xsl:value-of select="concat($meeting, '	')"/>
<xsl:value-of select="concat($sitting, '	')"/>
<xsl:value-of select="concat($agenda, '	')"/>
<xsl:value-of select="concat($subcorpus, '	')"/>
<!-- Speaker metadata -->
<xsl:value-of select="concat(et:u-role(@ana), '	')"/>
<xsl:choose>
<xsl:when test="not(@who)">
<xsl:text>-	</xsl:text>
<xsl:text>-	</xsl:text>
<xsl:text>-	</xsl:text>
<xsl:text>-	</xsl:text>
<xsl:text>-	</xsl:text>
<xsl:text>-	</xsl:text>
<xsl:text>-</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="speaker" select="key('idr', @who, $teiHeader)"/>
<xsl:if test="not(normalize-space($speaker))">
<xsl:message terminate="yes">
<xsl:text>FATAL: Can't find speaker for </xsl:text>
<xsl:value-of select="@who"/>
<xsl:text> in </xsl:text>
<xsl:value-of select="@xml:id"/>
</xsl:message>
</xsl:if>
<xsl:value-of select="concat(et:speaker-type($speaker), '	')"/>
<xsl:value-of select="concat(et:speaker-party($speaker, 'init'), '	')"/>
<xsl:value-of select="concat(et:speaker-party($speaker, 'yes'), '	')"/>
<xsl:value-of select="concat(et:party-status($speaker), '	')"/>
<xsl:value-of select="concat(et:format-name($speaker//tei:persName[1]), '	')"/>
<xsl:choose>
<xsl:when test="$speaker/tei:sex">
<xsl:value-of select="$speaker/tei:sex/@value"/>
</xsl:when>
<xsl:otherwise>-</xsl:otherwise>
</xsl:choose>
<xsl:text>	</xsl:text>
<xsl:choose>
<xsl:when test="$speaker/tei:birth">
<xsl:value-of select="replace($speaker/tei:birth/@when, '-.+', '')"/>
</xsl:when>
<xsl:otherwise>-</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<!-- Speech sizes -->
<!--xsl:value-of select="count(.//tei:w) + count(.//tei:pc)"/-->
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>