asciimath2unitsml 0.1.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,164 @@
1
+ module UnitsDB
2
+ class Dimension
3
+ attr_reader :id, :length, :mass, :time, :electric_current, :thermodynamic_temperature,
4
+ :amount_of_substance, :luminous_intensity, :plane_angle, :dimensionless
5
+
6
+ def initialize(id, hash)
7
+ begin
8
+ @id = id
9
+ @dimensionless = hash[:dimensionless]
10
+ hash[:length] and @length = hash[:length][:powerNumerator].to_i
11
+ hash[:mass] and @mass = hash[:mass][:powerNumerator].to_i
12
+ hash[:time] and @time = hash[:time][:powerNumerator].to_i
13
+ hash[:electric_current] and @electric_current = hash[:electric_current][:powerNumerator].to_i
14
+ hash[:thermodynamic_temperature] and
15
+ @thermodynamic_temperature = hash[:thermodynamic_temperature][:powerNumerator].to_i
16
+ hash[:amount_of_substance] and @amount_of_substance = hash[:amount_of_substance][:powerNumerator].to_i
17
+ hash[:luminous_intensity] and @luminous_intensity = hash[:luminous_intensity][:powerNumerator].to_i
18
+ hash[:plane_angle] and @plane_angle = hash[:plane_angle][:powerNumerator].to_i
19
+ rescue
20
+ raise StandardError.new "Parse fail on Dimension #{id}: #{hash}"
21
+ end
22
+ end
23
+
24
+ def keys
25
+ ret = []
26
+ @length and ret << "Length"
27
+ @mass and ret << "Mass"
28
+ @time and ret << "Time"
29
+ @electric_current and ret << "ElectricCurrent"
30
+ @thermodynamic_temperature and ret << "ThermodynamicTemperature"
31
+ @amount_of_substance and ret << "AmountOfSubstance"
32
+ @luminous_intensity and ret << "LuminousIntensity"
33
+ @plane_angle and ret << "PlaneAngle"
34
+ ret
35
+ end
36
+
37
+ def exponent(key)
38
+ case key
39
+ when "Length" then @length
40
+ when "Mass" then @mass
41
+ when "Time" then @time
42
+ when "ElectricCurrent" then @electric_current
43
+ when "ThermodynamicTemperature" then @thermodynamic_temperature
44
+ when "AmountOfSubstance" then @amount_of_substance
45
+ when "LuminousIntensity" then @luminous_intensity
46
+ when "PlaneAngle" then @plane_angle
47
+ end
48
+ end
49
+
50
+ def vector
51
+ "#{@length}:#{@mass}:#{@time}:#{@electric_current}:#{@thermodynamic_temperature}:#{@amount_of_substance}:"\
52
+ "#{@luminous_intensity}:#{@plane_angle}"
53
+ end
54
+ end
55
+
56
+ class Prefix
57
+ attr_reader :id, :name, :base, :power, :symbol
58
+
59
+ def initialize(id, hash)
60
+ begin
61
+ @id = id
62
+ @name = hash[:name]
63
+ @base = hash[:base]
64
+ @power = hash[:power]
65
+ @symbol = hash[:symbol] # always is a hash
66
+ rescue
67
+ raise StandardError.new "Parse fail on Prefix #{id}: #{hash}"
68
+ end
69
+ end
70
+
71
+ def ascii
72
+ @symbol[:ascii]
73
+ end
74
+
75
+ def symbolid
76
+ @symbol[:ascii]
77
+ end
78
+
79
+ def html
80
+ @symbol[:html]
81
+ end
82
+
83
+ def mathml
84
+ @symbol[:html]
85
+ end
86
+
87
+ def latex
88
+ @symbol[:latex]
89
+ end
90
+
91
+ def unicode
92
+ @symbol[:unicode]
93
+ end
94
+ end
95
+
96
+ class Quantity
97
+ attr_reader :id, :dimension, :type, :names, :units
98
+
99
+ def initialize(id, hash)
100
+ begin
101
+ @id = id
102
+ @dimension = hash[:dimension_url].sub(/^#/, "")
103
+ @type = hash[:quantity_type]
104
+ hash[:quantity_name] and @names = hash[:quantity_name]
105
+ hash[:unit_reference] and @units = hash[:unit_reference].map { |x| x[:url].sub(/^#/, "") }
106
+ rescue
107
+ raise StandardError.new "Parse fail on Quantity #{id}: #{hash}"
108
+ end
109
+ end
110
+
111
+ def name
112
+ @names&.first
113
+ end
114
+
115
+ def unit
116
+ @units&.first
117
+ end
118
+ end
119
+
120
+ class Unit
121
+ attr_reader :id, :dimension, :short, :root, :unit_system, :names, :symbols, :symbols_hash, :root_units, :quantities,
122
+ :si_derived_bases, :prefixed
123
+
124
+ def initialize(id, hash)
125
+ begin
126
+ @id = id
127
+ @short = short
128
+ @dimension = hash[:dimension_url].sub(/^#/, "")
129
+ hash[:short] && !hash[:short].empty? and @short = hash[:short]
130
+ @unit_system = hash[:unit_system]
131
+ @names = hash[:unit_name]
132
+ @symbols_hash = hash[:unit_symbols]&.each_with_object({}) { |h, m| m[h[:id]] = h } || {}
133
+ @symbols = hash[:unit_symbols]
134
+ hash[:root_units] and hash[:root_units][:enumerated_root_units] and
135
+ @root = hash[:root_units][:enumerated_root_units]
136
+ hash[:quantity_reference] and @quantities = hash[:quantity_reference].map { |x| x[:url].sub(/^#/, "") }
137
+ hash[:si_derived_bases] and @si_derived_bases = hash[:si_derived_bases]
138
+ @prefixed = (hash[:prefixed] == true)
139
+ rescue
140
+ raise StandardError.new "Parse fail on Unit #{id}: #{hash}"
141
+ end
142
+ end
143
+
144
+ def system_name
145
+ @unit_system[:name]
146
+ end
147
+
148
+ def system_type
149
+ @unit_system[:type]
150
+ end
151
+
152
+ def name
153
+ @names.first
154
+ end
155
+
156
+ def symbolid
157
+ @symbols ? @symbols.first[:id] : @short
158
+ end
159
+
160
+ def symbolids
161
+ @symbols ? @symbols.map { |s| s[:id] } : [ @short ]
162
+ end
163
+ end
164
+ end
data/spec/conv_spec.rb CHANGED
@@ -3,13 +3,14 @@ require "spec_helper"
3
3
  RSpec.describe Asciimath2UnitsML do
4
4
  it "converts an AsciiMath string to MathML + UnitsML" do
5
5
  expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
6
- 1 "unitsml(kg*s^-2)" xx 9 "unitsml(g)"
6
+ 1 "unitsml(mm*s^-2)"
7
7
  INPUT
8
- <math xmlns='http://www.w3.org/1998/Math/MathML'>
8
+ <?xml version='1.0'?>
9
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
9
10
  <mn>1</mn>
10
11
  <mo rspace='thickmathspace'>&#x2062;</mo>
11
- <mrow xref='U_kg.s-2'>
12
- <mi mathvariant='normal'>kg</mi>
12
+ <mrow xref='U_mm.s-2'>
13
+ <mi mathvariant='normal'>mm</mi>
13
14
  <mo>&#xB7;</mo>
14
15
  <msup>
15
16
  <mrow>
@@ -21,17 +22,17 @@ RSpec.describe Asciimath2UnitsML do
21
22
  </mrow>
22
23
  </msup>
23
24
  </mrow>
24
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#D_MT-2'>
25
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_mm.s-2' dimensionURL='#NISTd28'>
25
26
  <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
26
- <UnitName xml:lang='en'>kg*s^-2</UnitName>
27
+ <UnitName xml:lang='en'>mm*s^-2</UnitName>
27
28
  <UnitSymbol type='HTML'>
28
- kg&#xB7;s
29
+ mm&#xB7;s
29
30
  <sup>&#x2212;2</sup>
30
31
  </UnitSymbol>
31
32
  <UnitSymbol type='MathML'>
32
33
  <math xmlns='http://www.w3.org/1998/Math/MathML'>
33
34
  <mrow>
34
- <mi mathvariant='normal'>kg</mi>
35
+ <mi mathvariant='normal'>mm</mi>
35
36
  <mo>&#xB7;</mo>
36
37
  <msup>
37
38
  <mrow>
@@ -46,26 +47,262 @@ RSpec.describe Asciimath2UnitsML do
46
47
  </math>
47
48
  </UnitSymbol>
48
49
  <RootUnits>
49
- <EnumeratedRootUnit unit='gram' prefix='k'/>
50
+ <EnumeratedRootUnit unit='meter' prefix='m'/>
50
51
  <EnumeratedRootUnit unit='second' powerNumerator='-2'/>
51
52
  </RootUnits>
52
53
  </Unit>
54
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-3' xml:id='NISTp10_-3'>
55
+ <PrefixName xml:lang='en'>milli</PrefixName>
56
+ <PrefixSymbol type='ASCII'>m</PrefixSymbol>
57
+ <PrefixSymbol type='unicode'>m</PrefixSymbol>
58
+ <PrefixSymbol type='LaTeX'>m</PrefixSymbol>
59
+ <PrefixSymbol type='HTML'>m</PrefixSymbol>
60
+ </Prefix>
61
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd28'>
62
+ <Length symbol='L' powerNumerator='1'/>
63
+ <Time symbol='T' powerNumerator='-2'/>
64
+ </Dimension>
65
+ </math>
66
+ OUTPUT
67
+ end
68
+
69
+ it "deals with non-Ascii units and prefixes" do
70
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
71
+ 1 "unitsml(um)"
72
+ INPUT
73
+ <?xml version='1.0'?>
74
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
75
+ <mn>1</mn>
76
+ <mo rspace='thickmathspace'>&#x2062;</mo>
77
+ <mrow xref='U_um'>
78
+ <mi mathvariant='normal'>&#xB5;m</mi>
79
+ </mrow>
80
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_um' dimensionURL='#NISTd1'>
81
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
82
+ <UnitName xml:lang='en'>um</UnitName>
83
+ <UnitSymbol type='HTML'>um</UnitSymbol>
84
+ <UnitSymbol type='MathML'>
85
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
86
+ <mrow>
87
+ <mi mathvariant='normal'>&#xB5;m</mi>
88
+ </mrow>
89
+ </math>
90
+ </UnitSymbol>
91
+ <RootUnits>
92
+ <EnumeratedRootUnit unit='meter' prefix='u'/>
93
+ </RootUnits>
94
+ </Unit>
95
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-6' xml:id='NISTp10_-6'>
96
+ <PrefixName xml:lang='en'>micro</PrefixName>
97
+ <PrefixSymbol type='ASCII'>u</PrefixSymbol>
98
+ <PrefixSymbol type='unicode'>&#x3BC;</PrefixSymbol>
99
+ <PrefixSymbol type='LaTeX'>$mu$</PrefixSymbol>
100
+ <PrefixSymbol type='HTML'>&#xB5;</PrefixSymbol>
101
+ </Prefix>
102
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd1'>
103
+ <Length symbol='L' powerNumerator='1'/>
104
+ </Dimension>
105
+ </math>
106
+ OUTPUT
107
+ end
108
+
109
+ it "does not insert space before non-alphabetic units" do
110
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
111
+ 1 "unitsml(degK)" + 1 "unitsml(prime)"
112
+ INPUT
113
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
114
+ <mn>1</mn>
115
+ <mo rspace='thickmathspace'>&#x2062;</mo>
116
+ <mrow xref='U_NISTu5'>
117
+ <mi mathvariant='normal'>&#xB0;K</mi>
118
+ </mrow>
119
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu5' dimensionURL='#NISTd5'>
120
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
121
+ <UnitName xml:lang='en'>kelvin</UnitName>
122
+ <UnitSymbol type='HTML'>K</UnitSymbol>
123
+ <UnitSymbol type='MathML'>
124
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
125
+ <mrow>
126
+ <mi mathvariant='normal'>K</mi>
127
+ </mrow>
128
+ </math>
129
+ </UnitSymbol>
130
+ </Unit>
131
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd5'>
132
+ <ThermodynamicTemperature symbol='Theta' powerNumerator='1'/>
133
+ </Dimension>
134
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq5' dimensionURL='#NISTd5' quantityType='base'>
135
+ <QuantityName xml:lang='en-US'>thermodynamic temperature</QuantityName>
136
+ </Quantity>
137
+ <mo>+</mo>
138
+ <mn>1</mn>
139
+ <mo>&#x2062;</mo>
140
+ <mrow xref='U_NISTu147'>
141
+ <mi mathvariant='normal'>&#x2032;</mi>
142
+ </mrow>
143
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu147'>
144
+ <UnitSystem name='not_SI' type='not_SI' xml:lang='en-US'/>
145
+ <UnitName xml:lang='en'>minute (minute of arc)</UnitName>
146
+ <UnitSymbol type='HTML'>&#x2032;</UnitSymbol>
147
+ <UnitSymbol type='MathML'>
148
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
149
+ <mrow>
150
+ <mi mathvariant='normal'>&#x2032;</mi>
151
+ </mrow>
152
+ </math>
153
+ </UnitSymbol>
154
+ </Unit>
155
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd9'>
156
+ <PlaneAngle symbol='Phi' powerNumerator='1'/>
157
+ </Dimension>
158
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq9' dimensionURL='#NISTd9' quantityType='base'>
159
+ <QuantityName xml:lang='en-US'>plane angle</QuantityName>
160
+ <QuantityName xml:lang='en-US'>angle</QuantityName>
161
+ </Quantity>
162
+ </math>
163
+ OUTPUT
164
+ end
165
+
166
+ it "does not insert space before operators" do
167
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
168
+ 8 "unitsml(kg)" cdot "unitsml(m)"
169
+ INPUT
170
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
171
+ <mn>8</mn>
172
+ <mo rspace='thickmathspace'>&#x2062;</mo>
173
+ <mrow xref='U_NISTu2'>
174
+ <mi mathvariant='normal'>kg</mi>
175
+ </mrow>
176
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu2' dimensionURL='#NISTd2'>
177
+ <UnitSystem name='SI' type='SI_base' xml:lang='en-US'/>
178
+ <UnitName xml:lang='en'>kilogram</UnitName>
179
+ <UnitSymbol type='HTML'>kg</UnitSymbol>
180
+ <UnitSymbol type='MathML'>
181
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
182
+ <mrow>
183
+ <mi mathvariant='normal'>kg</mi>
184
+ </mrow>
185
+ </math>
186
+ </UnitSymbol>
187
+ <RootUnits>
188
+ <EnumeratedRootUnit unit='gram' prefix='k'/>
189
+ </RootUnits>
190
+ </Unit>
53
191
  <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
54
192
  <PrefixName xml:lang='en'>kilo</PrefixName>
55
193
  <PrefixSymbol type='ASCII'>k</PrefixSymbol>
194
+ <PrefixSymbol type='unicode'>k</PrefixSymbol>
195
+ <PrefixSymbol type='LaTeX'>k</PrefixSymbol>
196
+ <PrefixSymbol type='HTML'>k</PrefixSymbol>
56
197
  </Prefix>
57
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_MT-2'>
198
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd2'>
58
199
  <Mass symbol='M' powerNumerator='1'/>
59
- <Time symbol='T' powerNumerator='-2'/>
60
200
  </Dimension>
61
- <mo>&#xD7;</mo>
62
- <mn>9</mn>
201
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq2' dimensionURL='#NISTd2' quantityType='base'>
202
+ <QuantityName xml:lang='en-US'>mass</QuantityName>
203
+ </Quantity>
204
+ <mo>&#x22C5;</mo>
205
+ <mrow xref='U_NISTu1'>
206
+ <mi mathvariant='normal'>m</mi>
207
+ </mrow>
208
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu1' dimensionURL='#NISTd1'>
209
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
210
+ <UnitName xml:lang='en'>meter</UnitName>
211
+ <UnitSymbol type='HTML'>m</UnitSymbol>
212
+ <UnitSymbol type='MathML'>
213
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
214
+ <mrow>
215
+ <mi mathvariant='normal'>m</mi>
216
+ </mrow>
217
+ </math>
218
+ </UnitSymbol>
219
+ </Unit>
220
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd1'>
221
+ <Length symbol='L' powerNumerator='1'/>
222
+ </Dimension>
223
+ </math>
224
+ OUTPUT
225
+ end
226
+
227
+ it "deals with sqrt units" do
228
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
229
+ 1 "unitsml(sqrt(Hz))"
230
+ INPUT
231
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
232
+ <mn>1</mn>
233
+ <mo rspace='thickmathspace'>&#x2062;</mo>
234
+ <mrow xref='U_sqrtHz'>
235
+ <msqrt>
236
+ <mi mathvariant='normal'>Hz</mi>
237
+ </msqrt>
238
+ </mrow>
239
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_Hz0.5' dimensionURL='#D_T-0.5'>
240
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
241
+ <UnitName xml:lang='en'>Hz^0.5</UnitName>
242
+ <UnitSymbol type='HTML'>&#x221A;Hz</UnitSymbol>
243
+ <UnitSymbol type='MathML'>
244
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
245
+ <mrow>
246
+ <msqrt>
247
+ <mi mathvariant='normal'>Hz</mi>
248
+ </msqrt>
249
+ </mrow>
250
+ </math>
251
+ </UnitSymbol>
252
+ </Unit>
253
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_T-0.5'>
254
+ <Time symbol='T' powerNumerator='-0.5'/>
255
+ </Dimension>
256
+ </math>
257
+ OUTPUT
258
+ end
259
+
260
+ it "deals with kg and g" do
261
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
262
+ 1 "unitsml(kg)" + 1 "unitsml(g)"
263
+ INPUT
264
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
265
+ <mn>1</mn>
266
+ <mo rspace='thickmathspace'>&#x2062;</mo>
267
+ <mrow xref='U_NISTu2'>
268
+ <mi mathvariant='normal'>kg</mi>
269
+ </mrow>
270
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu2' dimensionURL='#NISTd2'>
271
+ <UnitSystem name='SI' type='SI_base' xml:lang='en-US'/>
272
+ <UnitName xml:lang='en'>kilogram</UnitName>
273
+ <UnitSymbol type='HTML'>kg</UnitSymbol>
274
+ <UnitSymbol type='MathML'>
275
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
276
+ <mrow>
277
+ <mi mathvariant='normal'>kg</mi>
278
+ </mrow>
279
+ </math>
280
+ </UnitSymbol>
281
+ <RootUnits>
282
+ <EnumeratedRootUnit unit='gram' prefix='k'/>
283
+ </RootUnits>
284
+ </Unit>
285
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
286
+ <PrefixName xml:lang='en'>kilo</PrefixName>
287
+ <PrefixSymbol type='ASCII'>k</PrefixSymbol>
288
+ <PrefixSymbol type='unicode'>k</PrefixSymbol>
289
+ <PrefixSymbol type='LaTeX'>k</PrefixSymbol>
290
+ <PrefixSymbol type='HTML'>k</PrefixSymbol>
291
+ </Prefix>
292
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd2'>
293
+ <Mass symbol='M' powerNumerator='1'/>
294
+ </Dimension>
295
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq2' dimensionURL='#NISTd2' quantityType='base'>
296
+ <QuantityName xml:lang='en-US'>mass</QuantityName>
297
+ </Quantity>
298
+ <mo>+</mo>
299
+ <mn>1</mn>
63
300
  <mo rspace='thickmathspace'>&#x2062;</mo>
64
301
  <mrow xref='U_NISTu27'>
65
302
  <mi mathvariant='normal'>g</mi>
66
303
  </mrow>
67
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu27' dimensionURL='#D_M'>
68
- <UnitSystem name='SI' type='SI_base' xml:lang='en-US'/>
304
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu27' dimensionURL='#NISTd2'>
305
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
69
306
  <UnitName xml:lang='en'>gram</UnitName>
70
307
  <UnitSymbol type='HTML'>g</UnitSymbol>
71
308
  <UnitSymbol type='MathML'>
@@ -76,9 +313,6 @@ RSpec.describe Asciimath2UnitsML do
76
313
  </math>
77
314
  </UnitSymbol>
78
315
  </Unit>
79
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_M'>
80
- <Mass symbol='M' powerNumerator='1'/>
81
- </Dimension>
82
316
  </math>
83
317
  OUTPUT
84
318
  end
@@ -105,6 +339,14 @@ RSpec.describe Asciimath2UnitsML do
105
339
  </math>
106
340
  </UnitSymbol>
107
341
  </Unit>
342
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd16'>
343
+ <Length symbol='L' powerNumerator='2'/>
344
+ <Mass symbol='M' powerNumerator='1'/>
345
+ <Time symbol='T' powerNumerator='-3'/>
346
+ </Dimension>
347
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq20' dimensionURL='#NISTd16' quantityType='base'>
348
+ <QuantityName xml:lang='en-US'>power</QuantityName>
349
+ </Quantity>
108
350
  </math>
109
351
  OUTPUT
110
352
  end
@@ -129,7 +371,7 @@ RSpec.describe Asciimath2UnitsML do
129
371
  </mrow>
130
372
  </msup>
131
373
  </mrow>
132
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#D_MT-2'>
374
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#NISTd37'>
133
375
  <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
134
376
  <UnitName xml:lang='en'>kg*s^-2</UnitName>
135
377
  <UnitSymbol type='HTML'>
@@ -161,8 +403,11 @@ RSpec.describe Asciimath2UnitsML do
161
403
  <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
162
404
  <PrefixName xml:lang='en'>kilo</PrefixName>
163
405
  <PrefixSymbol type='ASCII'>k</PrefixSymbol>
406
+ <PrefixSymbol type='unicode'>k</PrefixSymbol>
407
+ <PrefixSymbol type='LaTeX'>k</PrefixSymbol>
408
+ <PrefixSymbol type='HTML'>k</PrefixSymbol>
164
409
  </Prefix>
165
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_MT-2'>
410
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd37'>
166
411
  <Mass symbol='M' powerNumerator='1'/>
167
412
  <Time symbol='T' powerNumerator='-2'/>
168
413
  </Dimension>
@@ -182,64 +427,177 @@ RSpec.describe Asciimath2UnitsML do
182
427
  </mrow>
183
428
  </msup>
184
429
  </mrow>
185
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#D_MT-2'>
186
- <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
187
- <UnitName xml:lang='en'>kg*s^-2</UnitName>
188
- <UnitSymbol type='HTML'>
189
- kg&#xB7;s
190
- <sup>&#x2212;2</sup>
191
- </UnitSymbol>
192
- <UnitSymbol type='MathML'>
193
- <math xmlns='http://www.w3.org/1998/Math/MathML'>
194
- <mrow>
195
- <mi mathvariant='normal'>kg</mi>
196
- <mo>&#xB7;</mo>
197
- <msup>
198
- <mrow>
199
- <mi mathvariant='normal'>s</mi>
200
- </mrow>
201
- <mrow>
202
- <mo>&#x2212;</mo>
203
- <mn>2</mn>
204
- </mrow>
205
- </msup>
206
- </mrow>
207
- </math>
208
- </UnitSymbol>
209
- <RootUnits>
210
- <EnumeratedRootUnit unit='gram' prefix='k'/>
211
- <EnumeratedRootUnit unit='second' powerNumerator='-2'/>
212
- </RootUnits>
213
- </Unit>
214
- <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
215
- <PrefixName xml:lang='en'>kilo</PrefixName>
216
- <PrefixSymbol type='ASCII'>k</PrefixSymbol>
217
- </Prefix>
218
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_MT-2'>
219
- <Mass symbol='M' powerNumerator='1'/>
220
- <Time symbol='T' powerNumerator='-2'/>
221
- </Dimension>
222
430
  </math>
223
431
  OUTPUT
224
432
  end
225
433
 
226
- =begin
227
434
  it "deals with notational variants" do
228
435
  expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
229
436
  9 "unitsml(degK)" + 10 "unitsml(K)"
230
437
  INPUT
438
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
439
+ <mn>9</mn>
440
+ <mo rspace='thickmathspace'>&#x2062;</mo>
441
+ <mrow xref='U_NISTu5'>
442
+ <mi mathvariant='normal'>&#xB0;K</mi>
443
+ </mrow>
444
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu5' dimensionURL='#NISTd5'>
445
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
446
+ <UnitName xml:lang='en'>kelvin</UnitName>
447
+ <UnitSymbol type='HTML'>K</UnitSymbol>
448
+ <UnitSymbol type='MathML'>
449
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
450
+ <mrow>
451
+ <mi mathvariant='normal'>K</mi>
452
+ </mrow>
453
+ </math>
454
+ </UnitSymbol>
455
+ </Unit>
456
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd5'>
457
+ <ThermodynamicTemperature symbol='Theta' powerNumerator='1'/>
458
+ </Dimension>
459
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq5' dimensionURL='#NISTd5' quantityType='base'>
460
+ <QuantityName xml:lang='en-US'>thermodynamic temperature</QuantityName>
461
+ </Quantity>
462
+ <mo>+</mo>
463
+ <mn>10</mn>
464
+ <mo rspace='thickmathspace'>&#x2062;</mo>
465
+ <mrow xref='U_NISTu5'>
466
+ <mi mathvariant='normal'>K</mi>
467
+ </mrow>
468
+ </math>
469
+ OUTPUT
470
+ end
471
+
472
+ it "deals with prefixed units" do
473
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
474
+ 9 "unitsml(mbar)"
475
+ INPUT
476
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
477
+ <mn>9</mn>
478
+ <mo rspace='thickmathspace'>&#x2062;</mo>
479
+ <mrow xref='U_NISTu362'>
480
+ <mi mathvariant='normal'>mbar</mi>
481
+ </mrow>
482
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu362'>
483
+ <UnitSystem name='not_SI' type='not_SI' xml:lang='en-US'/>
484
+ <UnitName xml:lang='en'>millibar</UnitName>
485
+ <UnitSymbol type='HTML'>mbar</UnitSymbol>
486
+ <UnitSymbol type='MathML'>
487
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
488
+ <mrow>
489
+ <mi mathvariant='normal'>mbar</mi>
490
+ </mrow>
491
+ </math>
492
+ </UnitSymbol>
493
+ <RootUnits>
494
+ <EnumeratedRootUnit unit='bar' prefix='m'/>
495
+ </RootUnits>
496
+ </Unit>
497
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-3' xml:id='NISTp10_-3'>
498
+ <PrefixName xml:lang='en'>milli</PrefixName>
499
+ <PrefixSymbol type='ASCII'>m</PrefixSymbol>
500
+ <PrefixSymbol type='unicode'>m</PrefixSymbol>
501
+ <PrefixSymbol type='LaTeX'>m</PrefixSymbol>
502
+ <PrefixSymbol type='HTML'>m</PrefixSymbol>
503
+ </Prefix>
504
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd14'>
505
+ <Length symbol='L' powerNumerator='-1'/>
506
+ <Mass symbol='M' powerNumerator='1'/>
507
+ <Time symbol='T' powerNumerator='-2'/>
508
+ </Dimension>
509
+ </math>
231
510
  OUTPUT
232
511
  end
233
- =end
512
+
513
+ it "deals with standalone prefixes" do
514
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
515
+ "unitsml(p-)" "unitsml(da-)"
516
+ INPUT
517
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
518
+ <mrow xref='NISTp10_-12'>
519
+ <mi mathvariant='normal'>p</mi>
520
+ </mrow>
521
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-12' xml:id='NISTp10_-12'>
522
+ <PrefixName xml:lang='en'>pico</PrefixName>
523
+ <PrefixSymbol type='ASCII'>p</PrefixSymbol>
524
+ <PrefixSymbol type='unicode'>p</PrefixSymbol>
525
+ <PrefixSymbol type='LaTeX'>p</PrefixSymbol>
526
+ <PrefixSymbol type='HTML'>p</PrefixSymbol>
527
+ </Prefix>
528
+ <mo rspace='thickmathspace'>&#x2062;</mo>
529
+ <mrow xref='NISTp10_1'>
530
+ <mi mathvariant='normal'>da</mi>
531
+ </mrow>
532
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='1' xml:id='NISTp10_1'>
533
+ <PrefixName xml:lang='en'>deka</PrefixName>
534
+ <PrefixSymbol type='ASCII'>da</PrefixSymbol>
535
+ <PrefixSymbol type='unicode'>da</PrefixSymbol>
536
+ <PrefixSymbol type='LaTeX'>da</PrefixSymbol>
537
+ <PrefixSymbol type='HTML'>da</PrefixSymbol>
538
+ </Prefix>
539
+ </math>
540
+ OUTPUT
541
+ end
542
+
543
+ it "deals with HTML entities in UnitsDB" do
544
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
545
+ "unitsml(u-)" + "unitsml(um)"
546
+ INPUT
547
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
548
+ <mrow xref='NISTp10_-6'>
549
+ <mi mathvariant='normal'>&#xB5;</mi>
550
+ </mrow>
551
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-6' xml:id='NISTp10_-6'>
552
+ <PrefixName xml:lang='en'>micro</PrefixName>
553
+ <PrefixSymbol type='ASCII'>u</PrefixSymbol>
554
+ <PrefixSymbol type='unicode'>&#x3BC;</PrefixSymbol>
555
+ <PrefixSymbol type='LaTeX'>$mu$</PrefixSymbol>
556
+ <PrefixSymbol type='HTML'>&#xB5;</PrefixSymbol>
557
+ </Prefix>
558
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd2'>
559
+ <Mass symbol='M' powerNumerator='1'/>
560
+ </Dimension>
561
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq2' dimensionURL='#NISTd2' quantityType='base'>
562
+ <QuantityName xml:lang='en-US'>mass</QuantityName>
563
+ </Quantity>
564
+ <mo>+</mo>
565
+ <mo rspace='thickmathspace'>&#x2062;</mo>
566
+ <mrow xref='U_um'>
567
+ <mi mathvariant='normal'>&#xB5;m</mi>
568
+ </mrow>
569
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_um' dimensionURL='#NISTd1'>
570
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
571
+ <UnitName xml:lang='en'>um</UnitName>
572
+ <UnitSymbol type='HTML'>um</UnitSymbol>
573
+ <UnitSymbol type='MathML'>
574
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
575
+ <mrow>
576
+ <mi mathvariant='normal'>&#xB5;m</mi>
577
+ </mrow>
578
+ </math>
579
+ </UnitSymbol>
580
+ <RootUnits>
581
+ <EnumeratedRootUnit unit='meter' prefix='u'/>
582
+ </RootUnits>
583
+ </Unit>
584
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd1'>
585
+ <Length symbol='L' powerNumerator='1'/>
586
+ </Dimension>
587
+ </math>
588
+ OUTPUT
589
+ end
234
590
 
235
591
  it "deals with units division" do
236
592
  expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
237
- 9 "unitsml(C^3*A)" + 13 "unitsml(A/C^-3)"
593
+ 9 "unitsml(A*C^3)" + 13 "unitsml(A/C^-3)"
238
594
  INPUT
239
595
  <math xmlns='http://www.w3.org/1998/Math/MathML'>
240
596
  <mn>9</mn>
241
597
  <mo rspace='thickmathspace'>&#x2062;</mo>
242
- <mrow xref='U_C3.A'>
598
+ <mrow xref='U_A.C3'>
599
+ <mi mathvariant='normal'>A</mi>
600
+ <mo>&#xB7;</mo>
243
601
  <msup>
244
602
  <mrow>
245
603
  <mi mathvariant='normal'>C</mi>
@@ -248,20 +606,19 @@ INPUT
248
606
  <mn>3</mn>
249
607
  </mrow>
250
608
  </msup>
251
- <mo>&#xB7;</mo>
252
- <mi mathvariant='normal'>A</mi>
253
609
  </mrow>
254
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_C3.A' dimensionURL='#D_T3I4'>
610
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_A.C3' dimensionURL='#D_M3I4'>
255
611
  <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
256
- <UnitName xml:lang='en'>C^3*A</UnitName>
612
+ <UnitName xml:lang='en'>A*C^3</UnitName>
257
613
  <UnitSymbol type='HTML'>
258
- C
614
+ A&#xB7;C
259
615
  <sup>3</sup>
260
- &#xB7;A
261
616
  </UnitSymbol>
262
617
  <UnitSymbol type='MathML'>
263
618
  <math xmlns='http://www.w3.org/1998/Math/MathML'>
264
619
  <mrow>
620
+ <mi mathvariant='normal'>A</mi>
621
+ <mo>&#xB7;</mo>
265
622
  <msup>
266
623
  <mrow>
267
624
  <mi mathvariant='normal'>C</mi>
@@ -270,18 +627,16 @@ INPUT
270
627
  <mn>3</mn>
271
628
  </mrow>
272
629
  </msup>
273
- <mo>&#xB7;</mo>
274
- <mi mathvariant='normal'>A</mi>
275
630
  </mrow>
276
631
  </math>
277
632
  </UnitSymbol>
278
633
  <RootUnits>
279
- <EnumeratedRootUnit unit='coulomb' powerNumerator='3'/>
280
634
  <EnumeratedRootUnit unit='ampere'/>
635
+ <EnumeratedRootUnit unit='coulomb' powerNumerator='3'/>
281
636
  </RootUnits>
282
637
  </Unit>
283
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_T3I4'>
284
- <Time symbol='T' powerNumerator='3'/>
638
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_M3I4'>
639
+ <Mass symbol='M' powerNumerator='3'/>
285
640
  <ElectricCurrent symbol='I' powerNumerator='4'/>
286
641
  </Dimension>
287
642
  <mo>+</mo>
@@ -300,39 +655,6 @@ INPUT
300
655
  </mrow>
301
656
  </msup>
302
657
  </mrow>
303
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_A/C-3' dimensionURL='#D_T3I4'>
304
- <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
305
- <UnitName xml:lang='en'>A*C^3</UnitName>
306
- <UnitSymbol type='HTML'>
307
- A/C
308
- <sup>&#x2212;3</sup>
309
- </UnitSymbol>
310
- <UnitSymbol type='MathML'>
311
- <math xmlns='http://www.w3.org/1998/Math/MathML'>
312
- <mrow>
313
- <mi mathvariant='normal'>A</mi>
314
- <mo>/</mo>
315
- <msup>
316
- <mrow>
317
- <mi mathvariant='normal'>C</mi>
318
- </mrow>
319
- <mrow>
320
- <mo>&#x2212;</mo>
321
- <mn>3</mn>
322
- </mrow>
323
- </msup>
324
- </mrow>
325
- </math>
326
- </UnitSymbol>
327
- <RootUnits>
328
- <EnumeratedRootUnit unit='ampere'/>
329
- <EnumeratedRootUnit unit='coulomb' powerNumerator='3'/>
330
- </RootUnits>
331
- </Unit>
332
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_T3I4'>
333
- <Time symbol='T' powerNumerator='3'/>
334
- <ElectricCurrent symbol='I' powerNumerator='4'/>
335
- </Dimension>
336
658
  </math>
337
659
  OUTPUT
338
660
  end
@@ -389,10 +711,16 @@ OUTPUT
389
711
  </mrow>
390
712
  </math>
391
713
  </UnitSymbol>
714
+ <RootUnits>
715
+ <EnumeratedRootUnit unit='gram' prefix='k' powerNumerator='-2'/>
716
+ </RootUnits>
392
717
  </Unit>
393
718
  <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
394
719
  <PrefixName xml:lang='en'>kilo</PrefixName>
395
720
  <PrefixSymbol type='ASCII'>k</PrefixSymbol>
721
+ <PrefixSymbol type='unicode'>k</PrefixSymbol>
722
+ <PrefixSymbol type='LaTeX'>k</PrefixSymbol>
723
+ <PrefixSymbol type='HTML'>k</PrefixSymbol>
396
724
  </Prefix>
397
725
  <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_M-2'>
398
726
  <Mass symbol='M' powerNumerator='-2'/>
@@ -429,7 +757,7 @@ OUTPUT
429
757
  </mrow>
430
758
  </msup>
431
759
  </mrow>
432
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#D_MT-2'>
760
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#NISTd37'>
433
761
  <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
434
762
  <UnitName xml:lang='en'>kg*s^-2</UnitName>
435
763
  <UnitSymbol type='HTML'>
@@ -461,8 +789,11 @@ OUTPUT
461
789
  <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
462
790
  <PrefixName xml:lang='en'>kilo</PrefixName>
463
791
  <PrefixSymbol type='ASCII'>k</PrefixSymbol>
792
+ <PrefixSymbol type='unicode'>k</PrefixSymbol>
793
+ <PrefixSymbol type='LaTeX'>k</PrefixSymbol>
794
+ <PrefixSymbol type='HTML'>k</PrefixSymbol>
464
795
  </Prefix>
465
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_MT-2'>
796
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd37'>
466
797
  <Mass symbol='M' powerNumerator='1'/>
467
798
  <Time symbol='T' powerNumerator='-2'/>
468
799
  </Dimension>
@@ -487,7 +818,7 @@ OUTPUT
487
818
  </mrow>
488
819
  </msup>
489
820
  </mrow>
490
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#D_MT-2'>
821
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#NISTd37'>
491
822
  <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
492
823
  <UnitName xml:lang='en'>kg*s^-2</UnitName>
493
824
  <UnitSymbol type='HTML'>
@@ -519,8 +850,11 @@ OUTPUT
519
850
  <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
520
851
  <PrefixName xml:lang='en'>kilo</PrefixName>
521
852
  <PrefixSymbol type='ASCII'>k</PrefixSymbol>
853
+ <PrefixSymbol type='unicode'>k</PrefixSymbol>
854
+ <PrefixSymbol type='LaTeX'>k</PrefixSymbol>
855
+ <PrefixSymbol type='HTML'>k</PrefixSymbol>
522
856
  </Prefix>
523
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_MT-2'>
857
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd37'>
524
858
  <Mass symbol='M' powerNumerator='1'/>
525
859
  <Time symbol='T' powerNumerator='-2'/>
526
860
  </Dimension>
@@ -545,7 +879,7 @@ OUTPUT
545
879
  </mrow>
546
880
  </msup>
547
881
  </mrow>
548
- <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#D_MT-2'>
882
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_kg.s-2' dimensionURL='#NISTd37'>
549
883
  <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
550
884
  <UnitName xml:lang='en'>kg*s^-2</UnitName>
551
885
  <UnitSymbol type='HTML'>
@@ -577,12 +911,283 @@ OUTPUT
577
911
  <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
578
912
  <PrefixName xml:lang='en'>kilo</PrefixName>
579
913
  <PrefixSymbol type='ASCII'>k</PrefixSymbol>
914
+ <PrefixSymbol type='unicode'>k</PrefixSymbol>
915
+ <PrefixSymbol type='LaTeX'>k</PrefixSymbol>
916
+ <PrefixSymbol type='HTML'>k</PrefixSymbol>
580
917
  </Prefix>
581
- <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='D_MT-2'>
918
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd37'>
582
919
  <Mass symbol='M' powerNumerator='1'/>
583
920
  <Time symbol='T' powerNumerator='-2'/>
584
921
  </Dimension>
585
922
  </math>
586
923
  OUTPUT
587
924
  end
925
+
926
+ it "deals with dimension decomposition with like units" do
927
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
928
+ 9 "unitsml(mW*cm^(-2))"
929
+ INPUT
930
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
931
+ <mn>9</mn>
932
+ <mo rspace='thickmathspace'>&#x2062;</mo>
933
+ <mrow xref='U_mW.cm-2'>
934
+ <mi mathvariant='normal'>mW</mi>
935
+ <mo>&#xB7;</mo>
936
+ <msup>
937
+ <mrow>
938
+ <mi mathvariant='normal'>cm</mi>
939
+ </mrow>
940
+ <mrow>
941
+ <mo>&#x2212;</mo>
942
+ <mn>2</mn>
943
+ </mrow>
944
+ </msup>
945
+ </mrow>
946
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_mW.cm-2'>
947
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
948
+ <UnitName xml:lang='en'>mW*cm^-2</UnitName>
949
+ <UnitSymbol type='HTML'>
950
+ mW&#xB7;cm
951
+ <sup>&#x2212;2</sup>
952
+ </UnitSymbol>
953
+ <UnitSymbol type='MathML'>
954
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
955
+ <mrow>
956
+ <mi mathvariant='normal'>mW</mi>
957
+ <mo>&#xB7;</mo>
958
+ <msup>
959
+ <mrow>
960
+ <mi mathvariant='normal'>cm</mi>
961
+ </mrow>
962
+ <mrow>
963
+ <mo>&#x2212;</mo>
964
+ <mn>2</mn>
965
+ </mrow>
966
+ </msup>
967
+ </mrow>
968
+ </math>
969
+ </UnitSymbol>
970
+ <RootUnits>
971
+ <EnumeratedRootUnit unit='watt' prefix='m'/>
972
+ <EnumeratedRootUnit unit='meter' prefix='c' powerNumerator='-2'/>
973
+ </RootUnits>
974
+ </Unit>
975
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-3' xml:id='NISTp10_-3'>
976
+ <PrefixName xml:lang='en'>milli</PrefixName>
977
+ <PrefixSymbol type='ASCII'>m</PrefixSymbol>
978
+ <PrefixSymbol type='unicode'>m</PrefixSymbol>
979
+ <PrefixSymbol type='LaTeX'>m</PrefixSymbol>
980
+ <PrefixSymbol type='HTML'>m</PrefixSymbol>
981
+ </Prefix>
982
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-2' xml:id='NISTp10_-2'>
983
+ <PrefixName xml:lang='en'>centi</PrefixName>
984
+ <PrefixSymbol type='ASCII'>c</PrefixSymbol>
985
+ <PrefixSymbol type='unicode'>c</PrefixSymbol>
986
+ <PrefixSymbol type='LaTeX'>c</PrefixSymbol>
987
+ <PrefixSymbol type='HTML'>c</PrefixSymbol>
988
+ </Prefix>
989
+ </math>
990
+ OUTPUT
991
+ end
992
+
993
+ it "deals with quantity input" do
994
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
995
+ 9 "unitsml(m, quantity: NISTq103)"
996
+ INPUT
997
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
998
+ <mn>9</mn>
999
+ <mo rspace='thickmathspace'>&#x2062;</mo>
1000
+ <mrow xref='U_NISTu1'>
1001
+ <mi mathvariant='normal'>m</mi>
1002
+ </mrow>
1003
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu1' dimensionURL='#NISTd1'>
1004
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
1005
+ <UnitName xml:lang='en'>meter</UnitName>
1006
+ <UnitSymbol type='HTML'>m</UnitSymbol>
1007
+ <UnitSymbol type='MathML'>
1008
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1009
+ <mrow>
1010
+ <mi mathvariant='normal'>m</mi>
1011
+ </mrow>
1012
+ </math>
1013
+ </UnitSymbol>
1014
+ </Unit>
1015
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd1'>
1016
+ <Length symbol='L' powerNumerator='1'/>
1017
+ </Dimension>
1018
+ <Quantity xmlns='http://unitsml.nist.gov/2005' xml:id='NISTq103' dimensionURL='#NISTd1' quantityType='base'>
1019
+ <QuantityName xml:lang='en-US'>position vector</QuantityName>
1020
+ </Quantity>
1021
+ </math>
1022
+ OUTPUT
1023
+ end
1024
+
1025
+ it "deals with name input" do
1026
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
1027
+ 9 "unitsml(cal_th/cm^2, name: langley)"
1028
+ INPUT
1029
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1030
+ <mn>9</mn>
1031
+ <mo rspace='thickmathspace'>&#x2062;</mo>
1032
+ <mrow xref='U_cal_th/cm2'>
1033
+ <msub>
1034
+ <mrow>
1035
+ <mi mathvariant='normal'>cal</mi>
1036
+ </mrow>
1037
+ <mrow>
1038
+ <mi mathvariant='normal'>th</mi>
1039
+ </mrow>
1040
+ </msub>
1041
+ <mo>/</mo>
1042
+ <msup>
1043
+ <mrow>
1044
+ <mi mathvariant='normal'>cm</mi>
1045
+ </mrow>
1046
+ <mrow>
1047
+ <mn>2</mn>
1048
+ </mrow>
1049
+ </msup>
1050
+ </mrow>
1051
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_cal_th.cm-2'>
1052
+ <UnitSystem name='not_SI' type='not_SI' xml:lang='en-US'/>
1053
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
1054
+ <UnitName xml:lang='en'>langley</UnitName>
1055
+ <UnitSymbol type='HTML'>
1056
+ cal
1057
+ <sub>th</sub>
1058
+ &#xB7;cm
1059
+ <sup>&#x2212;2</sup>
1060
+ </UnitSymbol>
1061
+ <UnitSymbol type='MathML'>
1062
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1063
+ <mrow>
1064
+ <msub>
1065
+ <mrow>
1066
+ <mi mathvariant='normal'>cal</mi>
1067
+ </mrow>
1068
+ <mrow>
1069
+ <mi mathvariant='normal'>th</mi>
1070
+ </mrow>
1071
+ </msub>
1072
+ <mo>&#xB7;</mo>
1073
+ <msup>
1074
+ <mrow>
1075
+ <mi mathvariant='normal'>cm</mi>
1076
+ </mrow>
1077
+ <mrow>
1078
+ <mo>&#x2212;</mo>
1079
+ <mn>2</mn>
1080
+ </mrow>
1081
+ </msup>
1082
+ </mrow>
1083
+ </math>
1084
+ </UnitSymbol>
1085
+ <RootUnits>
1086
+ <EnumeratedRootUnit unit='thermochemical calorie'/>
1087
+ <EnumeratedRootUnit unit='meter' prefix='c' powerNumerator='-2'/>
1088
+ </RootUnits>
1089
+ </Unit>
1090
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-2' xml:id='NISTp10_-2'>
1091
+ <PrefixName xml:lang='en'>centi</PrefixName>
1092
+ <PrefixSymbol type='ASCII'>c</PrefixSymbol>
1093
+ <PrefixSymbol type='unicode'>c</PrefixSymbol>
1094
+ <PrefixSymbol type='LaTeX'>c</PrefixSymbol>
1095
+ <PrefixSymbol type='HTML'>c</PrefixSymbol>
1096
+ </Prefix>
1097
+ </math>
1098
+ OUTPUT
1099
+ end
1100
+
1101
+ it "deals with symbol input" do
1102
+ expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
1103
+ 9 "unitsml(m, symbol: La)" + 10 "unitsml(cm*s^-2, symbol: cm cdot s^-2)"
1104
+ INPUT
1105
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1106
+ <mn>9</mn>
1107
+ <mo rspace='thickmathspace'>&#x2062;</mo>
1108
+ <mrow xref='U_NISTu1'>
1109
+ <math>
1110
+ <mi mathvariant='normal'>L</mi>
1111
+ <mi mathvariant='normal'>a</mi>
1112
+ </math>
1113
+ </mrow>
1114
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_NISTu1' dimensionURL='#NISTd1'>
1115
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
1116
+ <UnitName xml:lang='en'>meter</UnitName>
1117
+ <UnitSymbol type='HTML'>m</UnitSymbol>
1118
+ <UnitSymbol type='MathML'>
1119
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1120
+ <mrow>
1121
+ <mi mathvariant='normal'>m</mi>
1122
+ </mrow>
1123
+ </math>
1124
+ </UnitSymbol>
1125
+ </Unit>
1126
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd1'>
1127
+ <Length symbol='L' powerNumerator='1'/>
1128
+ </Dimension>
1129
+ <mo>+</mo>
1130
+ <mn>10</mn>
1131
+ <mo rspace='thickmathspace'>&#x2062;</mo>
1132
+ <mrow xref='U_cm.s-2'>
1133
+ <math>
1134
+ <mi mathvariant='normal'>c</mi>
1135
+ <mi mathvariant='normal'>m</mi>
1136
+ <mo>&#x22C5;</mo>
1137
+ <msup>
1138
+ <mrow>
1139
+ <mi mathvariant='normal'>s</mi>
1140
+ </mrow>
1141
+ <mrow>
1142
+ <mo>&#x2212;</mo>
1143
+ </mrow>
1144
+ </msup>
1145
+ <mn>2</mn>
1146
+ </math>
1147
+ </mrow>
1148
+ <Unit xmlns='http://unitsml.nist.gov/2005' xml:id='U_cm.s-2' dimensionURL='#NISTd28'>
1149
+ <UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
1150
+ <UnitName xml:lang='en'>cm*s^-2</UnitName>
1151
+ <UnitSymbol type='HTML'>
1152
+ cm&#xB7;s
1153
+ <sup>&#x2212;2</sup>
1154
+ </UnitSymbol>
1155
+ <UnitSymbol type='MathML'>
1156
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
1157
+ <mrow>
1158
+ <mi mathvariant='normal'>cm</mi>
1159
+ <mo>&#xB7;</mo>
1160
+ <msup>
1161
+ <mrow>
1162
+ <mi mathvariant='normal'>s</mi>
1163
+ </mrow>
1164
+ <mrow>
1165
+ <mo>&#x2212;</mo>
1166
+ <mn>2</mn>
1167
+ </mrow>
1168
+ </msup>
1169
+ </mrow>
1170
+ </math>
1171
+ </UnitSymbol>
1172
+ <RootUnits>
1173
+ <EnumeratedRootUnit unit='meter' prefix='c'/>
1174
+ <EnumeratedRootUnit unit='second' powerNumerator='-2'/>
1175
+ </RootUnits>
1176
+ </Unit>
1177
+ <Prefix xmlns='http://unitsml.nist.gov/2005' prefixBase='10' prefixPower='-2' xml:id='NISTp10_-2'>
1178
+ <PrefixName xml:lang='en'>centi</PrefixName>
1179
+ <PrefixSymbol type='ASCII'>c</PrefixSymbol>
1180
+ <PrefixSymbol type='unicode'>c</PrefixSymbol>
1181
+ <PrefixSymbol type='LaTeX'>c</PrefixSymbol>
1182
+ <PrefixSymbol type='HTML'>c</PrefixSymbol>
1183
+ </Prefix>
1184
+ <Dimension xmlns='http://unitsml.nist.gov/2005' xml:id='NISTd28'>
1185
+ <Length symbol='L' powerNumerator='1'/>
1186
+ <Time symbol='T' powerNumerator='-2'/>
1187
+ </Dimension>
1188
+ </math>
1189
+ OUTPUT
1190
+ end
1191
+
1192
+
588
1193
  end