]> matita.cs.unibo.it Git - helm.git/blobdiff - 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
diff --git a/helm/style/style_prima_del_linguaggio_naturale/params.xsl b/helm/style/style_prima_del_linguaggio_naturale/params.xsl
new file mode 100644 (file)
index 0000000..034eeba
--- /dev/null
@@ -0,0 +1,191 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                              xmlns:m="http://www.w3.org/1998/Math/MathML">
+
+<!--***********************************************************************--> 
+<!-- auxiliary functions                                                   -->
+<!-- HELM Group: Asperti, Padovani, Sacerdoti, Schena                      -->
+<!--***********************************************************************--> 
+
+<!--***********************************************************************-->
+<!-- get the name from a URI                                               -->
+<!--***********************************************************************-->
+
+<!-- CSC: PROBLEMA: URI CHE NON CONTENGONO / ED INIZIANO CON cic: -->
+<xsl:template name="name_of_uri">
+ <xsl:param name="uri" select="&quot;&quot;"/>
+ <xsl:variable name="suffix" select="substring-after($uri, &quot;/&quot;)"/>
+ <xsl:choose>
+  <xsl:when test="$suffix = &quot;&quot;">
+   <!-- CSC: PROBLEMA: .con PUO' APPARIRE ALL'INTERNO DELLE URI ===>
+     SCRIVERE UNA FUNZIONE RICORSIVA CHE RISOLVA -->
+   <xsl:value-of select="substring-before($uri,&quot;.con&quot;)"/>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:call-template name="name_of_uri">
+    <xsl:with-param name="uri" select="$suffix"/>
+   </xsl:call-template>
+  </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!--***********************************************************************-->
+<!-- erase common prefix from two uris                                     -->
+<!--***********************************************************************-->
+
+<xsl:template name="common_prefix">
+ <xsl:param name="first_uri" select="&quot;&quot;"/>
+ <xsl:param name="second_uri" select="&quot;&quot;"/>
+ <xsl:choose>
+  <xsl:when test="(substring-before($first_uri,&quot;/&quot;) = 
+                substring-before($second_uri,&quot;/&quot;) and 
+                substring-after($second_uri,&quot;/&quot;) != &quot;&quot;)">
+   <xsl:call-template name="common_prefix">
+    <xsl:with-param 
+        name="first_uri" select="substring-after($first_uri,&quot;/&quot;)"/>
+    <xsl:with-param 
+        name="second_uri" select="substring-after($second_uri,&quot;/&quot;)"/>    </xsl:call-template>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:call-template name="slash_counting">
+    <xsl:with-param name="uri" select="$second_uri"/>
+    <xsl:with-param name="counter" select="0"/>
+   </xsl:call-template>
+  </xsl:otherwise>   
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="slash_counting">
+ <xsl:param name="uri" select="&quot;&quot;"/>
+ <xsl:param name="counter" select="0"/>
+ <xsl:choose>
+  <xsl:when test="(substring-after($uri,&quot;/&quot;) != &quot;&quot;)">
+   <xsl:call-template name="slash_counting">
+    <xsl:with-param 
+        name="uri" select="substring-after($uri,&quot;/&quot;)"/>
+    <xsl:with-param
+        name="counter" select="$counter +1"/> 
+   </xsl:call-template>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:value-of select="$counter"/>
+  </xsl:otherwise>
+ </xsl:choose>   
+</xsl:template>
+
+<xsl:template name="blank_counting">
+ <xsl:param name="string" select="&quot;&quot;"/>
+ <xsl:param name="counter" select="0"/>
+ <xsl:choose>
+  <xsl:when test="(substring-after($string,&quot; &quot;) != &quot;&quot;)">
+   <xsl:call-template name="blank_counting">
+    <xsl:with-param 
+        name="string" select="substring-after($string,&quot; &quot;)"/>
+    <xsl:with-param 
+        name="counter" select="$counter +1"/> 
+   </xsl:call-template>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:value-of select="$counter + 1"/>
+  </xsl:otherwise> 
+ </xsl:choose>  
+</xsl:template>
+
+<xsl:template name="double_point_counting">
+ <xsl:param name="string" select="&quot;&quot;"/>
+ <xsl:param name="counter" select="0"/>
+ <xsl:choose>
+  <xsl:when test="(substring-after($string,&quot;:&quot;) != &quot;&quot;)">
+   <xsl:call-template name="double_point_counting">
+    <xsl:with-param 
+        name="string" select="substring-after($string,&quot;:&quot;)"/>
+    <xsl:with-param 
+        name="counter" select="$counter +1"/> 
+   </xsl:call-template>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:value-of select="$counter"/>
+  </xsl:otherwise> 
+ </xsl:choose>  
+</xsl:template>
+
+<xsl:template name="min">
+ <xsl:param name="string" select="&quot;&quot;"/>
+ <xsl:param name="counter" select="0"/>
+ <xsl:choose>
+  <xsl:when test="contains($string,concat($counter,&quot;:&quot;))
+         or (0 > $counter)">
+  <xsl:value-of select="$counter"/>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:call-template name="min">
+    <xsl:with-param 
+        name="string" select="$string"/>
+    <xsl:with-param 
+        name="counter" select="$counter -1"/> 
+   </xsl:call-template>
+  </xsl:otherwise>
+ </xsl:choose>  
+</xsl:template>
+
+<xsl:template name="get_no_params">
+    <xsl:param name="first_uri" select="&quot;&quot;"/>
+    <xsl:param name="second_uri" select="&quot;&quot;"/>
+     <xsl:variable name="offset">
+      <xsl:call-template name="common_prefix">
+       <xsl:with-param name="first_uri" select="$first_uri"/>
+       <xsl:with-param name="second_uri" select="$second_uri"/>
+      </xsl:call-template>
+     </xsl:variable>
+     <xsl:choose>
+      <xsl:when test="$offset > 0">
+       <xsl:variable name="params"> 
+        <xsl:value-of 
+            select="document(concat(string($absPath),$second_uri))/*/@params"/>
+       </xsl:variable>
+       <xsl:variable name="minimum">
+        <xsl:call-template name="min">
+         <xsl:with-param name="string" select="$params"/>
+         <xsl:with-param name="counter" select="$offset - 1"/>
+        </xsl:call-template>
+       </xsl:variable>
+       <xsl:choose>
+        <xsl:when test="0 > $minimum">
+         0
+        </xsl:when>
+        <xsl:otherwise>
+         <xsl:variable name="relevant_params">
+          <!-- the blank after : in the next line is essential -->
+          <xsl:value-of 
+            select="substring-after($params,concat($minimum,&quot;: &quot;))"/>
+         </xsl:variable>
+         <xsl:variable name="tokens">
+          <xsl:call-template name="blank_counting">
+           <xsl:with-param name="string" select="$relevant_params"/>
+           <xsl:with-param name="counter" select="0"/>
+          </xsl:call-template>
+         </xsl:variable>
+         <xsl:variable name="separators">
+          <xsl:call-template name="double_point_counting">
+           <xsl:with-param name="string" select="$relevant_params"/>
+           <xsl:with-param name="counter" select="0"/>
+          </xsl:call-template>
+         </xsl:variable>
+         <xsl:value-of select="$tokens - $separators"/>
+        </xsl:otherwise>
+       </xsl:choose>
+      </xsl:when>
+      <xsl:otherwise>
+      0
+      </xsl:otherwise>
+     </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet> 
+
+
+
+
+
+