openmath 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +26 -5
  3. data/lib/openmath/cd/collection.rb +92 -0
  4. data/lib/openmath/cd/configuration.rb +65 -0
  5. data/lib/openmath/cd/definition.rb +42 -0
  6. data/lib/openmath/cd/document.rb +50 -0
  7. data/lib/openmath/cd/example.rb +22 -0
  8. data/lib/openmath/cd/fmp.rb +21 -0
  9. data/lib/openmath/cd/namespace.rb +13 -0
  10. data/lib/openmath/cd/validation.rb +10 -0
  11. data/lib/openmath/cd.rb +27 -0
  12. data/lib/openmath/evaluation/binding_table.rb +58 -0
  13. data/lib/openmath/evaluation/error_value.rb +27 -0
  14. data/lib/openmath/evaluation/errors.rb +65 -0
  15. data/lib/openmath/evaluation/evaluator.rb +141 -0
  16. data/lib/openmath/evaluation/operations.rb +126 -0
  17. data/lib/openmath/evaluation.rb +29 -0
  18. data/lib/openmath/v2.rb +1 -1
  19. data/lib/openmath/v3/common_elements.rb +48 -0
  20. data/lib/openmath/v3/configuration.rb +35 -0
  21. data/lib/openmath/v3/oma.rb +9 -0
  22. data/lib/openmath/v3/omatp.rb +9 -0
  23. data/lib/openmath/v3/omattr.rb +9 -0
  24. data/lib/openmath/v3/omb.rb +9 -0
  25. data/lib/openmath/v3/ombind.rb +9 -0
  26. data/lib/openmath/v3/ombvar.rb +9 -0
  27. data/lib/openmath/v3/ome.rb +9 -0
  28. data/lib/openmath/v3/omf.rb +9 -0
  29. data/lib/openmath/v3/omforeign.rb +9 -0
  30. data/lib/openmath/v3/omi.rb +9 -0
  31. data/lib/openmath/v3/omobj.rb +9 -0
  32. data/lib/openmath/v3/omr.rb +9 -0
  33. data/lib/openmath/v3/oms.rb +9 -0
  34. data/lib/openmath/v3/omstr.rb +9 -0
  35. data/lib/openmath/v3/omv.rb +9 -0
  36. data/lib/openmath/v3.rb +55 -0
  37. data/lib/openmath/validation.rb +62 -0
  38. data/lib/openmath/version.rb +1 -1
  39. data/lib/openmath.rb +28 -1
  40. data/schemas/PROVENANCE.md +17 -0
  41. data/schemas/om3-common.rng +257 -0
  42. data/schemas/omcd2.rng +180 -0
  43. data/schemas/openmath2.rnc +88 -0
  44. data/schemas/openmath2.rng +248 -0
  45. data/schemas/openmath3.rng +19 -0
  46. metadata +60 -9
data/lib/openmath.rb CHANGED
@@ -7,6 +7,10 @@ module Openmath
7
7
  autoload :CommonElements, "openmath/common_elements"
8
8
  autoload :Namespace, "openmath/namespace"
9
9
  autoload :V2, "openmath/v2"
10
+ autoload :V3, "openmath/v3"
11
+ autoload :Validation, "openmath/validation"
12
+ autoload :Evaluation, "openmath/evaluation"
13
+ autoload :CD, "openmath/cd"
10
14
 
11
15
  module Base
12
16
  autoload :Oms, "openmath/base/oms"
@@ -34,9 +38,32 @@ module Openmath
34
38
  def parse(input, version: 2)
35
39
  case version
36
40
  when 2 then V2.parse(input)
41
+ when 3 then V3.parse(input)
37
42
  else raise ArgumentError, "unsupported OpenMath version #{version.inspect}"
38
43
  end
39
44
  end
40
45
 
41
- module_function :parse
46
+ # Validates the document against the version's schema and raises
47
+ # Openmath::Validation::ValidationError on any violation.
48
+ def validate!(xml, version: 2)
49
+ Validation.validate!(xml, version: version)
50
+ end
51
+
52
+ def valid?(xml, version: 2)
53
+ Validation.valid?(xml, version: version)
54
+ end
55
+
56
+ # Parses a CD document into Openmath::CD::Document.
57
+ def parse_cd(input)
58
+ CD.parse(input)
59
+ end
60
+
61
+ # Evaluates an OpenMath object (or XML text) under the variable bindings.
62
+ def evaluate(object, variables: {}, table: nil, version: nil)
63
+ args = { variables: variables, version: version }.compact
64
+ args[:table] = table if table
65
+ Evaluation.evaluate(object, **args)
66
+ end
67
+
68
+ module_function :parse, :validate!, :valid?, :parse_cd, :evaluate
42
69
  end
@@ -0,0 +1,17 @@
1
+ # Schema provenance
2
+
3
+ All schemas are vendored verbatim from the OpenMath society's repositories
4
+ (cloned at openmath-reference/ in the workspace) so that validation never
5
+ depends on the network.
6
+
7
+ | File | Source | Notes |
8
+ |---|---|---|
9
+ | `openmath2.rng` | https://github.com/OpenMath/OMSVN, `www/standard/om20-2013-07-11/openmath2.rng` | The OpenMath 2 RelaxNG schema from the standard's second distribution. |
10
+ | `openmath2.rnc` | https://github.com/OpenMath/OMSVN, `formerCVS/OpenMath2/openmath2.rnc` | The same grammar in compact syntax, kept for reference. |
11
+ | `openmath3.rng` | https://github.com/OpenMath/OMSVN, `OpenMath3-effort-2009/rnc/openmath3.rng` | The OpenMath 3 draft schema (2009 effort); includes `om3-common.rng`. |
12
+ | `om3-common.rng` | https://github.com/OpenMath/OMSVN, `OpenMath3-effort-2009/rnc/om3-common.rng` | The OM3 draft's shared grammar. |
13
+
14
+ The object grammars of OpenMath 2 and the OM3 draft are the same shape; the
15
+ version distinction is carried by the document's `version` attribute and the
16
+ gem's versioned class hierarchies. Re-vendoring on an OM3 draft move is a
17
+ deliberate, recorded change.
@@ -0,0 +1,257 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- RELAX NG Schema for OpenMath 3 -->
3
+ <grammar ns="http://www.openmath.org/OpenMath" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
4
+ <!-- OpenMath object constructor -->
5
+ <define name="OMOBJ">
6
+ <element name="OMOBJ">
7
+ <ref name="compound.attributes"/>
8
+ <optional>
9
+ <attribute name="version">
10
+ <data type="string"/>
11
+ </attribute>
12
+ </optional>
13
+ <ref name="omel"/>
14
+ </element>
15
+ </define>
16
+ <!-- Elements which can appear inside an OpenMath object -->
17
+ <define name="omel">
18
+ <choice>
19
+ <ref name="omelBasic"/>
20
+ <ref name="omelDerived"/>
21
+ <ref name="OMR"/>
22
+ </choice>
23
+ </define>
24
+ <define name="omelBasic">
25
+ <choice>
26
+ <ref name="OMS"/>
27
+ <ref name="OMV"/>
28
+ <ref name="OMI"/>
29
+ <ref name="OMB"/>
30
+ <ref name="OMSTR"/>
31
+ <ref name="OMF"/>
32
+ </choice>
33
+ </define>
34
+ <define name="omelDerived">
35
+ <choice>
36
+ <ref name="OMA"/>
37
+ <ref name="OMBIND"/>
38
+ <ref name="OME"/>
39
+ <ref name="OMATTR"/>
40
+ </choice>
41
+ </define>
42
+ <!-- things which can be variables -->
43
+ <define name="omvar">
44
+ <choice>
45
+ <ref name="OMV"/>
46
+ <ref name="attvar"/>
47
+ </choice>
48
+ </define>
49
+ <define name="attvar">
50
+ <element name="OMATTR">
51
+ <ref name="common.attributes"/>
52
+ <group>
53
+ <ref name="OMATP"/>
54
+ <choice>
55
+ <ref name="OMV"/>
56
+ <ref name="attvar"/>
57
+ </choice>
58
+ </group>
59
+ </element>
60
+ </define>
61
+ <!-- attributes common to all elements -->
62
+ <define name="common.attributes">
63
+ <optional>
64
+ <attribute name="id">
65
+ <data type="ID"/>
66
+ </attribute>
67
+ </optional>
68
+ </define>
69
+ <!-- attributes common to all elements that construct compount OM objects. -->
70
+ <define name="cdbase">
71
+ <optional>
72
+ <attribute name="cdbase">
73
+ <data type="anyURI"/>
74
+ </attribute>
75
+ </optional>
76
+ </define>
77
+ <define name="compound.attributes">
78
+ <ref name="common.attributes"/>
79
+ <ref name="cdbase"/>
80
+ </define>
81
+ <!-- symbol -->
82
+ <define name="OMS">
83
+ <element name="OMS">
84
+ <ref name="common.attributes"/>
85
+ <attribute name="name">
86
+ <data type="NCName"/>
87
+ </attribute>
88
+ <attribute name="cd">
89
+ <data type="NCName"/>
90
+ </attribute>
91
+ <ref name="cdbase"/>
92
+ </element>
93
+ </define>
94
+ <!-- variable -->
95
+ <define name="OMV">
96
+ <element name="OMV">
97
+ <ref name="common.attributes"/>
98
+ <attribute name="name">
99
+ <data type="NCName"/>
100
+ </attribute>
101
+ </element>
102
+ </define>
103
+ <!-- integer -->
104
+ <define name="OMI">
105
+ <element name="OMI">
106
+ <ref name="common.attributes"/>
107
+ <data type="string">
108
+ <param name="pattern">\s*(-\s?)?[0-9]+(\s[0-9]+)*\s*</param>
109
+ </data>
110
+ </element>
111
+ </define>
112
+ <!-- byte array -->
113
+ <define name="OMB">
114
+ <element name="OMB">
115
+ <ref name="common.attributes"/>
116
+ <data type="base64Binary"/>
117
+ </element>
118
+ </define>
119
+ <!-- string -->
120
+ <define name="OMSTR">
121
+ <element name="OMSTR">
122
+ <ref name="common.attributes"/>
123
+ <text/>
124
+ </element>
125
+ </define>
126
+ <!-- IEEE floating point number -->
127
+ <define name="OMF">
128
+ <element name="OMF">
129
+ <ref name="common.attributes"/>
130
+ <choice>
131
+ <attribute name="dec">
132
+ <data type="double"/>
133
+ </attribute>
134
+ <attribute name="hex">
135
+ <data type="string">
136
+ <param name="pattern">[0-9A-F]+</param>
137
+ </data>
138
+ </attribute>
139
+ </choice>
140
+ </element>
141
+ </define>
142
+ <!-- apply constructor -->
143
+ <define name="OMA.content">
144
+ <notAllowed/>
145
+ </define>
146
+ <define name="OMA">
147
+ <element name="OMA">
148
+ <ref name="compound.attributes"/>
149
+ <ref name="OMA.content"/>
150
+ </element>
151
+ </define>
152
+ <!-- binding constructor -->
153
+ <define name="OMBIND.content">
154
+ <notAllowed/>
155
+ </define>
156
+ <define name="OMBIND">
157
+ <element name="OMBIND">
158
+ <ref name="compound.attributes"/>
159
+ <ref name="OMBIND.content"/>
160
+ </element>
161
+ </define>
162
+ <!-- variables used in binding constructor -->
163
+ <define name="OMBVAR">
164
+ <element name="OMBVAR">
165
+ <ref name="common.attributes"/>
166
+ <oneOrMore>
167
+ <ref name="omvar"/>
168
+ </oneOrMore>
169
+ </element>
170
+ </define>
171
+ <!-- error constructor -->
172
+ <define name="OME">
173
+ <element name="OME">
174
+ <ref name="common.attributes"/>
175
+ <ref name="OMS"/>
176
+ <zeroOrMore>
177
+ <choice>
178
+ <ref name="omel"/>
179
+ <ref name="OMFOREIGN"/>
180
+ </choice>
181
+ </zeroOrMore>
182
+ </element>
183
+ </define>
184
+ <!-- attribution constructor and attribute pair constructor -->
185
+ <define name="OMATTR">
186
+ <element name="OMATTR">
187
+ <ref name="compound.attributes"/>
188
+ <ref name="OMATP"/>
189
+ <ref name="omel"/>
190
+ </element>
191
+ </define>
192
+ <define name="OMATP">
193
+ <element name="OMATP">
194
+ <ref name="compound.attributes"/>
195
+ <oneOrMore>
196
+ <ref name="OMS"/>
197
+ <choice>
198
+ <ref name="omel"/>
199
+ <ref name="OMFOREIGN"/>
200
+ </choice>
201
+ </oneOrMore>
202
+ </element>
203
+ </define>
204
+ <!-- foreign constructor -->
205
+ <define name="OMFOREIGN">
206
+ <element name="OMFOREIGN">
207
+ <ref name="compound.attributes"/>
208
+ <optional>
209
+ <attribute name="encoding">
210
+ <data type="string"/>
211
+ </attribute>
212
+ </optional>
213
+ <zeroOrMore>
214
+ <choice>
215
+ <ref name="omel"/>
216
+ <ref name="notom"/>
217
+ </choice>
218
+ </zeroOrMore>
219
+ </element>
220
+ </define>
221
+ <!--
222
+ Any elements not in the om namespace
223
+ (valid om is allowed as a descendant)
224
+ -->
225
+ <define name="notom">
226
+ <choice>
227
+ <element>
228
+ <anyName>
229
+ <except>
230
+ <nsName/>
231
+ </except>
232
+ </anyName>
233
+ <zeroOrMore>
234
+ <attribute>
235
+ <anyName/>
236
+ </attribute>
237
+ </zeroOrMore>
238
+ <zeroOrMore>
239
+ <choice>
240
+ <ref name="omel"/>
241
+ <ref name="notom"/>
242
+ </choice>
243
+ </zeroOrMore>
244
+ </element>
245
+ <text/>
246
+ </choice>
247
+ </define>
248
+ <!-- reference constructor -->
249
+ <define name="OMR">
250
+ <element name="OMR">
251
+ <ref name="common.attributes"/>
252
+ <attribute name="href">
253
+ <data type="anyURI"/>
254
+ </attribute>
255
+ </element>
256
+ </define>
257
+ </grammar>
data/schemas/omcd2.rng ADDED
@@ -0,0 +1,180 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ *********************************************
4
+
5
+ Relax NG Schema for OpenMath CD
6
+
7
+ *********************************************
8
+ -->
9
+ <grammar ns="http://www.openmath.org/OpenMathCD" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
10
+ <include href="openmath2.rng">
11
+ <start>
12
+ <ref name="CD"/>
13
+ </start>
14
+ </include>
15
+ <define name="CDComment">
16
+ <element name="CDComment">
17
+ <text/>
18
+ </element>
19
+ </define>
20
+ <define name="CDName">
21
+ <element name="CDName">
22
+ <data type="NCName"/>
23
+ </element>
24
+ </define>
25
+ <define name="CDUses">
26
+ <element name="CDUses">
27
+ <zeroOrMore>
28
+ <ref name="CDName"/>
29
+ </zeroOrMore>
30
+ </element>
31
+ </define>
32
+ <define name="CDURL">
33
+ <element name="CDURL">
34
+ <data type="anyURI"/>
35
+ </element>
36
+ </define>
37
+ <define name="CDBase">
38
+ <element name="CDBase">
39
+ <data type="anyURI"/>
40
+ </element>
41
+ </define>
42
+ <define name="text-or-om">
43
+ <zeroOrMore>
44
+ <choice>
45
+ <text/>
46
+ <ref name="OMOBJ"/>
47
+ </choice>
48
+ </zeroOrMore>
49
+ </define>
50
+ <define name="CDReviewDate">
51
+ <element name="CDReviewDate">
52
+ <data type="date"/>
53
+ </element>
54
+ </define>
55
+ <define name="CDDate">
56
+ <element name="CDDate">
57
+ <data type="date"/>
58
+ </element>
59
+ </define>
60
+ <define name="CDVersion">
61
+ <element name="CDVersion">
62
+ <data type="nonNegativeInteger"/>
63
+ </element>
64
+ </define>
65
+ <define name="CDRevision">
66
+ <element name="CDRevision">
67
+ <data type="nonNegativeInteger"/>
68
+ </element>
69
+ </define>
70
+ <define name="CDStatus">
71
+ <element name="CDStatus">
72
+ <choice>
73
+ <value>official</value>
74
+ <value>experimental</value>
75
+ <value>private</value>
76
+ <value>obsolete</value>
77
+ </choice>
78
+ </element>
79
+ </define>
80
+ <define name="Description">
81
+ <element name="Description">
82
+ <text/>
83
+ </element>
84
+ </define>
85
+ <define name="Name">
86
+ <element name="Name">
87
+ <data type="NCName"/>
88
+ </element>
89
+ </define>
90
+ <define name="Role">
91
+ <element name="Role">
92
+ <choice>
93
+ <value>binder</value>
94
+ <value>attribution</value>
95
+ <value>semantic-attribution</value>
96
+ <value>error</value>
97
+ <value>application</value>
98
+ <value>constant</value>
99
+ </choice>
100
+ </element>
101
+ </define>
102
+ <define name="CMP">
103
+ <element name="CMP">
104
+ <text/>
105
+ </element>
106
+ </define>
107
+ <define name="FMP">
108
+ <element name="FMP">
109
+ <optional>
110
+ <attribute name="kind">
111
+ <data type="string"/>
112
+ </attribute>
113
+ </optional>
114
+ <ref name="OMOBJ"/>
115
+ </element>
116
+ </define>
117
+ <!-- allow embedded OM -->
118
+ <define name="Example">
119
+ <element name="Example">
120
+ <ref name="text-or-om"/>
121
+ </element>
122
+ </define>
123
+ <define name="CDDefinition">
124
+ <element name="CDDefinition">
125
+ <zeroOrMore>
126
+ <ref name="CDComment"/>
127
+ </zeroOrMore>
128
+ <interleave>
129
+ <ref name="Name"/>
130
+ <optional>
131
+ <ref name="Role"/>
132
+ </optional>
133
+ <ref name="Description"/>
134
+ </interleave>
135
+ <zeroOrMore>
136
+ <choice>
137
+ <ref name="CDComment"/>
138
+ <ref name="Example"/>
139
+ <ref name="FMP"/>
140
+ <ref name="CMP"/>
141
+ </choice>
142
+ </zeroOrMore>
143
+ </element>
144
+ </define>
145
+ <define name="CD">
146
+ <element name="CD">
147
+ <interleave>
148
+ <zeroOrMore>
149
+ <ref name="CDComment"/>
150
+ </zeroOrMore>
151
+ <optional>
152
+ <ref name="Description"/>
153
+ </optional>
154
+ <ref name="CDName"/>
155
+ <optional>
156
+ <ref name="CDURL"/>
157
+ </optional>
158
+ <optional>
159
+ <ref name="CDBase"/>
160
+ </optional>
161
+ <optional>
162
+ <ref name="CDReviewDate"/>
163
+ </optional>
164
+ <ref name="CDDate"/>
165
+ <ref name="CDStatus"/>
166
+ <optional>
167
+ <ref name="CDUses"/>
168
+ </optional>
169
+ <ref name="CDVersion"/>
170
+ <ref name="CDRevision"/>
171
+ </interleave>
172
+ <oneOrMore>
173
+ <ref name="CDDefinition"/>
174
+ <zeroOrMore>
175
+ <ref name="CDComment"/>
176
+ </zeroOrMore>
177
+ </oneOrMore>
178
+ </element>
179
+ </define>
180
+ </grammar>
@@ -0,0 +1,88 @@
1
+ # RELAX NG Schema for OpenMath 2
2
+
3
+
4
+ default namespace om = "http://www.openmath.org/OpenMath"
5
+
6
+ start = OMOBJ
7
+
8
+ # OpenMath object constructor
9
+ OMOBJ = element OMOBJ { compound.attributes,
10
+ attribute version { xsd:string }?,
11
+ omel }
12
+
13
+
14
+ # Elements which can appear inside an OpenMath object
15
+ omel =
16
+ OMS | OMV | OMI | OMB | OMSTR | OMF | OMA | OMBIND | OME | OMATTR |OMR
17
+
18
+ # things which can be variables
19
+ omvar = OMV | attvar
20
+
21
+ attvar = element OMATTR { common.attributes,(OMATP , (OMV | attvar))}
22
+
23
+
24
+ cdbase = attribute cdbase { xsd:anyURI}?
25
+
26
+ # attributes common to all elements
27
+ common.attributes = (attribute id { xsd:ID })?
28
+
29
+ # attributes common to all elements that construct compount OM objects.
30
+ compound.attributes = common.attributes,cdbase
31
+
32
+ # symbol
33
+ OMS = element OMS { common.attributes,
34
+ attribute name { xsd:NCName},
35
+ attribute cd { xsd:NCName},
36
+ cdbase }
37
+
38
+ # variable
39
+ OMV = element OMV { common.attributes,
40
+ attribute name { xsd:NCName} }
41
+
42
+ # integer
43
+ OMI = element OMI { common.attributes,
44
+ xsd:string {pattern = "\s*(-\s?)?[0-9]+(\s[0-9]+)*\s*"}}
45
+ # byte array
46
+ OMB = element OMB { common.attributes, xsd:base64Binary }
47
+
48
+ # string
49
+ OMSTR = element OMSTR { common.attributes, text }
50
+
51
+ # IEEE floating point number
52
+ OMF = element OMF { common.attributes,
53
+ ( attribute dec { xsd:double } |
54
+ attribute hex { xsd:string {pattern = "[0-9A-F]+"}}) }
55
+
56
+ # apply constructor
57
+ OMA = element OMA { compound.attributes, omel+ }
58
+
59
+ # binding constructor
60
+ OMBIND = element OMBIND { compound.attributes, omel, OMBVAR, omel }
61
+
62
+ # variables used in binding constructor
63
+ OMBVAR = element OMBVAR { common.attributes, omvar+ }
64
+
65
+ # error constructor
66
+ OME = element OME { common.attributes, OMS, (omel|OMFOREIGN)* }
67
+
68
+ # attribution constructor and attribute pair constructor
69
+ OMATTR = element OMATTR { compound.attributes, OMATP, omel }
70
+
71
+ OMATP = element OMATP { compound.attributes, (OMS, (omel | OMFOREIGN) )+ }
72
+
73
+ # foreign constructor
74
+ OMFOREIGN = element OMFOREIGN {
75
+ compound.attributes, attribute encoding {xsd:string}?,
76
+ (omel|notom)* }
77
+
78
+ # Any elements not in the om namespace
79
+ # (valid om is allowed as a descendant)
80
+ notom =
81
+ (element * - om:* {attribute * { text }*,(omel|notom)*}
82
+ | text)
83
+
84
+ # reference constructor
85
+ OMR = element OMR { common.attributes,
86
+ attribute href { xsd:anyURI }
87
+ }
88
+