forked from clarin-eric/ParlaMint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparlamint2tbl-meta.xsl
More file actions
145 lines (137 loc) · 5.6 KB
/
parlamint2tbl-meta.xsl
File metadata and controls
145 lines (137 loc) · 5.6 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
<?xml version="1.0"?>
<!-- Make TSV/LaTeX table with overview info on metadata of the ParlaMint corpora -->
<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:output method="text" encoding="utf-8"/>
<!-- What to output the table as -->
<xsl:param name="mode">TeX</xsl:param>
<!-- Mode dependent colon and line separators -->
<xsl:variable name="col-sep">
<xsl:choose>
<xsl:when test="matches($mode, 'tex', 'i')">
<xsl:text>&</xsl:text>
</xsl:when>
<xsl:when test="matches($mode, 'tsv', 'i')">
<xsl:text>	</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="line-sep">
<xsl:choose>
<xsl:when test="matches($mode, 'tex', 'i')">
<xsl:text>\\ </xsl:text>
</xsl:when>
<xsl:when test="matches($mode, 'tsv', 'i')">
<xsl:text> </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:variable>
<!-- If LaTeX -->
<xsl:variable name="preamble">\begin{tabular}{l|rrr|rrrrrrr} </xsl:variable>
<xsl:variable name="header-row">
<xsl:text>ID</xsl:text> <!-- ISO country code -->
<xsl:value-of select="$col-sep"/>
<xsl:text>Prts</xsl:text> <!-- Number of political parties -->
<xsl:value-of select="$col-sep"/>
<xsl:text>C/O</xsl:text> <!-- Number of coalitions + oppositions -->
<xsl:value-of select="$col-sep"/>
<xsl:text>Orgs</xsl:text> <!-- Number of other organistations -->
<xsl:value-of select="$col-sep"/>
<xsl:text>Spkrs</xsl:text> <!-- Number of speakers -->
<xsl:value-of select="$col-sep"/>
<xsl:text>Sex</xsl:text> <!-- Number of speakers with gender -->
<xsl:value-of select="$col-sep"/>
<xsl:text>MP</xsl:text> <!-- Number of MPs -->
<xsl:value-of select="$col-sep"/>
<xsl:text>Affill</xsl:text> <!-- Number of MPs affiliated with political parties -->
<xsl:value-of select="$col-sep"/>
<xsl:text>Birth</xsl:text> <!-- Speakers with birth dates -->
<xsl:value-of select="$col-sep"/>
<xsl:text>URL</xsl:text> <!-- Speakers with one or more URLs (contact, twitter, facebook) -->
<xsl:value-of select="$col-sep"/>
<xsl:text>IMG</xsl:text> <!-- Speakers with images -->
<xsl:value-of select="$line-sep"/>
<xsl:if test="matches($mode, 'tex', 'i')">\hline </xsl:if>
</xsl:variable>
<xsl:key name="ref" match="tei:org" use="concat('#', @xml:id)"/>
<xsl:template match="tei:teiCorpus">
<xsl:choose>
<xsl:when test="matches($mode, 'tex', 'i')">
<xsl:value-of select="$preamble"/>
<xsl:value-of select="$header-row"/>
</xsl:when>
<xsl:when test="matches($mode, 'tsv', 'i')">
<xsl:value-of select="$header-row"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">Parameter 'mode' should be either TSV of TeX.</xsl:message>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="xi:include">
<xsl:apply-templates select="document(@href)/tei:teiCorpus/tei:teiHeader"/>
</xsl:for-each>
<xsl:if test="matches($mode, 'tex', 'i')">
<xsl:text>\end{tabular} </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="tei:teiHeader">
<xsl:value-of select="ancestor::tei:teiCorpus/replace(@xml:id, '.+-', '')"/>
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//
tei:org[@role='politicalParty' or @role='politicalGroup'])"/>
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//
tei:relation[@name='coalition' or @name='opposition'])"/>
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//
tei:org[@role!='politicalParty' and @role!='politicalGroup'])"/>
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//tei:person)"/>
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//tei:person[tei:sex])"/>
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//tei:person[tei:affiliation[@role='MP']])"/>
<xsl:value-of select="$col-sep"/>
<!-- tei:affiliation[@role='MP'] and -->
<xsl:value-of select="et:cnt(.//tei:particDesc//tei:person[
tei:affiliation[(@role='member' or @role='candidateMP') and
key('ref', @ref)[@role='politicalParty' or @role='politicalGroup']]
])"/>
<!-- [tei:affiliation[@role='MP']] -->
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//tei:person
[tei:birth]
)"/>
<!-- [tei:affiliation[@role='MP']] -->
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//tei:person
[tei:idno[@type='URI']]
)"/>
<!-- [tei:affiliation[@role='MP']] -->
<xsl:value-of select="$col-sep"/>
<xsl:value-of select="et:cnt(.//tei:particDesc//tei:person
[tei:figure]
)"/>
<xsl:value-of select="$line-sep"/>
</xsl:template>
<!-- Count nodes and, if LaTeX, give thousands separator -->
<xsl:function name="et:cnt">
<xsl:param name="nodes"/>
<xsl:choose>
<xsl:when test="matches($mode, 'tex', 'i')">
<xsl:value-of select="format-number(count($nodes), '###,###,###')"/>
</xsl:when>
<xsl:when test="matches($mode, 'tsv', 'i')">
<xsl:value-of select="count($nodes)"/>
</xsl:when>
</xsl:choose>
</xsl:function>
</xsl:stylesheet>