-
Notifications
You must be signed in to change notification settings - Fork 54
/
pmml.xsl
176 lines (150 loc) · 5.53 KB
/
pmml.xsl
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?xml version="1.0" ?>
<!--
Copyright (c) 2009 University of Tartu
-->
<xsl:stylesheet version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" xalan:indent-amount="2" xmlns:xalan="http://xml.apache.org/xslt"/>
<xsl:strip-space elements="*"/>
<xsl:include href="pmml-compatibility.xsl"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template name="extension">
<xs:element ref="Extension" minOccurs="0" maxOccurs="unbounded"/>
</xsl:template>
<xsl:template name="extension-comment">
<xsl:comment> <xs:element ref="Extension" minOccurs="0" maxOccurs="unbounded"/> </xsl:comment>
</xsl:template>
<xsl:template match="xs:schema">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:call-template name="compatibility-content"/>
</xsl:copy>
</xsl:template>
<!--
Ensure that the Extension list is on the first position
-->
<xsl:template match="xs:sequence">
<xsl:copy>
<xsl:choose>
<xsl:when test="count(xs:element[@ref='Extension']) = 1">
<xsl:apply-templates select="node()[@ref='Extension']"/>
<xsl:apply-templates select="@*|node()[not(@ref='Extension')]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@*|node()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<!--
Simplify Model type definitions by keeping the leading Extension list and commenting out the trailing Extension list
-->
<xsl:template match="xs:element[@ref='Extension'][position() > 1 and position() = last()]">
<xsl:call-template name="extension-comment"/>
</xsl:template>
<!--
Simplify EmbeddedModel group definition from XSD sequence to XSD choice by commenting out the Extension list
-->
<xsl:template match="xs:group[@name='EmbeddedModel']/xs:sequence/xs:element[@ref='Extension']">
<xsl:call-template name="extension-comment"/>
</xsl:template>
<!--
Simplify Array type definition
-->
<xsl:template match="xs:element[@name='Array']">
</xsl:template>
<xsl:template match="xs:complexType[@name='ArrayType']">
<xs:element name="Array">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xsl:copy-of select="*"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xsl:template>
<!--
Restrict xs:string to FIELD-NAME where appropriate
-->
<xsl:template match="xs:element[@name='BayesInput' or @name='BayesOutput']/xs:complexType/xs:attribute[@name='fieldName']/@type">
<xsl:attribute name="type">FIELD-NAME</xsl:attribute>
</xsl:template>
<xsl:template match="xs:element[@name='InstanceField' or @name='VerificationField']/xs:complexType/xs:attribute[@name='field']/@type">
<xsl:attribute name="type">FIELD-NAME</xsl:attribute>
</xsl:template>
<xsl:template match="xs:element[@name='NearestNeighborModel']/xs:complexType/xs:attribute[@name='instanceIdVariable']/@type">
<xsl:attribute name="type">FIELD-NAME</xsl:attribute>
</xsl:template>
<xsl:template match="xs:element[@name='ParameterField']/xs:complexType/xs:attribute[@name='name']/@type">
<xsl:attribute name="type">FIELD-NAME</xsl:attribute>
</xsl:template>
<xsl:template match="xs:element[@name='PredictiveModelQuality']/xs:complexType/xs:attribute[@name='targetField']/@type">
<xsl:attribute name="type">FIELD-NAME</xsl:attribute>
</xsl:template>
<!--
Simplify CONTINUOUS-DISTRIBUTION-TYPE group definition from XSD sequence to XSD choice by relocating the Extension list
-->
<xsl:template match="xs:group[@name='CONTINUOUS-DISTRIBUTION-TYPES']">
<xsl:copy>
<xsl:apply-templates select="@*|xs:sequence/xs:choice"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xs:element[@name='Alternate' or @name='Baseline']/xs:complexType">
<xsl:copy>
<xs:sequence>
<xsl:call-template name="extension"/>
<xsl:apply-templates select="@*|node()"/>
</xs:sequence>
</xsl:copy>
</xsl:template>
<!--
Declare dummy timeseries algorithm types
-->
<xsl:template match="xs:element[@name='ARIMA' or @name='SeasonalTrendDecomposition' or @name='SpectralAnalysis']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xs:complexType>
</xs:complexType>
</xsl:copy>
</xsl:template>
<!--
Replace xs:string with enum
-->
<xsl:template match="xs:element[@name='SetPredicate']/xs:complexType/xs:attribute[@name='operator']">
<xs:attribute name="operator" fixed="supersetOf">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="supersetOf"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xsl:template>
<!--
Replace xs:integer and xs:nonNegativeInteger with INT-NUMBER
-->
<xsl:template match="xs:attribute[@type='xs:integer' or @type='xs:nonNegativeInteger']/@type">
<xsl:attribute name="type">INT-NUMBER</xsl:attribute>
</xsl:template>
<!--
Replace xs:float and xs:double with NUMBER
-->
<xsl:template match="xs:attribute[@type='xs:float' or @type='xs:double']/@type">
<xsl:attribute name="type">NUMBER</xsl:attribute>
</xsl:template>
<!--
Replace xs:integer with xs:int
-->
<xsl:template match="xs:simpleType[@name='INT-NUMBER']/xs:restriction/@base">
<xsl:attribute name="base">xs:int</xsl:attribute>
</xsl:template>
<!--
Replace xs:decimal with xs:double
-->
<xsl:template match="xs:simpleType[@name='PROB-NUMBER' or @name='PERCENTAGE-NUMBER']/xs:restriction/@base">
<xsl:attribute name="base">xs:double</xsl:attribute>
</xsl:template>
</xsl:stylesheet>