]> matita.cs.unibo.it Git - helm.git/blob - helm/style/style_prima_del_linguaggio_naturale/params.xsl
Added style before natural language synthesis
[helm.git] / helm / style / style_prima_del_linguaggio_naturale / params.xsl
1 <?xml version="1.0"?>
2
3 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4                               xmlns:m="http://www.w3.org/1998/Math/MathML">
5
6 <!--***********************************************************************--> 
7 <!-- auxiliary functions                                                   -->
8 <!-- HELM Group: Asperti, Padovani, Sacerdoti, Schena                      -->
9 <!--***********************************************************************--> 
10
11 <!--***********************************************************************-->
12 <!-- get the name from a URI                                               -->
13 <!--***********************************************************************-->
14
15 <!-- CSC: PROBLEMA: URI CHE NON CONTENGONO / ED INIZIANO CON cic: -->
16 <xsl:template name="name_of_uri">
17  <xsl:param name="uri" select="&quot;&quot;"/>
18  <xsl:variable name="suffix" select="substring-after($uri, &quot;/&quot;)"/>
19  <xsl:choose>
20   <xsl:when test="$suffix = &quot;&quot;">
21    <!-- CSC: PROBLEMA: .con PUO' APPARIRE ALL'INTERNO DELLE URI ===>
22      SCRIVERE UNA FUNZIONE RICORSIVA CHE RISOLVA -->
23    <xsl:value-of select="substring-before($uri,&quot;.con&quot;)"/>
24   </xsl:when>
25   <xsl:otherwise>
26    <xsl:call-template name="name_of_uri">
27     <xsl:with-param name="uri" select="$suffix"/>
28    </xsl:call-template>
29   </xsl:otherwise>
30  </xsl:choose>
31 </xsl:template>
32
33 <!--***********************************************************************-->
34 <!-- erase common prefix from two uris                                     -->
35 <!--***********************************************************************-->
36
37 <xsl:template name="common_prefix">
38  <xsl:param name="first_uri" select="&quot;&quot;"/>
39  <xsl:param name="second_uri" select="&quot;&quot;"/>
40  <xsl:choose>
41   <xsl:when test="(substring-before($first_uri,&quot;/&quot;) = 
42                 substring-before($second_uri,&quot;/&quot;) and 
43                 substring-after($second_uri,&quot;/&quot;) != &quot;&quot;)">
44    <xsl:call-template name="common_prefix">
45     <xsl:with-param 
46         name="first_uri" select="substring-after($first_uri,&quot;/&quot;)"/>
47     <xsl:with-param 
48         name="second_uri" select="substring-after($second_uri,&quot;/&quot;)"/>    </xsl:call-template>
49   </xsl:when>
50   <xsl:otherwise>
51    <xsl:call-template name="slash_counting">
52     <xsl:with-param name="uri" select="$second_uri"/>
53     <xsl:with-param name="counter" select="0"/>
54    </xsl:call-template>
55   </xsl:otherwise>   
56  </xsl:choose>
57 </xsl:template>
58
59 <xsl:template name="slash_counting">
60  <xsl:param name="uri" select="&quot;&quot;"/>
61  <xsl:param name="counter" select="0"/>
62  <xsl:choose>
63   <xsl:when test="(substring-after($uri,&quot;/&quot;) != &quot;&quot;)">
64    <xsl:call-template name="slash_counting">
65     <xsl:with-param 
66         name="uri" select="substring-after($uri,&quot;/&quot;)"/>
67     <xsl:with-param
68         name="counter" select="$counter +1"/> 
69    </xsl:call-template>
70   </xsl:when>
71   <xsl:otherwise>
72    <xsl:value-of select="$counter"/>
73   </xsl:otherwise>
74  </xsl:choose>   
75 </xsl:template>
76
77 <xsl:template name="blank_counting">
78  <xsl:param name="string" select="&quot;&quot;"/>
79  <xsl:param name="counter" select="0"/>
80  <xsl:choose>
81   <xsl:when test="(substring-after($string,&quot; &quot;) != &quot;&quot;)">
82    <xsl:call-template name="blank_counting">
83     <xsl:with-param 
84         name="string" select="substring-after($string,&quot; &quot;)"/>
85     <xsl:with-param 
86         name="counter" select="$counter +1"/> 
87    </xsl:call-template>
88   </xsl:when>
89   <xsl:otherwise>
90    <xsl:value-of select="$counter + 1"/>
91   </xsl:otherwise> 
92  </xsl:choose>  
93 </xsl:template>
94
95 <xsl:template name="double_point_counting">
96  <xsl:param name="string" select="&quot;&quot;"/>
97  <xsl:param name="counter" select="0"/>
98  <xsl:choose>
99   <xsl:when test="(substring-after($string,&quot;:&quot;) != &quot;&quot;)">
100    <xsl:call-template name="double_point_counting">
101     <xsl:with-param 
102         name="string" select="substring-after($string,&quot;:&quot;)"/>
103     <xsl:with-param 
104         name="counter" select="$counter +1"/> 
105    </xsl:call-template>
106   </xsl:when>
107   <xsl:otherwise>
108    <xsl:value-of select="$counter"/>
109   </xsl:otherwise> 
110  </xsl:choose>  
111 </xsl:template>
112
113 <xsl:template name="min">
114  <xsl:param name="string" select="&quot;&quot;"/>
115  <xsl:param name="counter" select="0"/>
116  <xsl:choose>
117   <xsl:when test="contains($string,concat($counter,&quot;:&quot;))
118          or (0 > $counter)">
119   <xsl:value-of select="$counter"/>
120   </xsl:when>
121   <xsl:otherwise>
122    <xsl:call-template name="min">
123     <xsl:with-param 
124         name="string" select="$string"/>
125     <xsl:with-param 
126         name="counter" select="$counter -1"/> 
127    </xsl:call-template>
128   </xsl:otherwise>
129  </xsl:choose>  
130 </xsl:template>
131
132 <xsl:template name="get_no_params">
133     <xsl:param name="first_uri" select="&quot;&quot;"/>
134     <xsl:param name="second_uri" select="&quot;&quot;"/>
135      <xsl:variable name="offset">
136       <xsl:call-template name="common_prefix">
137        <xsl:with-param name="first_uri" select="$first_uri"/>
138        <xsl:with-param name="second_uri" select="$second_uri"/>
139       </xsl:call-template>
140      </xsl:variable>
141      <xsl:choose>
142       <xsl:when test="$offset > 0">
143        <xsl:variable name="params"> 
144         <xsl:value-of 
145             select="document(concat(string($absPath),$second_uri))/*/@params"/>
146        </xsl:variable>
147        <xsl:variable name="minimum">
148         <xsl:call-template name="min">
149          <xsl:with-param name="string" select="$params"/>
150          <xsl:with-param name="counter" select="$offset - 1"/>
151         </xsl:call-template>
152        </xsl:variable>
153        <xsl:choose>
154         <xsl:when test="0 > $minimum">
155          0
156         </xsl:when>
157         <xsl:otherwise>
158          <xsl:variable name="relevant_params">
159           <!-- the blank after : in the next line is essential -->
160           <xsl:value-of 
161             select="substring-after($params,concat($minimum,&quot;: &quot;))"/>
162          </xsl:variable>
163          <xsl:variable name="tokens">
164           <xsl:call-template name="blank_counting">
165            <xsl:with-param name="string" select="$relevant_params"/>
166            <xsl:with-param name="counter" select="0"/>
167           </xsl:call-template>
168          </xsl:variable>
169          <xsl:variable name="separators">
170           <xsl:call-template name="double_point_counting">
171            <xsl:with-param name="string" select="$relevant_params"/>
172            <xsl:with-param name="counter" select="0"/>
173           </xsl:call-template>
174          </xsl:variable>
175          <xsl:value-of select="$tokens - $separators"/>
176         </xsl:otherwise>
177        </xsl:choose>
178       </xsl:when>
179       <xsl:otherwise>
180       0
181       </xsl:otherwise>
182      </xsl:choose>
183 </xsl:template>
184
185 </xsl:stylesheet> 
186
187
188
189
190
191