home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW.cab / AS_msmdlocal_dll_32.C16C67A1_5ADC_4C44_B6AE_A40000020FCC / HTML / DMS2Y.XSL < prev    next >
Extensible Markup Language  |  2009-09-03  |  33KB  |  794 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.  
  4. *****************************************************************************
  5. *                                                                           *
  6. *                                                                           *
  7. *     Copyright (c) Microsoft Corporation.  All rights reserved.                *
  8. *                                                                           *
  9. *    File:        dmS2Y.xsl                                                    *
  10. *    Owner:       Bogdan Crivat (BogdanC)                                   *
  11. *___________________________________________________________________________*
  12. *                                                                           *
  13. *    Description:                                                           *
  14. *                                                                           *
  15. *        This XSLT transform generates XML DDL from an old( Shiloh) XML     *
  16. *         persistence format (extended PMML)                                    *
  17. *                                                                             *
  18. *         @todo: bogdanc - check whether the following are structural         *
  19. *        elements and need conversion to DDL                                    *
  20. *            - compound-categories|compound-category|categoryref|parent        *
  21. *            - hierarchy-parent                                                *
  22. *            - simple -attribute                                                *
  23. *            - compound-attribute, key-val,                                     *
  24. *            - derived-attribute                                                *
  25. *            - predicate/compound-predicate                                    *
  26. *                                                                            *
  27. *                                                                            *
  28. *        The DDL contains an internal element                                 *
  29. *        (MiningStructure\PMMLSourceVersion) -  that marks it  as being         *
  30. *        generated from PMML                                                 *
  31. *****************************************************************************
  32.  
  33. -->
  34. <xsl:transform 
  35.     version="1.0"
  36.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  37.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38.     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  39.     xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  40.     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  41.     xmlns:msxmla="urn:schemas-microsoft-com:xml-analysis"
  42.     xmlns:msddl="http://schemas.microsoft.com/analysisservices/2003/engine"
  43.     xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"
  44.     xmlns:prefix="msddl"
  45. >
  46.  
  47. <xsl:strip-space elements="*"/>
  48. <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" standalone="yes" />
  49.  
  50.  
  51. <!-- 
  52. /////////////////////////////////////////////////////////////////////////
  53. //                                                                     //
  54. // This transform can parse the following tree:                        //
  55. //                                                                     //
  56. //    <PMML name=>                                                       //
  57. //        <statements>                                                    //
  58. //            <statement type="CREATE"...>                                //
  59. //            ...                                                            //
  60. //        </statements>                                                    //
  61. //        <data-dictionary>                                                //
  62. //            <key...>                                                    //
  63. //            <categorical...>                                            //
  64. //            <ordinal....>                                                //
  65. //            <categorical-continuous....>                                //
  66. //            <continuous-categorical....>                                //
  67. //            <probability....>                                            //
  68. //            <value-variance....>                                        //
  69. //            <value-std....>                                                //
  70. //            <probability-variance....>                                    //
  71. //            <probability-std....>                                        //
  72. //            <support....>                                                //
  73. //            <data-dictionary>                                            //
  74. //                ...                                                        //
  75. //            </data-dictionary>                                            //
  76. //        </data-dictionary>                                                //
  77. //    </PMML>                                                               //
  78. //////////////////////////////////////////////////////////////////////////
  79. -->
  80.  
  81. <!-- ================================================================ -->
  82. <!--                                                                  -->
  83. <!--   Main Program                                                   -->
  84. <!--   Creates a SOAP Envelope then launches a Command template       -->
  85. <!-- ================================================================ -->
  86.  
  87. <xsl:template match="/">
  88.     <xsl:element name="soap:Envelope">
  89.         <xsl:element name="soap:Body">
  90.             <xsl:call-template name="generate-DDL-command"/>
  91.         </xsl:element>
  92.     </xsl:element>
  93. </xsl:template>
  94.  
  95.  
  96.  
  97. <!-- 
  98. /////////////////////////////////////////////////////////////////////////
  99. // generate-DDL-command:                                               //
  100. // Generates an Execute/Command object                                   //
  101. // Then, calls generate-DDL-Dataabse to get a Database element         // 
  102. /////////////////////////////////////////////////////////////////////////
  103. -->
  104. <xsl:template match="*" name="generate-DDL-command">
  105.     <xsl:element name="msxmla:Execute">
  106.         <!-- Command element-->
  107.         <xsl:element name="msxmla:Command">    
  108.             <!-- Generate Mining Model DDL -->
  109.             <xsl:element name="Create">
  110.                 <!-- Generate object definition -->
  111.                 <xsl:call-template name="generate-DDL-database-ref"/>
  112.                 <xsl:element name="ObjectDefinition">
  113.                     <xsl:call-template name="generate-olap-miningstructures"/>
  114.                 </xsl:element>
  115.             </xsl:element>
  116.         </xsl:element>
  117.         <xsl:element name="msxmla:Properties"/>
  118.     </xsl:element>
  119.    
  120. </xsl:template>
  121.  
  122.  
  123. <!-- 
  124. /////////////////////////////////////////////////////////////////////////
  125. // generate-DDL-database:                                               //
  126. // Generates a Database element, populates it with ID and Name            //
  127. //    based on the PMML                                                      //        
  128. // Then, calls generate-olap-miningstructures                           // 
  129. /////////////////////////////////////////////////////////////////////////
  130. -->
  131. <xsl:template match="*" name="generate-DDL-database-ref">
  132.     <xsl:element name="ParentObject">
  133.         <xsl:element name="DatabaseID">
  134.             <xsl:value-of select="/pmml/Injected_DatabaseID"/>
  135.         </xsl:element>
  136.     </xsl:element>
  137. </xsl:template>
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. <!-- 
  145. /////////////////////////////////////////////////////////////////////////
  146. // OLAP Mining Structures:                                             //
  147. // Generate the Mininng Structures                                     //
  148. /////////////////////////////////////////////////////////////////////////
  149. -->
  150. <xsl:template match="*" name="generate-olap-miningstructures">
  151.         <xsl:element name="MiningStructure">
  152.         <!--xsl:attribute name="dwd:design-time-name">miningStructure_<xsl:value-of select="/pmml/@name"/></xsl:attribute-->
  153.  
  154.             <xsl:for-each select="pmml">
  155.  
  156.                 <!-- generate the mining structure section of the ddl-->
  157.                 <xsl:call-template name="generate-olap-miningstructure">
  158.                     <xsl:with-param name="in_pmmlName" select="/pmml/Injected_ModelID"/>
  159.                     <xsl:with-param name="in_pmmlCreationTime" select="@creation-time"/>
  160.                     <xsl:with-param name="in_pmmlModifiedTime" select="@modified-time"/>
  161.                 </xsl:call-template>
  162.  
  163.  
  164.  
  165.                 <!--
  166.                 This element is unsupported
  167.                 <xsl:element name="State">UnProcessed</xsl:element>
  168.                 -->
  169.  
  170.                 <!-- generate the mining model -->
  171.                 <xsl:call-template name="generate-olap-miningmodel">
  172.                     <xsl:with-param name="in_pmmlName" select="/pmml/Injected_ModelID"/>
  173.                     <xsl:with-param name="in_pmmlCreationTime" select="@creation-time"/>
  174.                     <xsl:with-param name="in_pmmlModifiedTime" select="@modified-time"/>
  175.                 </xsl:call-template>
  176.  
  177.                 </xsl:for-each>
  178.             
  179.         </xsl:element>
  180. </xsl:template>
  181.  
  182.  
  183.  
  184. <!-- 
  185. /////////////////////////////////////////////////////////////////////////
  186. // OLAP Mining Structure:                                              //
  187. // Generate elements of an OLAP mining structure                       //
  188. /////////////////////////////////////////////////////////////////////////
  189. -->
  190. <xsl:template match="pmml" name="generate-olap-miningstructure">
  191.     <xsl:param name="in_pmmlName"/>
  192.     <xsl:param name="in_pmmlCreationTime"/>
  193.     <xsl:param name="in_pmmlModifiedTime"/>
  194.  
  195.     <xsl:element name="PMMLSourceVersion"><xsl:value-of select="/pmml/Injected_PMMLVersion"/></xsl:element>
  196.     
  197.     
  198.     <xsl:element name="ID">
  199.         <xsl:choose>
  200.             <xsl:when test="$in_pmmlName">
  201.                 <xsl:call-template name="render-valid-ID-from-string">
  202.                     <xsl:with-param name="in_strBaseName" select="$in_pmmlName"/>
  203.                 </xsl:call-template>
  204.             </xsl:when>
  205.             <xsl:otherwise>
  206.                 <xsl:call-template name="render-valid-ID-from-string">
  207.                     <xsl:with-param name="in_strBaseName" select="@name"/>
  208.                 </xsl:call-template>
  209.             </xsl:otherwise>
  210.         </xsl:choose>
  211.     </xsl:element>
  212.     <xsl:element name="Name">
  213.         <xsl:choose>
  214.             <xsl:when test="$in_pmmlName">
  215.                 <xsl:call-template name="render-valid-ID-from-string">
  216.                     <xsl:with-param name="in_strBaseName" select="$in_pmmlName"/>
  217.                 </xsl:call-template>
  218.             </xsl:when>
  219.             <xsl:otherwise>
  220.                 <xsl:call-template name="render-valid-ID-from-string">
  221.                     <xsl:with-param name="in_strBaseName" select="@name"/>
  222.                 </xsl:call-template>
  223.             </xsl:otherwise>
  224.         </xsl:choose>
  225.     </xsl:element>
  226.  
  227.     <!--  The Created/Updated stuff seems not to be needed
  228.         
  229.     <xsl:call-template name="create-updated-dateTime-format-element">
  230.         <xsl:with-param name="in_tagName" >CreatedTimeStamp</xsl:with-param>
  231.         <xsl:with-param name="in_oldDateTime" select="$in_pmmlCreationTime"/>
  232.     </xsl:call-template>
  233.     
  234.     <xsl:call-template name="create-updated-dateTime-format-element">
  235.         <xsl:with-param name="in_tagName" >LastSchemaUpdate</xsl:with-param>
  236.         <xsl:with-param name="in_oldDateTime" select="$in_pmmlModifiedTime"/>
  237.     </xsl:call-template>
  238.     
  239.     -->
  240.     
  241.  
  242.     <xsl:comment>The SOURCE section might have to be filled</xsl:comment>
  243.  
  244.     <!--  The Created/Updated stuff seems not to be needed
  245.     <xsl:call-template name="create-updated-dateTime-format-element">
  246.         <xsl:with-param name="in_tagName" >LastProcessed</xsl:with-param>
  247.         <xsl:with-param name="in_oldDateTime" select="$in_pmmlModifiedTime"/>
  248.     </xsl:call-template>
  249.     -->
  250.  
  251.     <xsl:for-each select="./data-dictionary">
  252.         <xsl:call-template name="olap-mininingstruct-columns-from-datadictionary" />
  253.     </xsl:for-each>
  254.  
  255. </xsl:template>
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264. <!-- 
  265. /////////////////////////////////////////////////////////////////////////
  266. // OLAP Mining Model:                                                  //
  267. // Generate elements of an OLAP mining model                           //
  268. /////////////////////////////////////////////////////////////////////////
  269. -->
  270. <xsl:template match="pmml" name="generate-olap-miningmodel">
  271.     <xsl:param name="in_pmmlName"/>
  272.     <xsl:param name="in_pmmlCreationTime"/>
  273.     <xsl:param name="in_pmmlModifiedTime"/>
  274.  
  275.     <xsl:element name="MiningModels">
  276.         <xsl:element name="MiningModel">
  277.             <!--xsl:attribute name="dwd:design-time-name">miningModel_<xsl:value-of select="@name"/></xsl:attribute-->
  278.  
  279.             <xsl:element name="ID">
  280.                 <xsl:choose>
  281.                     <xsl:when test="$in_pmmlName">
  282.                         <xsl:call-template name="render-valid-ID-from-string">
  283.                             <xsl:with-param name="in_strBaseName" select="$in_pmmlName"/>
  284.                         </xsl:call-template>
  285.                     </xsl:when>
  286.                     <xsl:otherwise>
  287.                         <xsl:call-template name="render-valid-ID-from-string">
  288.                             <xsl:with-param name="in_strBaseName" select="@name"/>
  289.                         </xsl:call-template>
  290.                     </xsl:otherwise>
  291.                 </xsl:choose>
  292.             </xsl:element>
  293.             <xsl:element name="Name">
  294.                 <xsl:choose>
  295.                     <xsl:when test="$in_pmmlName">
  296.                         <xsl:call-template name="render-valid-ID-from-string">
  297.                             <xsl:with-param name="in_strBaseName" select="$in_pmmlName"/>
  298.                         </xsl:call-template>
  299.                     </xsl:when>
  300.                     <xsl:otherwise>
  301.                         <xsl:call-template name="render-valid-ID-from-string">
  302.                             <xsl:with-param name="in_strBaseName" select="@name"/>
  303.                         </xsl:call-template>
  304.                     </xsl:otherwise>
  305.                 </xsl:choose>
  306.             </xsl:element>
  307.     
  308.             <!--  The Created/Updated stuff seems not to be needed
  309.             <xsl:call-template name="create-updated-dateTime-format-element">
  310.                 <xsl:with-param name="in_tagName" >CreatedTimeStamp</xsl:with-param>
  311.                 <xsl:with-param name="in_oldDateTime" select="$in_pmmlCreationTime"/>
  312.             </xsl:call-template>
  313.             
  314.             <xsl:call-template name="create-updated-dateTime-format-element">
  315.                 <xsl:with-param name="in_tagName" >LastSchemaUpdate</xsl:with-param>
  316.                 <xsl:with-param name="in_oldDateTime" select="$in_pmmlModifiedTime"/>
  317.             </xsl:call-template>
  318.             -->
  319.             
  320.             <xsl:element name="Algorithm">
  321.                 <xsl:choose>
  322.                     <!-- If a tree-model exists, then Decision_Trees -->
  323.                     <xsl:when test="/pmml/tree-model">
  324.                         <xsl:value-of select="'Microsoft_Decision_Trees'"/>
  325.                     </xsl:when>
  326.                     <!-- Otherwise, Clustering -->
  327.                     <xsl:otherwise>
  328.                         <xsl:value-of select="'Microsoft_Clustering'"/>
  329.                     </xsl:otherwise>
  330.                 </xsl:choose>
  331.             </xsl:element>
  332.             
  333.             <xsl:element name="AlgorithmParameters">
  334.                 <xsl:call-template name="render-algorithm-parameters"/>
  335.             </xsl:element>
  336.             
  337.             <!--  The Created/Updated stuff seems not to be needed
  338.             <xsl:call-template name="create-updated-dateTime-format-element">
  339.                 <xsl:with-param name="in_tagName" >LastProcessed</xsl:with-param>
  340.                 <xsl:with-param name="in_oldDateTime" select="$in_pmmlModifiedTime"/>
  341.             </xsl:call-template>
  342.             -->
  343.             
  344.             <xsl:for-each select="./data-dictionary">
  345.                 <xsl:call-template name="olap-mininingmodel-columns-from-datadictionary" />
  346.             </xsl:for-each>
  347.         </xsl:element>
  348.     </xsl:element>
  349. </xsl:template>  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356. <!-- 
  357. /////////////////////////////////////////////////////////////////////////
  358. // OLAP Mining Structure columns:                                      //
  359. // Generates the content of a  Mining Structure Columns tag from a     //
  360. // pmml data-dictionary                                                //
  361. /////////////////////////////////////////////////////////////////////////
  362. -->
  363.  
  364. <xsl:template match="data-dictionary" name="olap-mininingstruct-columns-from-datadictionary">
  365.    
  366.    <xsl:element name="Columns">
  367.     <xsl:for-each select="./*">
  368.     <!-- call a template to generate a column for each child element-->
  369.       <xsl:choose>
  370.         <xsl:when test="'data-dictionary'=local-name()">
  371.           <!--nested table column-->
  372.           <xsl:call-template name="olap-miningstructure-column">
  373.             <xsl:with-param name="in_columnType">TableMiningStructureColumn</xsl:with-param>
  374.           </xsl:call-template>
  375.         </xsl:when>
  376.         <xsl:otherwise>
  377.           <!--regular, simple column-->
  378.           <xsl:call-template name="olap-miningstructure-column">
  379.             <xsl:with-param name="in_columnType">ScalarMiningStructureColumn</xsl:with-param>
  380.           </xsl:call-template>
  381.         </xsl:otherwise>
  382.       </xsl:choose>
  383.     </xsl:for-each>
  384.    </xsl:element>
  385.    
  386. </xsl:template>
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393. <!-- 
  394. /////////////////////////////////////////////////////////////////////////
  395. // OLAP Mining Model columns:                                          //
  396. // Generates the content of a  Mining Model Columns tag from a         //
  397. // pmml data-dictionary                                                //
  398. /////////////////////////////////////////////////////////////////////////
  399. -->
  400.  
  401. <xsl:template match="data-dictionary" name="olap-mininingmodel-columns-from-datadictionary">
  402.    
  403.    <xsl:element name="Columns">
  404.     <xsl:for-each select="./*">
  405.     <!-- Call a template to generate a column for each child element
  406.          Also, treat all columns as regular, simple columns-->
  407.       <xsl:call-template name="olap-miningmodel-column"/>
  408.     </xsl:for-each>
  409.    </xsl:element>
  410.    
  411. </xsl:template>
  412.  
  413.  
  414. <!-- 
  415. /////////////////////////////////////////////////////////////////////////
  416. // Creates one OLAP Mining Structure column:                           //
  417. /////////////////////////////////////////////////////////////////////////
  418. -->
  419. <xsl:template match="*" name="olap-miningstructure-column">
  420.     <xsl:param name="in_columnType"/>
  421.     
  422.     <xsl:element name="Column">
  423.         <xsl:attribute name="xsi:type"><xsl:value-of select="$in_columnType"/></xsl:attribute>
  424.         <!--xsl:attribute name="dwd:design-time-name"><xsl:value-of select="$in_columnType"/>_<xsl:value-of select="@name"/></xsl:attribute-->
  425.  
  426.         <xsl:element name="ID" >
  427.             <xsl:call-template name="render-valid-ID-from-string">
  428.                 <xsl:with-param name="in_strBaseName" select="@name"/>
  429.             </xsl:call-template>
  430.         </xsl:element>
  431.         <xsl:element name="Name" ><xsl:value-of select="@name"/></xsl:element>
  432.         
  433.         <xsl:choose>
  434.            <xsl:when test="'ScalarMiningStructureColumn' = $in_columnType">
  435.                 <!-- generate Scalar Column -->
  436.                 <xsl:element name="Type" >
  437.                     <!-- Type has to be Phrase-case the type name
  438.                          bogdanc - Look for a better way to do this    
  439.                          Exceptions 
  440.                              - Real has to become Double
  441.                      -->
  442.                    <xsl:choose>
  443.                            <xsl:when test="'REAL'=@datatype">Double</xsl:when>
  444.                            <xsl:otherwise>
  445.                            <xsl:variable name="TmpString1" select="substring(@datatype,1,1)"/>
  446.                             <xsl:value-of select="translate($TmpString1, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
  447.                             <xsl:variable name="TmpString2" select="substring(@datatype,2)"/>
  448.                             <xsl:value-of select="translate($TmpString2, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  449.                          </xsl:otherwise>
  450.                      </xsl:choose>
  451.                 </xsl:element>
  452.                 <xsl:if test="'key' = local-name()">
  453.                     <!-- this element is a key - add a IsKey tag -->
  454.                     <xsl:element name="IsKey" >true</xsl:element>
  455.                 </xsl:if>
  456.                 
  457.                 <!-- TODO - find out whether a Key can be input and/or predict,and how to represent it in Usage -->
  458.                 
  459.                 <xsl:element name="Content" >
  460.                     <!-- MAPPING : determine the Content value based on the key name -->
  461.                     <xsl:choose>
  462.                         <xsl:when test="'key'=local-name()">Key</xsl:when>
  463.                         <xsl:when test="'categorical'=local-name()">Discrete</xsl:when>
  464.                         <xsl:when test="'continuous'=local-name()">Continuous</xsl:when>
  465.                         <xsl:when test="('continuous-categorical'=local-name()) or ('categorical-continuous'=local-name())">Discretized</xsl:when>
  466.                         <xsl:when test="'categorical-continuous'=local-name()">Discretized</xsl:when>
  467.                         <!-- MAPPING - how to interpret the old spec for <!ELEMENT ordinal /page115? -->
  468.                         <xsl:when test="'ordinal'=local-name()">
  469.                             <xsl:choose>
  470.                                 <xsl:when test="'true'=@cyclical">Cyclical</xsl:when>
  471.                                 <xsl:when test="'true'=@timesequence">Sequence</xsl:when> <!-- OR should it be Time??? -->
  472.                                 <xsl:otherwise>Ordered</xsl:otherwise>
  473.                             </xsl:choose>
  474.                         </xsl:when>
  475.                         <xsl:when test="'probability'=local-name()">Probability</xsl:when>
  476.                         <xsl:when test="'value-variance'=local-name()">Variance</xsl:when>
  477.                         <xsl:when test="'value-std'=local-name()">StdDev</xsl:when>
  478.                         <xsl:when test="'probability-variance'=local-name()">ProbabilityVariance</xsl:when>
  479.                         <xsl:when test="'probability-std'=local-name()">ProbabilityStdDev</xsl:when>
  480.                         <xsl:when test="'support'=local-name()">Support</xsl:when>
  481.                         <xsl:when test="'hierarchy-parent'=local-name()">Discrete</xsl:when>
  482.                     </xsl:choose>
  483.                 </xsl:element>
  484.  
  485.                 <!-- for hierarchy-parent columns, add a ClassifiedColumnID element -->
  486.                 <xsl:if test="'hierarchy-parent'=local-name()">
  487.                     <xsl:element name="ClassifiedColumns">
  488.                         <xsl:element name="ClassifiedColumnID">
  489.                             <xsl:value-of select="@relates-to"/>
  490.                         </xsl:element>
  491.                     </xsl:element>
  492.                 </xsl:if>
  493.                 
  494.                 <xsl:element name="ModelingFlags">
  495.                     <xsl:if test="'true'=@model-not-null">
  496.                         <xsl:element name="ModelingFlag">NOT NULL</xsl:element>
  497.                     </xsl:if>
  498.                 </xsl:element>
  499.                 <!-- for discretized types, try too figure out the discretization method -->
  500.                 <xsl:if test="('continuous-categorical'=local-name()) or ('categorical-continuous'=local-name())">
  501.                   <xsl:element name="DiscretizationMethod">
  502.                     <xsl:choose>
  503.                       <!-- MAPPING: determine the discretization method and the buckets count based on the @discretization-method attributes-->
  504.                       <xsl:when test="'EQUALAREA'=@discretization-method">EqualAreas</xsl:when>
  505.                       <xsl:when test="'CLUSTER'=@discretization-method">Clusters</xsl:when>
  506.                       <xsl:when test="'THRESHOLD'=@discretization-method">Thresholds</xsl:when>
  507.                       <xsl:otherwise>Automatic</xsl:otherwise>
  508.                     </xsl:choose>
  509.                   </xsl:element>
  510.                   <xsl:element name="DiscretizationBucketCount">
  511.                     <xsl:choose>
  512.                       <!-- MAPPING: determine the discretization method and the buckets count based on the @discretization-method attributes-->
  513.                       <xsl:when test="@number-of-buckets"><xsl:value-of select="@number-of-buckets"/></xsl:when>
  514.                       <xsl:otherwise>5</xsl:otherwise>
  515.                     </xsl:choose>
  516.                   </xsl:element>
  517.                 </xsl:if>
  518.                 
  519.                 <!-- add KeyColumns although there is not enough information to fill them now -->
  520.                 <xsl:element name="KeyColumns"/>
  521.            </xsl:when>
  522.            
  523.            <xsl:when test="'TableMiningStructureColumn' = $in_columnType">
  524.                 <!-- generate Table Column(nested) -->
  525.                 <xsl:element name="ForeignKeyColumns"/>
  526.                 
  527.                 <!-- now generate the Columns section of the nested table-->
  528.                 <xsl:call-template name="olap-mininingstruct-columns-from-datadictionary" />
  529.            </xsl:when>
  530.         </xsl:choose>
  531.            
  532.             
  533.         
  534.     </xsl:element>
  535. </xsl:template>
  536.  
  537.  
  538.  
  539.  
  540.  
  541. <!-- 
  542. /////////////////////////////////////////////////////////////////////////
  543. // Creates one OLAP Mining Model column:                               //
  544. /////////////////////////////////////////////////////////////////////////
  545. -->
  546. <xsl:template match="*" name="olap-miningmodel-column">
  547.     
  548.     <xsl:element name="Column">
  549.         <!--xsl:attribute name="dwd:design-time-name">miningModelColumn_<xsl:value-of select="@name"/></xsl:attribute-->
  550.  
  551.         <xsl:element name="ID" >
  552.             <xsl:call-template name="render-valid-ID-from-string">
  553.                 <xsl:with-param name="in_strBaseName" select="@name"/>
  554.             </xsl:call-template>
  555.         </xsl:element>
  556.         <xsl:element name="Name" ><xsl:value-of select="@name"/></xsl:element>
  557.         <xsl:element name="SourceColumnID" ><xsl:value-of select="@name"/></xsl:element>
  558.  
  559.         <!-- MAPPING - Generate Usage element if necessary
  560.             from the attributes of the PMML element
  561.             ASSUMING - that isinput AND ispredict = Predict
  562.                      - that ispredict AND NO isinput = PredictOnly
  563.                      - that isinput AND NO ispredict= Input 
  564.         -->
  565.  
  566.  
  567.         <!-- Key element name => <IsKey>true</IsKey> -->
  568.         <xsl:if test="'key' = local-name()">
  569.             <xsl:element name="Usage" >Key</xsl:element>
  570.         </xsl:if>
  571.         
  572.         <xsl:element name="ModelingFlags">
  573.             <xsl:if test="'true'=@model-as-binary">
  574.                 <xsl:element name="ModelingFlag">MODEL_EXISTENCE_ONLY</xsl:element>
  575.             </xsl:if>
  576.         </xsl:element>
  577.         
  578.  
  579.         <xsl:choose>
  580.             <!-- isinput AND ispredict => Predict -->
  581.             <xsl:when test="('true'=@isinput) and ('true'=@ispredict) and not ('key'=local-name())">
  582.                 <xsl:element name="Usage" >Predict</xsl:element>
  583.             </xsl:when>
  584.             
  585.             <!-- NOT isinput AND ispredict => Predict -->
  586.             <xsl:when test="('true'!=@isinput) and ('true'=@ispredict) and not ('key'=local-name())">
  587.                 <xsl:element name="Usage" >PredictOnly</xsl:element>
  588.             </xsl:when>
  589.             
  590.             <!-- isinput AND NOT ispredict => Predict -->
  591.             <xsl:when test="('true'=@isinput) and ('true'!=@ispredict) and not ('key'=local-name())">
  592.                 <xsl:element name="Usage" >Input</xsl:element>
  593.             </xsl:when>
  594.             
  595.         </xsl:choose>
  596.  
  597.  
  598.         <xsl:if test="'data-dictionary'=local-name()">
  599.           <!--nested table column, restart this template and generate another Columns element-->
  600.           <xsl:call-template name="olap-mininingmodel-columns-from-datadictionary"/>
  601.         </xsl:if>
  602.  
  603.         
  604.     </xsl:element>
  605. </xsl:template>
  606.  
  607.  
  608.  
  609.  
  610.  
  611. <!-- 
  612. /////////////////////////////////////////////////////////////////////////
  613. // Converts an old dateTime representation to teh 2001 schema form     //
  614. /////////////////////////////////////////////////////////////////////////
  615. -->
  616.  
  617. <xsl:template match="*" name="create-updated-dateTime-format-element">
  618.     <xsl:param name="in_tagName"/>
  619.     <xsl:param name="in_oldDateTime"/>
  620.     <!-- TODO :  look for a way to get locale GMT time offset -->    
  621.     <xsl:element name="{$in_tagName}"><xsl:value-of select="$in_oldDateTime"/>.0000000-08:00</xsl:element>
  622. </xsl:template>
  623.  
  624.  
  625.  
  626. <!-- 
  627. ///////////////////////////////////////////////////////////////////////////
  628. // Renders a  string as a valid ID value, therefore removes all entities //
  629. ///////////////////////////////////////////////////////////////////////////
  630. -->
  631.  
  632. <xsl:template match="*" name="render-valid-ID-from-string">
  633.     <xsl:param name="in_strBaseName"/>
  634.  
  635.     <xsl:variable name="postApos" select="translate($in_strBaseName,"'",'')"/>
  636.     <xsl:variable name="postAmp" select="translate($postApos,"&",'')"/>
  637.     <xsl:value-of select="$postAmp"/>
  638. </xsl:template>
  639.  
  640.  
  641.  
  642.  
  643. <!-- 
  644. ///////////////////////////////////////////////////////////////////////////
  645. // Renders a  string as a valid ID value, therefore removes all entities //
  646. // Note -  modifying this requires modifications in the                  //
  647. // DMParserShilohPMMLToDDL::startElement which generates the IDs of      //
  648. // the mining struct and mining model on the same rule                     //
  649. ///////////////////////////////////////////////////////////////////////////
  650. -->
  651.  
  652. <xsl:template match="*" name="render-algorithm-parameters">
  653.     
  654.     
  655.  
  656.  
  657.     <!-- 
  658.     ///////////////////////////////////////////////////////////////////////////
  659.     // Common parameters (Classification and clustering)                     //
  660.     ///////////////////////////////////////////////////////////////////////////
  661.     -->
  662.     <!-- Checking for MAXIMUM_INPUT_ATTRIBUTES-->
  663.     <xsl:call-template name="render-one-algorithm-parameter">
  664.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@maximum-input-attributes"/>
  665.         <xsl:with-param name="in_DDLName" select="'MAXIMUM_INPUT_ATTRIBUTES'"/>
  666.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  667.     </xsl:call-template>
  668.     
  669.     <!-- Checking for MAXIMUM_OUTUT_ATTRIBUTES-->
  670.     <xsl:call-template name="render-one-algorithm-parameter">
  671.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@maximum-output-attributes"/>
  672.         <xsl:with-param name="in_DDLName" select="'MAXIMUM_OUTPUT_ATTRIBUTES'"/>
  673.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  674.     </xsl:call-template>
  675.  
  676.     <!-- 
  677.     ///////////////////////////////////////////////////////////////////////////
  678.     // Parameters for Decision Trees (Classification)                         //
  679.     ///////////////////////////////////////////////////////////////////////////
  680.     -->
  681.     
  682.     <!-- Checking for SPLIT_METHOD-->
  683.     <xsl:call-template name="render-one-algorithm-parameter">
  684.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@split-method"/>
  685.         <xsl:with-param name="in_DDLName" select="'SPLIT_METHOD'"/>
  686.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  687.     </xsl:call-template>
  688.     
  689.     
  690.     <!-- Checking for SCORE_METHOD-->
  691.     <xsl:call-template name="render-one-algorithm-parameter">
  692.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@score-method"/>
  693.         <xsl:with-param name="in_DDLName" select="'SCORE_METHOD'"/>
  694.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  695.     </xsl:call-template>
  696.     
  697.     <!-- Checking for MINIMUM_LEAF_CASES-->
  698.     <xsl:call-template name="render-one-algorithm-parameter">
  699.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@minimum-leaf-cases"/>
  700.         <xsl:with-param name="in_DDLName" select="'MINIMUM_SUPPORT'"/>
  701.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  702.     </xsl:call-template>
  703.     
  704.     <!-- Checking for COMPLEXITY_PENALTY-->
  705.     <xsl:call-template name="render-one-algorithm-parameter">
  706.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@complexity-penalty"/>
  707.         <xsl:with-param name="in_DDLName" select="'COMPLEXITY_PENALTY'"/>
  708.         <xsl:with-param name="in_XSDType" select="'xsd:double'"/>
  709.     </xsl:call-template>
  710.     
  711.     
  712.     
  713.     <!-- 
  714.     ///////////////////////////////////////////////////////////////////////////
  715.     // Parameters for Clustering                                               //
  716.     ///////////////////////////////////////////////////////////////////////////
  717.     -->
  718.     
  719.     <!-- Checking for CLUSTERING_METHOD-->
  720.     <xsl:call-template name="render-one-algorithm-parameter">
  721.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@clustering-method"/>
  722.         <xsl:with-param name="in_DDLName" select="'CLUSTERING_METHOD'"/>
  723.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  724.     </xsl:call-template>
  725.     
  726.     <!-- Checking for CLUSTER_COUNT-->
  727.     <xsl:call-template name="render-one-algorithm-parameter">
  728.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@cluster-count"/>
  729.         <xsl:with-param name="in_DDLName" select="'CLUSTER_COUNT'"/>
  730.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  731.     </xsl:call-template>
  732.     
  733.     <!-- Checking for MINIMUM_CLUSTER_CASES-->
  734.     <xsl:call-template name="render-one-algorithm-parameter">
  735.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@minimum-cluster-cases"/>
  736.         <xsl:with-param name="in_DDLName" select="'MINIMUM_SUPPORT'"/>
  737.         <xsl:with-param name="in_XSDType" select="'xsd:double'"/>
  738.     </xsl:call-template>
  739.     
  740.     <!-- Checking for MODELLING_CARDINALITY-->
  741.     <xsl:call-template name="render-one-algorithm-parameter">
  742.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@modelling-cardinality"/>
  743.         <xsl:with-param name="in_DDLName" select="'MODELLING_CARDINALITY'"/>
  744.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  745.     </xsl:call-template>
  746.     
  747.     <!-- Checking for STOPPING_TOLERANCE-->
  748.     <xsl:call-template name="render-one-algorithm-parameter">
  749.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@stopping-tolerance"/>
  750.         <xsl:with-param name="in_DDLName" select="'STOPPING_TOLERANCE'"/>
  751.         <xsl:with-param name="in_XSDType" select="'xsd:double'"/>
  752.     </xsl:call-template>
  753.  
  754.     <!-- Checking for SAMPLE_SIZE does not appear in Shiloh-->
  755.     <!-- xsl:call-template name="render-one-algorithm-parameter">
  756.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@sample-size"/>
  757.         <xsl:with-param name="in_DDLName" select="'SAMPLE_SIZE'"/>
  758.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  759.     </xsl:call-template-->
  760.     
  761.     <!-- Checking for MAXIMUM_STATES does not appear in Shiloh-->
  762.     <!-- xsl:call-template name="render-one-algorithm-parameter">
  763.         <xsl:with-param name="in_DDAttrName" select="/pmml/data-dictionary/@maximum-states"/>
  764.         <xsl:with-param name="in_DDLName" select="'MAXIMUM_STATES'"/>
  765.         <xsl:with-param name="in_XSDType" select="'xsd:int'"/>
  766.     </xsl:call-template-->
  767. </xsl:template>
  768.  
  769.  
  770.  
  771. <xsl:template match="*" name="render-one-algorithm-parameter">
  772.     <xsl:param name="in_DDAttrName"/>
  773.     <xsl:param name="in_DDLName"/>
  774.     <xsl:param name="in_XSDType"/>
  775.  
  776.     <xsl:if test="string-length($in_DDAttrName) > 0">
  777.         <xsl:element name="AlgorithmParameter">
  778.             <xsl:element name="Name">
  779.                 <xsl:value-of select="$in_DDLName"/>
  780.             </xsl:element>
  781.             <xsl:element name="Value">
  782.                 <xsl:attribute name="xsi:type">
  783.                     <xsl:value-of select="$in_XSDType"/>
  784.                 </xsl:attribute>
  785.                 <xsl:value-of select="$in_DDAttrName"/>
  786.             </xsl:element>
  787.         </xsl:element>
  788.     </xsl:if>
  789.  
  790. </xsl:template>
  791.  
  792.  
  793. </xsl:transform>
  794.