Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / concordance_simple.xsl @ 187

History | View | Annotate | Download (7.2 kB)

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
3
								xmlns:exsl="http://exslt.org/common">
4
	<!-- Revised 8 Feb 2012 by TMR -->
5
	
6
	<!-- Delimiter is tab. written as &#09; -->
7

    
8
	<xsl:output method="text" encoding="UTF-8" indent="no" />
9

    
10
	<xsl:param name="cx" select="15"/>
11
	<!-- vary this value to change the size of the context -->
12
	
13
	<xsl:param name="ntTypes"></xsl:param>
14
	<!-- non-terminal pivot features to show -->
15
		
16
	<xsl:param name="tTypes" >pos form</xsl:param>
17
	<!-- terminal pivot features to show -->
18
				
19
	<xsl:key name="idkey" match="t|nt" use="@id"/>
20
	<!-- Lezius' lookup key -->
21

    
22
	<xsl:template match="/">
23
		
24
		<xsl:variable name="valueshownt" ><xsl:value-of select="$ntTypes" /></xsl:variable>
25
		
26
		<xsl:variable name="valueshowt" ><xsl:value-of select="$tTypes" /></xsl:variable>
27
		
28
		<!--Write a header-->
29
				
30
		<xsl:text>ID&#x09;LeftCxOutsideSnt&#x09;LeftCxInsideSnt&#x09;Pivot&#x09;</xsl:text>
31
		
32
		<xsl:for-each select="tokenize($valueshownt/node(), '\s+')">
33
			
34
			<xsl:value-of select="." /><xsl:text>&#x09;</xsl:text>
35
			
36
		</xsl:for-each>
37
		
38
		<xsl:for-each select="tokenize($valueshowt/node(), '\s+')">
39
			
40
			<xsl:value-of select="." /><xsl:text>&#x09;</xsl:text>
41
			
42
		</xsl:for-each>
43
		
44
		<xsl:text>RightCxInsideSnt&#x09;RightCxOutsideSnt&#x0D;&#x0A;</xsl:text>
45
	
46
		<xsl:for-each select="descendant::variable[@name='#pivot']">
47
			
48
			<!-- Each #pivot node in the document is selected -->
49

    
50
			<xsl:variable name="inpivot">
51

    
52
				<pivot>
53
					<xsl:apply-templates select="key('idkey', @idref)" mode="get-terminals" />
54
				</pivot>
55

    
56
			</xsl:variable>
57

    
58
			<xsl:variable name="inpivot-sort">
59
				<pivot>
60
					<xsl:for-each select="exsl:node-set($inpivot)//t">
61
						<xsl:sort select="@id" />
62
						<xsl:copy-of select="." />
63
					</xsl:for-each>
64
				</pivot>
65
			</xsl:variable>
66

    
67
			<xsl:variable name="firstpivotid">
68

    
69
				<xsl:apply-templates select="exsl:node-set($inpivot-sort)//t[1]" mode="id" />
70
					
71
			</xsl:variable>
72

    
73
			<xsl:variable name="lastpivotid">
74

    
75
				<xsl:apply-templates select="exsl:node-set($inpivot-sort)//t[last()]" mode="id" />
76

    
77
			</xsl:variable>
78

    
79
			<!-- sentence ID -->
80

    
81
			<xsl:apply-templates select="ancestor::s" mode="id" />			
82
			<xsl:text>&#x09;</xsl:text>
83

    
84
			<!-- left context -->
85

    
86
			<xsl:apply-templates select="key('idkey', $firstpivotid)" mode="left-cx" /><xsl:text>&#x09;</xsl:text>
87

    
88
			<!-- pivot text -->
89

    
90
			<xsl:apply-templates select="ancestor::s" mode="pivot">
91
				<xsl:with-param name="inpivot" select="exsl:node-set($inpivot-sort)" />
92
			</xsl:apply-templates><xsl:text>&#x09;</xsl:text>
93
			
94
			<!-- pivot properties -->
95
			
96
			<xsl:variable name="thispivot" select="key('idkey', @idref)" />
97
			
98
			<xsl:for-each select="tokenize($valueshownt/node(), '\s+')">
99
				
100
				<xsl:variable name="attr" select="."/>
101
				
102
				<xsl:value-of select="$thispivot/@*[name()=$attr]"/><xsl:text>&#x09;</xsl:text>
103
				
104
			</xsl:for-each>
105
			<xsl:for-each select="tokenize($valueshowt/node(), '\s+')">
106
				
107
				<xsl:variable name="attr" select="."/>
108
				
109
				<xsl:value-of select="$thispivot/@*[name()=$attr]"/><xsl:text>&#x09;</xsl:text>
110
				
111
			</xsl:for-each>
112
				
113
			<!-- right context -->
114
			<xsl:apply-templates select="key('idkey', $lastpivotid)" mode="right-cx" /><xsl:text>&#x0D;&#x0A;</xsl:text>
115

    
116
		</xsl:for-each>
117

    
118
	</xsl:template>
119

    
120
	<xsl:template match="t" mode="get-terminals">
121

    
122
		<xsl:copy-of select="." />
123

    
124
	</xsl:template>
125

    
126
	<xsl:template match="t" mode="left-cx">
127
		
128
		<xsl:variable name="pivot-node" select="." />
129
		<xsl:variable name="this-sid"><xsl:value-of select="ancestor::s/@id" /></xsl:variable>
130
		
131
		<xsl:for-each select="preceding::t[position() &lt; number($cx)]" >
132
			<!-- xsl:sort select="@id" / -->
133
			<xsl:choose>
134
				<!-- switch from out-of-sentence to in-sentence context -->
135
				<xsl:when test="ancestor::s[@id = $this-sid] and not(preceding-sibling::t)">
136
					<xsl:text>&#x09;</xsl:text>
137
				</xsl:when>
138
				
139
				<!-- first word of the context and in the same sentence -->
140
				
141
				<xsl:when test="position() = 1 and ancestor::s[@id=$this-sid]"><xsl:text>&#x09;</xsl:text></xsl:when>
142
				
143
				<!-- first word of the context -->
144
				
145
				<xsl:when test="position() = 1" />
146
				
147
				<!-- first word in a sentence -->
148
				<xsl:when test="not(preceding-sibling::t)"><xsl:text> / </xsl:text></xsl:when>
149
				
150
				<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
151
				
152
			</xsl:choose>
153
			
154
			<xsl:apply-templates select="." mode="output" />
155
			
156
			<!-- add blank column if there's no in-sentence context -->
157
			<xsl:if test="position() = last() and ancestor::s[@id != $this-sid]"><xsl:text>&#x09;</xsl:text></xsl:if>
158
			
159
		</xsl:for-each>
160
		
161
	</xsl:template>
162
	
163
	<xsl:template match="t" mode="right-cx">
164
		
165
		<xsl:variable name="pivot-node" select="." />
166
		<xsl:variable name="this-sid"><xsl:value-of select="ancestor::s/@id" /></xsl:variable>
167
		
168
		<xsl:for-each select="following::t[position() &lt; number($cx)]" >
169
			<!-- xsl:sort select="@id" / -->
170
			<xsl:choose>
171
				<!-- switch from in-sentence to out-of-sentence context -->
172
				<xsl:when test="ancestor::s[@id != $this-sid] and preceding::t[position()=1]/ancestor::s[@id = $this-sid]">
173
					<xsl:text>&#x09;</xsl:text>
174
				</xsl:when>
175
				
176
				<!-- first word of the context -->
177
				
178
				<xsl:when test="position() = 1" />
179
				
180
				<!-- first word in a sentence -->
181
				<xsl:when test="not(preceding-sibling::t)"><xsl:text> / </xsl:text></xsl:when>
182
				
183
				<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
184
				
185
			</xsl:choose>
186
			<xsl:apply-templates select="." mode="output" />
187
			<!-- add blank column if there's no out-of-sentence context -->
188
			<xsl:if test="position() = last() and ancestor::s[@id = $this-sid]"><xsl:text>&#x09;</xsl:text></xsl:if>
189
			
190
		</xsl:for-each>
191
		
192
	</xsl:template>
193

    
194
	<xsl:template match="s" mode="pivot">
195
		<xsl:param name="inpivot" />
196

    
197
			<xsl:variable name="firstpivotid">
198

    
199
				<xsl:apply-templates select="$inpivot//t[1]" mode="id" />
200
					
201
			</xsl:variable>
202

    
203
			<xsl:variable name="lastpivotid">
204
				<xsl:apply-templates select="$inpivot//t[last()]" mode="id" />
205

    
206
			</xsl:variable>
207

    
208
		<xsl:for-each select="descendant::t" >
209
			<xsl:variable name="thisid" select = "@id" />
210
			<xsl:choose>
211
				<xsl:when test="following-sibling::t[@id=$firstpivotid]" />
212
				<xsl:when test="preceding-sibling::t[@id=$lastpivotid]" />
213
				<xsl:when test="$inpivot//t[@id=$thisid]"><xsl:apply-templates select="." mode="output" /><xsl:text> </xsl:text></xsl:when>
214
				<xsl:otherwise>[<xsl:apply-templates select="." mode="output" />]<xsl:text> </xsl:text></xsl:otherwise>
215
			</xsl:choose>			
216
		</xsl:for-each>
217

    
218
	</xsl:template>
219

    
220
	<xsl:template match="t" mode="output">
221
		
222
		<xsl:value-of select="@word" />
223

    
224
	</xsl:template>
225

    
226
	<xsl:template match="nt|t|s" mode="id">
227
		
228
		<xsl:value-of select="@id" />
229

    
230
	</xsl:template>
231

    
232
	<xsl:template match="nt" mode="get-terminals">
233

    
234
		<xsl:for-each select="edge">
235

    
236
			<xsl:apply-templates select="key('idkey', @idref)" mode="get-terminals" />
237
	
238
		</xsl:for-each>
239

    
240
	</xsl:template>
241

    
242
</xsl:stylesheet>
243