openmath 0.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE.md +33 -0
- data/README.adoc +57 -0
- data/lib/openmath/base/common.rb +15 -0
- data/lib/openmath/base/compound.rb +18 -0
- data/lib/openmath/base/oma.rb +20 -0
- data/lib/openmath/base/omatp.rb +21 -0
- data/lib/openmath/base/omattr.rb +20 -0
- data/lib/openmath/base/omb.rb +22 -0
- data/lib/openmath/base/ombind.rb +20 -0
- data/lib/openmath/base/ombvar.rb +20 -0
- data/lib/openmath/base/ome.rb +20 -0
- data/lib/openmath/base/omf.rb +24 -0
- data/lib/openmath/base/omforeign.rb +26 -0
- data/lib/openmath/base/omi.rb +24 -0
- data/lib/openmath/base/omobj.rb +24 -0
- data/lib/openmath/base/omr.rb +22 -0
- data/lib/openmath/base/oms.rb +27 -0
- data/lib/openmath/base/omstr.rb +22 -0
- data/lib/openmath/base/omv.rb +21 -0
- data/lib/openmath/common_elements.rb +11 -0
- data/lib/openmath/namespace.rb +13 -0
- data/lib/openmath/v2/common_elements.rb +49 -0
- data/lib/openmath/v2/configuration.rb +35 -0
- data/lib/openmath/v2/oma.rb +9 -0
- data/lib/openmath/v2/omatp.rb +9 -0
- data/lib/openmath/v2/omattr.rb +9 -0
- data/lib/openmath/v2/omb.rb +9 -0
- data/lib/openmath/v2/ombind.rb +9 -0
- data/lib/openmath/v2/ombvar.rb +9 -0
- data/lib/openmath/v2/ome.rb +9 -0
- data/lib/openmath/v2/omf.rb +9 -0
- data/lib/openmath/v2/omforeign.rb +9 -0
- data/lib/openmath/v2/omi.rb +9 -0
- data/lib/openmath/v2/omobj.rb +9 -0
- data/lib/openmath/v2/omr.rb +9 -0
- data/lib/openmath/v2/oms.rb +9 -0
- data/lib/openmath/v2/omstr.rb +9 -0
- data/lib/openmath/v2/omv.rb +9 -0
- data/lib/openmath/v2.rb +54 -0
- data/lib/openmath/version.rb +5 -0
- data/lib/openmath.rb +42 -0
- metadata +119 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f92e3382228d53dfb3a626b4b03f7886d9fd7398a7740712c04af80b2f02388b
|
|
4
|
+
data.tar.gz: a8ae3e8694ded73aa8af782e9c9cf0275e7cd678cea6c707f5c72c12d85bb414
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1139b059df8e96ec61e64b3e46823517d792cbc308fc48fb384250b56f45d9bbd43d5436a453ec7258966fac3ad784ca579e570d8503aafc2422afac4eca9f8b
|
|
7
|
+
data.tar.gz: e356ac24eac85b3086e675ed42f9c31300bfcc25c7906c5069bd1aa8cb59b2a648e1be8f3d532e225920dad35b3ae0c9a8f2b44036e3cba5f1f7d61a2fff7b40
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Licenses & Copyright
|
|
2
|
+
====================
|
|
3
|
+
|
|
4
|
+
This license file adheres to the formatting guidelines of
|
|
5
|
+
[readable-licenses](https://github.com/nevir/readable-licenses).
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Ribose's BSD 2-Clause License
|
|
9
|
+
-----------------------------
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026, [Ribose Inc](https://www.ribose.com).
|
|
12
|
+
All rights reserved.
|
|
13
|
+
|
|
14
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
15
|
+
are permitted provided that the following conditions are met:
|
|
16
|
+
|
|
17
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
18
|
+
this list of conditions and the following disclaimer.
|
|
19
|
+
|
|
20
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
21
|
+
this list of conditions and the following disclaimer in the documentation
|
|
22
|
+
and/or other materials provided with the distribution.
|
|
23
|
+
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
25
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
26
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
28
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
29
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
32
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
= OpenMath
|
|
2
|
+
|
|
3
|
+
OpenMath 2 (the published standard) and OpenMath 3 (the draft) as a typed
|
|
4
|
+
Ruby model: parse the XML encoding, serialize it back, and evaluate through
|
|
5
|
+
content dictionaries. Part of the {plurimath}[https://github.com/plurimath]
|
|
6
|
+
ecosystem; consumed by the plurimath gem.
|
|
7
|
+
|
|
8
|
+
== Status (0.1.0)
|
|
9
|
+
|
|
10
|
+
The complete OpenMath 2 object grammar — OMOBJ, OMS, OMV, OMI, OMB, OMSTR,
|
|
11
|
+
OMF, OMA, OMBIND, OMBVAR, OME, OMATTR, OMATP, OMFOREIGN, OMR — modeled with
|
|
12
|
+
{LutaML Model}[https://github.com/lutaml/lutaml-model] against the
|
|
13
|
+
authoritative schema (`schemas/openmath2.rnc`, vendored from
|
|
14
|
+
OpenMath/OMSVN). Namespaced documents parse in both the unprefixed and the
|
|
15
|
+
`om:`-prefixed form; round trips are byte-stable.
|
|
16
|
+
|
|
17
|
+
Known limitations (tracked in the issues):
|
|
18
|
+
|
|
19
|
+
* OpenMath 3 is scaffolded, not modeled — its versioned hierarchy lands
|
|
20
|
+
with the draft revision it implements (plurimath#582).
|
|
21
|
+
* Root-element and schema validation are roadmap work; the reader is
|
|
22
|
+
lenient about unknown roots.
|
|
23
|
+
* Non-OpenMath markup inside OMFOREIGN is not yet represented.
|
|
24
|
+
|
|
25
|
+
== Usage
|
|
26
|
+
|
|
27
|
+
[source,ruby]
|
|
28
|
+
----
|
|
29
|
+
require "openmath"
|
|
30
|
+
|
|
31
|
+
object = Openmath.parse(<<~XML, version: 2)
|
|
32
|
+
<OMOBJ xmlns="http://www.openmath.org/OpenMath">
|
|
33
|
+
<OMA><OMS cd="arith1" name="plus"/><OMI>1</OMI><OMI>1</OMI></OMA>
|
|
34
|
+
</OMOBJ>
|
|
35
|
+
XML
|
|
36
|
+
|
|
37
|
+
object.oma_value.first.omi_value.map { |i| i.value.first.strip }
|
|
38
|
+
# => ["1", "1"]
|
|
39
|
+
|
|
40
|
+
puts object.to_xml
|
|
41
|
+
----
|
|
42
|
+
|
|
43
|
+
== Roadmap
|
|
44
|
+
|
|
45
|
+
The semantic program: content dictionaries bind symbols to evaluated
|
|
46
|
+
operations (the Plurimath PM-series evaluator), the official CD collection
|
|
47
|
+
loads as data, and the test suites of other implementations join the
|
|
48
|
+
{plurimath-testsuite}[https://github.com/plurimath/plurimath-testsuite]
|
|
49
|
+
under the provenance discipline. Tracked in plurimath#582 (the gem),
|
|
50
|
+
#583 (evaluation), #584 (the testsuite stage), #585 (the wiring).
|
|
51
|
+
|
|
52
|
+
== Development
|
|
53
|
+
|
|
54
|
+
----
|
|
55
|
+
bundle install
|
|
56
|
+
bundle exec rake
|
|
57
|
+
----
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# Attributes common to all OpenMath 2 elements: the optional id.
|
|
6
|
+
module Common
|
|
7
|
+
def self.included(klass)
|
|
8
|
+
klass.class_eval do
|
|
9
|
+
attribute :id, :string
|
|
10
|
+
xml { map_attribute "id", to: :id }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# Attributes common to all elements that construct compound objects:
|
|
6
|
+
# id plus the optional cdbase.
|
|
7
|
+
module Compound
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Common
|
|
11
|
+
|
|
12
|
+
attribute :cdbase, :string
|
|
13
|
+
xml { map_attribute "cdbase", to: :cdbase }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# An application: <OMA><OMS cd="arith1" name="plus"/> ...args</OMA>
|
|
6
|
+
# (schema: compound attributes, omel+; the first child is the operator).
|
|
7
|
+
module Oma
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Compound
|
|
11
|
+
|
|
12
|
+
xml do
|
|
13
|
+
element "OMA"
|
|
14
|
+
ordered
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# An attribute-pair list: <OMATP><OMS .../> <value/> ...</OMATP>
|
|
6
|
+
# (schema: compound attributes, (OMS, value)+ — the pairs alternate, and
|
|
7
|
+
# the document order is the pairing).
|
|
8
|
+
module Omatp
|
|
9
|
+
def self.included(klass)
|
|
10
|
+
klass.class_eval do
|
|
11
|
+
include Openmath::Base::Compound
|
|
12
|
+
|
|
13
|
+
xml do
|
|
14
|
+
element "OMATP"
|
|
15
|
+
ordered
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# An attributed object: <OMATTR><OMATP>...</OMATP> <object/></OMATTR>
|
|
6
|
+
# (schema: compound attributes, OMATP, omel).
|
|
7
|
+
module Omattr
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Compound
|
|
11
|
+
|
|
12
|
+
xml do
|
|
13
|
+
element "OMATTR"
|
|
14
|
+
ordered
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# A byte array: <OMB>base64</OMB> (schema: xsd:base64Binary content).
|
|
6
|
+
module Omb
|
|
7
|
+
def self.included(klass)
|
|
8
|
+
klass.class_eval do
|
|
9
|
+
include Openmath::Base::Common
|
|
10
|
+
|
|
11
|
+
attribute :value, :string, collection: true
|
|
12
|
+
|
|
13
|
+
xml do
|
|
14
|
+
element "OMB"
|
|
15
|
+
mixed_content
|
|
16
|
+
map_content to: :value
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# A binding: <OMBIND><head/> <OMBVAR>...</OMBVAR> <body/></OMBIND>
|
|
6
|
+
# (schema: compound attributes, omel, OMBVAR, omel — head, binder, body).
|
|
7
|
+
module Ombind
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Compound
|
|
11
|
+
|
|
12
|
+
xml do
|
|
13
|
+
element "OMBIND"
|
|
14
|
+
ordered
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# The binding-variable container: <OMBVAR><OMV .../>...</OMBVAR>
|
|
6
|
+
# (schema: common attributes, omvar+ where omvar = OMV | attributed OMV).
|
|
7
|
+
module Ombvar
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Common
|
|
11
|
+
|
|
12
|
+
xml do
|
|
13
|
+
element "OMBVAR"
|
|
14
|
+
ordered
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# An error: <OME><OMS cd="..." name="..."/> ...content</OME>
|
|
6
|
+
# (schema: common attributes, one leading OMS, then objects or foreign).
|
|
7
|
+
module Ome
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Common
|
|
11
|
+
|
|
12
|
+
xml do
|
|
13
|
+
element "OME"
|
|
14
|
+
ordered
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# An IEEE floating-point literal: <OMF dec="0.5"/> or
|
|
6
|
+
# <OMF hex="4008000000000000"/> (schema: exactly one of dec or hex).
|
|
7
|
+
module Omf
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Common
|
|
11
|
+
|
|
12
|
+
attribute :dec, :string
|
|
13
|
+
attribute :hex, :string
|
|
14
|
+
|
|
15
|
+
xml do
|
|
16
|
+
element "OMF"
|
|
17
|
+
map_attribute "dec", to: :dec
|
|
18
|
+
map_attribute "hex", to: :hex
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# A foreign object: <OMFOREIGN encoding="...">...</OMFOREIGN>
|
|
6
|
+
# (schema: compound attributes, optional encoding, then OpenMath children
|
|
7
|
+
# and foreign markup. This release models the OpenMath children and the
|
|
8
|
+
# encoding; non-OpenMath markup inside is not yet represented — see the
|
|
9
|
+
# roadmap issue.)
|
|
10
|
+
module Omforeign
|
|
11
|
+
def self.included(klass)
|
|
12
|
+
klass.class_eval do
|
|
13
|
+
include Openmath::Base::Compound
|
|
14
|
+
|
|
15
|
+
attribute :foreign_encoding, :string
|
|
16
|
+
|
|
17
|
+
xml do
|
|
18
|
+
element "OMFOREIGN"
|
|
19
|
+
ordered
|
|
20
|
+
map_attribute "encoding", to: :foreign_encoding
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# An integer literal: <OMI>10</OMI>. The schema pattern allows digit
|
|
6
|
+
# groups separated by single spaces ("1 000 000"), so the text is held
|
|
7
|
+
# as written.
|
|
8
|
+
module Omi
|
|
9
|
+
def self.included(klass)
|
|
10
|
+
klass.class_eval do
|
|
11
|
+
include Openmath::Base::Common
|
|
12
|
+
|
|
13
|
+
attribute :value, :string, collection: true
|
|
14
|
+
|
|
15
|
+
xml do
|
|
16
|
+
element "OMI"
|
|
17
|
+
mixed_content
|
|
18
|
+
map_content to: :value
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# The OpenMath object root:
|
|
6
|
+
# <OMOBJ cdbase="..." version="2.0"> ... </OMOBJ>
|
|
7
|
+
# (schema: compound attributes, optional version, one object element).
|
|
8
|
+
module Omobj
|
|
9
|
+
def self.included(klass)
|
|
10
|
+
klass.class_eval do
|
|
11
|
+
include Openmath::Base::Compound
|
|
12
|
+
|
|
13
|
+
attribute :version, :string
|
|
14
|
+
|
|
15
|
+
xml do
|
|
16
|
+
element "OMOBJ"
|
|
17
|
+
ordered
|
|
18
|
+
map_attribute "version", to: :version
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# A reference: <OMR href="#id"/> (schema: common attributes + href
|
|
6
|
+
# anyURI).
|
|
7
|
+
module Omr
|
|
8
|
+
def self.included(klass)
|
|
9
|
+
klass.class_eval do
|
|
10
|
+
include Openmath::Base::Common
|
|
11
|
+
|
|
12
|
+
attribute :href, :string
|
|
13
|
+
|
|
14
|
+
xml do
|
|
15
|
+
element "OMR"
|
|
16
|
+
map_attribute "href", to: :href
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# A symbol from a content dictionary:
|
|
6
|
+
# <OMS cd="arith1" name="plus"/> (schema: name and cd required NCNames,
|
|
7
|
+
# plus the optional id and cdbase).
|
|
8
|
+
module Oms
|
|
9
|
+
def self.included(klass)
|
|
10
|
+
klass.class_eval do
|
|
11
|
+
include Openmath::Base::Common
|
|
12
|
+
|
|
13
|
+
attribute :name, :string
|
|
14
|
+
attribute :cd, :string
|
|
15
|
+
attribute :cdbase, :string
|
|
16
|
+
|
|
17
|
+
xml do
|
|
18
|
+
element "OMS"
|
|
19
|
+
map_attribute "name", to: :name
|
|
20
|
+
map_attribute "cd", to: :cd
|
|
21
|
+
map_attribute "cdbase", to: :cdbase
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# A string: <OMSTR>text</OMSTR> (schema: text content).
|
|
6
|
+
module Omstr
|
|
7
|
+
def self.included(klass)
|
|
8
|
+
klass.class_eval do
|
|
9
|
+
include Openmath::Base::Common
|
|
10
|
+
|
|
11
|
+
attribute :value, :string, collection: true
|
|
12
|
+
|
|
13
|
+
xml do
|
|
14
|
+
element "OMSTR"
|
|
15
|
+
mixed_content
|
|
16
|
+
map_content to: :value
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module Base
|
|
5
|
+
# A variable: <OMV name="x"/> (schema: required name NCName, id).
|
|
6
|
+
module Omv
|
|
7
|
+
def self.included(klass)
|
|
8
|
+
klass.class_eval do
|
|
9
|
+
include Openmath::Base::Common
|
|
10
|
+
|
|
11
|
+
attribute :name, :string
|
|
12
|
+
|
|
13
|
+
xml do
|
|
14
|
+
element "OMV"
|
|
15
|
+
map_attribute "name", to: :name
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model"
|
|
4
|
+
|
|
5
|
+
module Openmath
|
|
6
|
+
# The root of every OpenMath element class hierarchy. Version-scoped
|
|
7
|
+
# subclasses (e.g. Openmath::V2::CommonElements) declare the child object
|
|
8
|
+
# collections and their element maps for their version's grammar.
|
|
9
|
+
class CommonElements < Lutaml::Model::Serializable
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model"
|
|
4
|
+
|
|
5
|
+
module Openmath
|
|
6
|
+
# The OpenMath XML namespace: http://www.openmath.org/OpenMath.
|
|
7
|
+
# Documents may use it unprefixed (the default form) or with a prefix
|
|
8
|
+
# such as om:.
|
|
9
|
+
class Namespace < Lutaml::Xml::Namespace
|
|
10
|
+
uri "http://www.openmath.org/OpenMath"
|
|
11
|
+
prefix_default "om"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module V2
|
|
5
|
+
# The shared parent of the OpenMath 2 element classes: the child object
|
|
6
|
+
# collections and their element maps, modeled from schemas/openmath2.rnc
|
|
7
|
+
# (the OpenMath 2 RelaxNG schema, vendored from OpenMath/OMSVN). Child
|
|
8
|
+
# types are declared as symbols resolved through this version's
|
|
9
|
+
# registered models.
|
|
10
|
+
class CommonElements < Openmath::CommonElements
|
|
11
|
+
def self.lutaml_default_register
|
|
12
|
+
Configuration::CONTEXT_ID
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
attribute :oms_value, :oms, collection: true
|
|
16
|
+
attribute :omv_value, :omv, collection: true
|
|
17
|
+
attribute :omi_value, :omi, collection: true
|
|
18
|
+
attribute :omb_value, :omb, collection: true
|
|
19
|
+
attribute :omstr_value, :omstr, collection: true
|
|
20
|
+
attribute :omf_value, :omf, collection: true
|
|
21
|
+
attribute :oma_value, :oma, collection: true
|
|
22
|
+
attribute :ombind_value, :ombind, collection: true
|
|
23
|
+
attribute :ombvar_value, :ombvar, collection: true
|
|
24
|
+
attribute :ome_value, :ome, collection: true
|
|
25
|
+
attribute :omattr_value, :omattr, collection: true
|
|
26
|
+
attribute :omatp_value, :omatp, collection: true
|
|
27
|
+
attribute :omforeign_value, :omforeign, collection: true
|
|
28
|
+
attribute :omr_value, :omr, collection: true
|
|
29
|
+
|
|
30
|
+
xml do
|
|
31
|
+
namespace Openmath::Namespace
|
|
32
|
+
map_element "OMS", to: :oms_value
|
|
33
|
+
map_element "OMV", to: :omv_value
|
|
34
|
+
map_element "OMI", to: :omi_value
|
|
35
|
+
map_element "OMB", to: :omb_value
|
|
36
|
+
map_element "OMSTR", to: :omstr_value
|
|
37
|
+
map_element "OMF", to: :omf_value
|
|
38
|
+
map_element "OMA", to: :oma_value
|
|
39
|
+
map_element "OMBIND", to: :ombind_value
|
|
40
|
+
map_element "OMBVAR", to: :ombvar_value
|
|
41
|
+
map_element "OME", to: :ome_value
|
|
42
|
+
map_element "OMATTR", to: :omattr_value
|
|
43
|
+
map_element "OMATP", to: :omatp_value
|
|
44
|
+
map_element "OMFOREIGN", to: :omforeign_value
|
|
45
|
+
map_element "OMR", to: :omr_value
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
module V2
|
|
5
|
+
# Registers the version's element classes under this version's LutaML
|
|
6
|
+
# context, so the symbol-typed child attributes resolve (the Mml
|
|
7
|
+
# pattern).
|
|
8
|
+
module Configuration
|
|
9
|
+
CONTEXT_ID = :openmath_v2
|
|
10
|
+
|
|
11
|
+
extend self
|
|
12
|
+
|
|
13
|
+
def context
|
|
14
|
+
Lutaml::Model::GlobalContext.context(CONTEXT_ID) || create_context!
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def register_model(klass, id:)
|
|
18
|
+
create_context! unless Lutaml::Model::GlobalContext.context(CONTEXT_ID)
|
|
19
|
+
Lutaml::Model::GlobalContext.context(CONTEXT_ID)
|
|
20
|
+
.registry.register(id.to_sym, klass)
|
|
21
|
+
klass
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_context!
|
|
25
|
+
Lutaml::Model::GlobalContext.register_context(
|
|
26
|
+
Lutaml::Model::TypeContext.new(
|
|
27
|
+
id: CONTEXT_ID,
|
|
28
|
+
registry: Lutaml::Model::TypeRegistry.new,
|
|
29
|
+
),
|
|
30
|
+
)
|
|
31
|
+
Lutaml::Model::GlobalContext.context(CONTEXT_ID)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/openmath/v2.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Openmath
|
|
4
|
+
# OpenMath 2: the published standard (2004).
|
|
5
|
+
module V2
|
|
6
|
+
autoload :Configuration, "openmath/v2/configuration"
|
|
7
|
+
autoload :CommonElements, "openmath/v2/common_elements"
|
|
8
|
+
autoload :Oms, "openmath/v2/oms"
|
|
9
|
+
autoload :Omv, "openmath/v2/omv"
|
|
10
|
+
autoload :Omi, "openmath/v2/omi"
|
|
11
|
+
autoload :Omb, "openmath/v2/omb"
|
|
12
|
+
autoload :Omstr, "openmath/v2/omstr"
|
|
13
|
+
autoload :Omf, "openmath/v2/omf"
|
|
14
|
+
autoload :Oma, "openmath/v2/oma"
|
|
15
|
+
autoload :Ombind, "openmath/v2/ombind"
|
|
16
|
+
autoload :Ombvar, "openmath/v2/ombvar"
|
|
17
|
+
autoload :Ome, "openmath/v2/ome"
|
|
18
|
+
autoload :Omattr, "openmath/v2/omattr"
|
|
19
|
+
autoload :Omatp, "openmath/v2/omatp"
|
|
20
|
+
autoload :Omr, "openmath/v2/omr"
|
|
21
|
+
autoload :Omforeign, "openmath/v2/omforeign"
|
|
22
|
+
autoload :Omobj, "openmath/v2/omobj"
|
|
23
|
+
|
|
24
|
+
module_function
|
|
25
|
+
|
|
26
|
+
# Registers every element class with this version's context, once per
|
|
27
|
+
# process (the Mml::VersionedParser pattern).
|
|
28
|
+
def register_models!
|
|
29
|
+
return if @registered
|
|
30
|
+
|
|
31
|
+
Configuration.register_model(Oms, id: :oms)
|
|
32
|
+
Configuration.register_model(Omv, id: :omv)
|
|
33
|
+
Configuration.register_model(Omi, id: :omi)
|
|
34
|
+
Configuration.register_model(Omb, id: :omb)
|
|
35
|
+
Configuration.register_model(Omstr, id: :omstr)
|
|
36
|
+
Configuration.register_model(Omf, id: :omf)
|
|
37
|
+
Configuration.register_model(Oma, id: :oma)
|
|
38
|
+
Configuration.register_model(Ombind, id: :ombind)
|
|
39
|
+
Configuration.register_model(Ombvar, id: :ombvar)
|
|
40
|
+
Configuration.register_model(Ome, id: :ome)
|
|
41
|
+
Configuration.register_model(Omattr, id: :omattr)
|
|
42
|
+
Configuration.register_model(Omatp, id: :omatp)
|
|
43
|
+
Configuration.register_model(Omforeign, id: :omforeign)
|
|
44
|
+
Configuration.register_model(Omr, id: :omr)
|
|
45
|
+
Configuration.register_model(Omobj, id: :omobj)
|
|
46
|
+
@registered = true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def parse(input)
|
|
50
|
+
register_models!
|
|
51
|
+
Omobj.from_xml(input)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/openmath.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model"
|
|
4
|
+
|
|
5
|
+
module Openmath
|
|
6
|
+
autoload :VERSION, "openmath/version"
|
|
7
|
+
autoload :CommonElements, "openmath/common_elements"
|
|
8
|
+
autoload :Namespace, "openmath/namespace"
|
|
9
|
+
autoload :V2, "openmath/v2"
|
|
10
|
+
|
|
11
|
+
module Base
|
|
12
|
+
autoload :Oms, "openmath/base/oms"
|
|
13
|
+
autoload :Omv, "openmath/base/omv"
|
|
14
|
+
autoload :Omi, "openmath/base/omi"
|
|
15
|
+
autoload :Omf, "openmath/base/omf"
|
|
16
|
+
autoload :Oma, "openmath/base/oma"
|
|
17
|
+
autoload :Ombind, "openmath/base/ombind"
|
|
18
|
+
autoload :Omb, "openmath/base/omb"
|
|
19
|
+
autoload :Omstr, "openmath/base/omstr"
|
|
20
|
+
autoload :Ombvar, "openmath/base/ombvar"
|
|
21
|
+
autoload :Ome, "openmath/base/ome"
|
|
22
|
+
autoload :Omattr, "openmath/base/omattr"
|
|
23
|
+
autoload :Omatp, "openmath/base/omatp"
|
|
24
|
+
autoload :Omr, "openmath/base/omr"
|
|
25
|
+
autoload :Omforeign, "openmath/base/omforeign"
|
|
26
|
+
autoload :Common, "openmath/base/common"
|
|
27
|
+
autoload :Compound, "openmath/base/compound"
|
|
28
|
+
autoload :Omobj, "openmath/base/omobj"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Parses an OpenMath XML document into the typed model of the requested
|
|
32
|
+
# version. OpenMath 2 is the published standard; OpenMath 3 arrives with
|
|
33
|
+
# its own versioned hierarchy (plurimath/plurimath#582).
|
|
34
|
+
def parse(input, version: 2)
|
|
35
|
+
case version
|
|
36
|
+
when 2 then V2.parse(input)
|
|
37
|
+
else raise ArgumentError, "unsupported OpenMath version #{version.inspect}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
module_function :parse
|
|
42
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: openmath
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ribose Inc.
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: lutaml-model
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.8'
|
|
19
|
+
- - ">="
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.8.162
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0.8'
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: 0.8.162
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: moxml
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - "~>"
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 0.6.1
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - "~>"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 0.6.1
|
|
46
|
+
description: |
|
|
47
|
+
OpenMath 2 and OpenMath 3 XML encoding parsed into a typed model
|
|
48
|
+
declared with LutaML Model, with content-dictionary-aware semantics.
|
|
49
|
+
Used by Plurimath.
|
|
50
|
+
email:
|
|
51
|
+
- open.source@ribose.com
|
|
52
|
+
executables: []
|
|
53
|
+
extensions: []
|
|
54
|
+
extra_rdoc_files: []
|
|
55
|
+
files:
|
|
56
|
+
- LICENSE.md
|
|
57
|
+
- README.adoc
|
|
58
|
+
- lib/openmath.rb
|
|
59
|
+
- lib/openmath/base/common.rb
|
|
60
|
+
- lib/openmath/base/compound.rb
|
|
61
|
+
- lib/openmath/base/oma.rb
|
|
62
|
+
- lib/openmath/base/omatp.rb
|
|
63
|
+
- lib/openmath/base/omattr.rb
|
|
64
|
+
- lib/openmath/base/omb.rb
|
|
65
|
+
- lib/openmath/base/ombind.rb
|
|
66
|
+
- lib/openmath/base/ombvar.rb
|
|
67
|
+
- lib/openmath/base/ome.rb
|
|
68
|
+
- lib/openmath/base/omf.rb
|
|
69
|
+
- lib/openmath/base/omforeign.rb
|
|
70
|
+
- lib/openmath/base/omi.rb
|
|
71
|
+
- lib/openmath/base/omobj.rb
|
|
72
|
+
- lib/openmath/base/omr.rb
|
|
73
|
+
- lib/openmath/base/oms.rb
|
|
74
|
+
- lib/openmath/base/omstr.rb
|
|
75
|
+
- lib/openmath/base/omv.rb
|
|
76
|
+
- lib/openmath/common_elements.rb
|
|
77
|
+
- lib/openmath/namespace.rb
|
|
78
|
+
- lib/openmath/v2.rb
|
|
79
|
+
- lib/openmath/v2/common_elements.rb
|
|
80
|
+
- lib/openmath/v2/configuration.rb
|
|
81
|
+
- lib/openmath/v2/oma.rb
|
|
82
|
+
- lib/openmath/v2/omatp.rb
|
|
83
|
+
- lib/openmath/v2/omattr.rb
|
|
84
|
+
- lib/openmath/v2/omb.rb
|
|
85
|
+
- lib/openmath/v2/ombind.rb
|
|
86
|
+
- lib/openmath/v2/ombvar.rb
|
|
87
|
+
- lib/openmath/v2/ome.rb
|
|
88
|
+
- lib/openmath/v2/omf.rb
|
|
89
|
+
- lib/openmath/v2/omforeign.rb
|
|
90
|
+
- lib/openmath/v2/omi.rb
|
|
91
|
+
- lib/openmath/v2/omobj.rb
|
|
92
|
+
- lib/openmath/v2/omr.rb
|
|
93
|
+
- lib/openmath/v2/oms.rb
|
|
94
|
+
- lib/openmath/v2/omstr.rb
|
|
95
|
+
- lib/openmath/v2/omv.rb
|
|
96
|
+
- lib/openmath/version.rb
|
|
97
|
+
homepage: https://github.com/plurimath/openmath
|
|
98
|
+
licenses:
|
|
99
|
+
- BSD-2-Clause
|
|
100
|
+
metadata:
|
|
101
|
+
rubygems_mfa_required: 'true'
|
|
102
|
+
rdoc_options: []
|
|
103
|
+
require_paths:
|
|
104
|
+
- lib
|
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: 3.2.0
|
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
requirements: []
|
|
116
|
+
rubygems_version: 4.0.20
|
|
117
|
+
specification_version: 4
|
|
118
|
+
summary: OpenMath parser by Plurimath.
|
|
119
|
+
test_files: []
|