asciimath2unitsml 0.0.2

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.
data/spec/conv_spec.rb ADDED
@@ -0,0 +1,254 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciimath2UnitsML do
4
+ it "converts an AsciiMath string to MathML + UnitsML" do
5
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
6
+ 32 + 5 xx 7 "unitsml(kg^-2)" xx 9 "unitsml(g)" xx 1 "unitsml(kg*s^-2)" xx 812 "unitsml(m*s^-2)" - 9 "unitsml(C^3*A)" + 7 "unitsml(hp)"
7
+ INPUT
8
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
9
+ <mn>32</mn>
10
+ <mo>+</mo>
11
+ <mn>5</mn>
12
+ <mo>&#xD7;</mo>
13
+ <mn>7</mn>
14
+ <mo rspace='thickmathspace'>&#x2062;</mo>
15
+ <mrow xref='U_kg-2'>
16
+ <msup>
17
+ <mrow>
18
+ <mi mathvariant='normal'>kg</mi>
19
+ </mrow>
20
+ <mrow>
21
+ <mo>&#x2212;</mo>
22
+ <mn>2</mn>
23
+ </mrow>
24
+ </msup>
25
+ </mrow>
26
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg-2' dimensionURL='#D_M-2'>
27
+ <UnitSystem name='SI' type='SI_base' xml:lang='en-US'/>
28
+ <UnitName xml:lang='en'>kg^-2</UnitName>
29
+ <UnitSymbol type='HTML'>
30
+ kg
31
+ <sup>&#x2212;2</sup>
32
+ </UnitSymbol>
33
+ <UnitSymbol type='MathML'>
34
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
35
+ <mrow>
36
+ <msup>
37
+ <mrow>
38
+ <mi mathvariant='normal'>kg</mi>
39
+ </mrow>
40
+ <mrow>
41
+ <mo>&#x2212;</mo>
42
+ <mn>2</mn>
43
+ </mrow>
44
+ </msup>
45
+ </mrow>
46
+ </math>
47
+ </UnitSymbol>
48
+ </Unit>
49
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
50
+ <PrefixName xml:lang='en'>kilo</PrefixName>
51
+ <PrefixSymbol type='ASCII'>k</PrefixSymbol>
52
+ </Prefix>
53
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_M-2'>
54
+ <Mass symbol='M' powerNumerator='-2'/>
55
+ </Dimension>
56
+ <mo>&#xD7;</mo>
57
+ <mn>9</mn>
58
+ <mo rspace='thickmathspace'>&#x2062;</mo>
59
+ <mrow xref='U_NISTu27'>
60
+ <mi mathvariant='normal'>g</mi>
61
+ </mrow>
62
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu27' dimensionURL='#D_M'>
63
+ <UnitSystem name='SI' type='SI_base' xml:lang='en-US'/>
64
+ <UnitName xml:lang='en'>gram</UnitName>
65
+ <UnitSymbol type='HTML'>g</UnitSymbol>
66
+ <UnitSymbol type='MathML'>
67
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
68
+ <mrow>
69
+ <mi mathvariant='normal'>g</mi>
70
+ </mrow>
71
+ </math>
72
+ </UnitSymbol>
73
+ </Unit>
74
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_M'>
75
+ <Mass symbol='M' powerNumerator='1'/>
76
+ </Dimension>
77
+ <mo>&#xD7;</mo>
78
+ <mn>1</mn>
79
+ <mo rspace='thickmathspace'>&#x2062;</mo>
80
+ <mrow xref='U_kg.s-2'>
81
+ <mi mathvariant='normal'>kg</mi>
82
+ <mo>&#xB7;</mo>
83
+ <msup>
84
+ <mrow>
85
+ <mi mathvariant='normal'>s</mi>
86
+ </mrow>
87
+ <mrow>
88
+ <mo>&#x2212;</mo>
89
+ <mn>2</mn>
90
+ </mrow>
91
+ </msup>
92
+ </mrow>
93
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#D_MT-2'>
94
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
95
+ <UnitName xml:lang='en'>kg*s^-2</UnitName>
96
+ <UnitSymbol type='HTML'>
97
+ kg &#xB7; s
98
+ <sup>&#x2212;2</sup>
99
+ </UnitSymbol>
100
+ <UnitSymbol type='MathML'>
101
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
102
+ <mrow>
103
+ <mi mathvariant='normal'>kg</mi>
104
+ <mo>&#xB7;</mo>
105
+ <msup>
106
+ <mrow>
107
+ <mi mathvariant='normal'>s</mi>
108
+ </mrow>
109
+ <mrow>
110
+ <mo>&#x2212;</mo>
111
+ <mn>2</mn>
112
+ </mrow>
113
+ </msup>
114
+ </mrow>
115
+ </math>
116
+ </UnitSymbol>
117
+ <RootUnits>
118
+ <EnumeratedRootUnit unit='gram' prefix='k'/>
119
+ <EnumeratedRootUnit unit='second' powerNumerator='-2'/>
120
+ </RootUnits>
121
+ </Unit>
122
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
123
+ <PrefixName xml:lang='en'>kilo</PrefixName>
124
+ <PrefixSymbol type='ASCII'>k</PrefixSymbol>
125
+ </Prefix>
126
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_MT-2'>
127
+ <Mass symbol='M' powerNumerator='1'/>
128
+ <Time symbol='T' powerNumerator='-2'/>
129
+ </Dimension>
130
+ <mo>&#xD7;</mo>
131
+ <mn>812</mn>
132
+ <mo rspace='thickmathspace'>&#x2062;</mo>
133
+ <mrow xref='U_NISTu1.u3e-2_1'>
134
+ <mi mathvariant='normal'>m</mi>
135
+ <mo>&#xB7;</mo>
136
+ <msup>
137
+ <mrow>
138
+ <mi mathvariant='normal'>s</mi>
139
+ </mrow>
140
+ <mrow>
141
+ <mo>&#x2212;</mo>
142
+ <mn>2</mn>
143
+ </mrow>
144
+ </msup>
145
+ </mrow>
146
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu1.u3e-2_1' dimensionURL='#D_LT-2'>
147
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
148
+ <UnitName xml:lang='en'>meter per second squared</UnitName>
149
+ <UnitSymbol type='HTML'>
150
+ m &#xB7; s
151
+ <sup>&#x2212;2</sup>
152
+ </UnitSymbol>
153
+ <UnitSymbol type='MathML'>
154
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
155
+ <mrow>
156
+ <mi mathvariant='normal'>m</mi>
157
+ <mo>&#xB7;</mo>
158
+ <msup>
159
+ <mrow>
160
+ <mi mathvariant='normal'>s</mi>
161
+ </mrow>
162
+ <mrow>
163
+ <mo>&#x2212;</mo>
164
+ <mn>2</mn>
165
+ </mrow>
166
+ </msup>
167
+ </mrow>
168
+ </math>
169
+ </UnitSymbol>
170
+ <RootUnits>
171
+ <EnumeratedRootUnit unit='meter'/>
172
+ <EnumeratedRootUnit unit='second' powerNumerator='-2'/>
173
+ </RootUnits>
174
+ </Unit>
175
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_LT-2'>
176
+ <Length symbol='L' powerNumerator='1'/>
177
+ <Time symbol='T' powerNumerator='-2'/>
178
+ </Dimension>
179
+ <mo>&#x2212;</mo>
180
+ <mn>9</mn>
181
+ <mo rspace='thickmathspace'>&#x2062;</mo>
182
+ <mrow xref='U_C3.A'>
183
+ <msup>
184
+ <mrow>
185
+ <mi mathvariant='normal'>C</mi>
186
+ </mrow>
187
+ <mrow>
188
+ <mn>3</mn>
189
+ </mrow>
190
+ </msup>
191
+ <mo>&#xB7;</mo>
192
+ <mi mathvariant='normal'>A</mi>
193
+ </mrow>
194
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_C3.A' dimensionURL='#D_T3I4'>
195
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
196
+ <UnitName xml:lang='en'>C^3*A</UnitName>
197
+ <UnitSymbol type='HTML'>
198
+ C
199
+ <sup>3</sup>
200
+ &#xB7; A
201
+ </UnitSymbol>
202
+ <UnitSymbol type='MathML'>
203
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
204
+ <mrow>
205
+ <msup>
206
+ <mrow>
207
+ <mi mathvariant='normal'>C</mi>
208
+ </mrow>
209
+ <mrow>
210
+ <mn>3</mn>
211
+ </mrow>
212
+ </msup>
213
+ <mo>&#xB7;</mo>
214
+ <mi mathvariant='normal'>A</mi>
215
+ </mrow>
216
+ </math>
217
+ </UnitSymbol>
218
+ <RootUnits>
219
+ <EnumeratedRootUnit unit='coulomb' powerNumerator='3'/>
220
+ <EnumeratedRootUnit unit='ampere'/>
221
+ </RootUnits>
222
+ </Unit>
223
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_T3I4'>
224
+ <Time symbol='T' powerNumerator='3'/>
225
+ <ElectricCurrent symbol='I' powerNumerator='4'/>
226
+ </Dimension>
227
+ <mo>+</mo>
228
+ <mn>7</mn>
229
+ <mo rspace='thickmathspace'>&#x2062;</mo>
230
+ <mrow xref='U_NISTu284'>
231
+ <mi mathvariant='normal'>hp</mi>
232
+ </mrow>
233
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu284'>
234
+ <UnitSystem name='not_SI' type='not_SI' xml:lang='en-US'/>
235
+ <UnitName xml:lang='en'>horsepower</UnitName>
236
+ <UnitSymbol type='HTML'>hp</UnitSymbol>
237
+ <UnitSymbol type='MathML'>
238
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
239
+ <mrow>
240
+ <mi mathvariant='normal'>hp</mi>
241
+ </mrow>
242
+ </math>
243
+ </UnitSymbol>
244
+ </Unit>
245
+ </math>
246
+ OUTPUT
247
+ end
248
+
249
+ it "raises error for illegal unit" do
250
+ expect{xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))}.to raise_error(Rsec::SyntaxError)
251
+ 12 "unitsml(que?)"
252
+ INPUT
253
+ end
254
+ end
@@ -0,0 +1,33 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.profiles.define 'gem' do
4
+ add_filter '/spec/'
5
+ add_filter '/autotest/'
6
+ add_group 'Libraries', '/lib/'
7
+ end
8
+ SimpleCov.start 'gem'
9
+
10
+ require 'asciimath2unitsml'
11
+ require "rspec/matchers"
12
+ require "equivalent-xml/rspec_matchers"
13
+ require "rexml/document"
14
+
15
+ RSpec.configure do |config|
16
+ # Enable flags like --only-failures and --next-failure
17
+ config.example_status_persistence_file_path = ".rspec_status"
18
+
19
+ # Disable RSpec exposing methods globally on `Module` and `main`
20
+ config.disable_monkey_patching!
21
+
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = :expect
24
+ end
25
+ end
26
+
27
+ def xmlpp(x)
28
+ s = ""
29
+ f = REXML::Formatters::Pretty.new(2)
30
+ f.compact = true
31
+ f.write(REXML::Document.new(x),s)
32
+ s
33
+ end
metadata ADDED
@@ -0,0 +1,257 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciimath2unitsml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciimath
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlentities
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.10.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.10.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rsec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '9.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '9.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: equivalent-xml
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.14'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.14'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '12.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '12.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.6'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.6'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '='
172
+ - !ruby/object:Gem::Version
173
+ version: 0.54.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '='
179
+ - !ruby/object:Gem::Version
180
+ version: 0.54.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.15'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.15'
195
+ - !ruby/object:Gem::Dependency
196
+ name: timecop
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '0.9'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '0.9'
209
+ description: 'Convert Asciimath via MathML to UnitsML
210
+
211
+ '
212
+ email:
213
+ - open.source@ribose.com
214
+ executables: []
215
+ extensions: []
216
+ extra_rdoc_files: []
217
+ files:
218
+ - Gemfile
219
+ - LICENSE
220
+ - README.adoc
221
+ - Rakefile
222
+ - asciimath2unitsml.gemspec
223
+ - bin/rspec
224
+ - lib/asciimath2unitsml.rb
225
+ - lib/asciimath2unitsml/conv.rb
226
+ - lib/asciimath2unitsml/parse.rb
227
+ - lib/asciimath2unitsml/string.rb
228
+ - lib/asciimath2unitsml/version.rb
229
+ - lib/unitsdb/prefixes.yaml
230
+ - lib/unitsdb/quantities.yaml
231
+ - lib/unitsdb/units.yaml
232
+ - spec/conv_spec.rb
233
+ - spec/spec_helper.rb
234
+ homepage: https://github.com/plurimath/asciimath2unitsml
235
+ licenses:
236
+ - BSD-2-Clause
237
+ metadata: {}
238
+ post_install_message:
239
+ rdoc_options: []
240
+ require_paths:
241
+ - lib
242
+ required_ruby_version: !ruby/object:Gem::Requirement
243
+ requirements:
244
+ - - ">="
245
+ - !ruby/object:Gem::Version
246
+ version: 2.4.0
247
+ required_rubygems_version: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ version: '0'
252
+ requirements: []
253
+ rubygems_version: 3.1.4
254
+ signing_key:
255
+ specification_version: 4
256
+ summary: Convert Asciimath via MathML to UnitsML
257
+ test_files: []