asciimath2unitsml 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciimath2unitsml/parse.rb +6 -5
- data/lib/asciimath2unitsml/version.rb +1 -1
- data/spec/conv_spec.rb +143 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eabcf099e41ebc168ea5904e903893af61c95667e0f778fdf17e39e18fd867a
|
4
|
+
data.tar.gz: 6316d4d968b656249cd69b255e8c68f9f0c7307055fe55d205902c9409d21a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4450d314da42fa0941730c668090c7d3bef43ccd8da4a9ad7e5b29a008dcb8abbf9935732229f988a58cbe624ec10eba52e2400efddb7b09a71b6fe51d9ee579
|
7
|
+
data.tar.gz: 66e66fee285dc9788006a58b98e0e3660b8e829aa29c601eb45a3d2ad263da31582df9267a2a93053f24d0ff89503092395b0ec1ff3ffe8d99ec6161b05a260c
|
@@ -97,14 +97,15 @@ module Asciimath2UnitsML
|
|
97
97
|
seq("sqrt(", unit1, ")") { |x| { prefix: nil, unit: x[1], display_exponent: "0.5" } } |
|
98
98
|
seq("sqrt(", prefix1, unit1, ")") { |x| { prefix: x[1], unit: x[2], display_exponent: "0.5" } } |
|
99
99
|
seq("sqrt(", prefix2, unit1, ")") { |x| { prefix: x[1], unit: x[2], display_exponent: "0.5" } } |
|
100
|
-
seq(unit1, exponent._? & multiplier) { |x| { prefix: nil, unit: x[0], display_exponent: (x[1][0] )} } |
|
100
|
+
seq(unit1, exponent._? & (multiplier | ")".r)) { |x| { prefix: nil, unit: x[0], display_exponent: (x[1][0] )} } |
|
101
101
|
seq(unit1, exponent._?).eof { |x| { prefix: nil, unit: x[0], display_exponent: (x[1][0] )} } |
|
102
102
|
seq(prefix1, unit1, exponent._? ) { |x| { prefix: x[0], unit: x[1], display_exponent: (x[2][0] ) } } |
|
103
103
|
seq(prefix2, unit1, exponent._? ) { |x| { prefix: x[0], unit: x[1], display_exponent: (x[2][0] ) } } |
|
104
|
-
"1".r.map { |_| { prefix: nil, unit: "1", display_exponent: nil } }
|
104
|
+
"1".r.map { |_| { prefix: nil, unit: "1", display_exponent: nil } }
|
105
|
+
units1 = "(".r >> lazy{units} << ")" | unit
|
105
106
|
units = seq(prefix2, "-") { |x| [{ prefix: x[0], unit: nil, display_exponent: nil }] } |
|
106
107
|
seq(prefix1, "-") { |x| [{ prefix: x[0], unit: nil, display_exponent: nil }] } |
|
107
|
-
|
108
|
+
units1.join(multiplier)
|
108
109
|
parser = units.eof
|
109
110
|
end
|
110
111
|
|
@@ -119,7 +120,7 @@ module Asciimath2UnitsML
|
|
119
120
|
end
|
120
121
|
|
121
122
|
def postprocess(units, text)
|
122
|
-
units = postprocess1(units)
|
123
|
+
units = postprocess1(units.flatten)
|
123
124
|
quantity = text[1..-1]&.select { |x| /^quantity:/.match(x) }&.first&.sub(/^quantity:\s*/, "")
|
124
125
|
name = text[1..-1]&.select { |x| /^name:/.match(x) }&.first&.sub(/^name:\s*/, "")
|
125
126
|
symbol = text[1..-1]&.select { |x| /^symbol:/.match(x) }&.first&.sub(/^symbol:\s*/, "")
|
@@ -135,7 +136,7 @@ module Asciimath2UnitsML
|
|
135
136
|
inverse = false
|
136
137
|
units.each_with_object([]) do |u, m|
|
137
138
|
if u[:multiplier]
|
138
|
-
inverse = (u[:multiplier] == "/")
|
139
|
+
inverse = !inverse if (u[:multiplier] == "/")
|
139
140
|
else
|
140
141
|
u[:exponent] = inverse ? "-#{u[:display_exponent] || '1'}" : u[:display_exponent]
|
141
142
|
u[:exponent] = u[:exponent]&.sub(/^--+/, "")
|
data/spec/conv_spec.rb
CHANGED
@@ -489,6 +489,78 @@ OUTPUT
|
|
489
489
|
OUTPUT
|
490
490
|
end
|
491
491
|
|
492
|
+
it "deals with parentheses" do
|
493
|
+
expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
|
494
|
+
10 "unitsml(K/(kg*m))"
|
495
|
+
INPUT
|
496
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML'>
|
497
|
+
<mn>10</mn>
|
498
|
+
<mo rspace='thickmathspace'>⁢</mo>
|
499
|
+
<mrow xref='U_K/kg.m'>
|
500
|
+
<mi mathvariant='normal'>K</mi>
|
501
|
+
<mo>/</mo>
|
502
|
+
<mi mathvariant='normal'>kg</mi>
|
503
|
+
<mo>·</mo>
|
504
|
+
<mi mathvariant='normal'>m</mi>
|
505
|
+
</mrow>
|
506
|
+
<Unit xmlns='https://schema.unitsml.org/unitsml/1.0' xml:id='U_K.kg-1.m-1' dimensionURL='#D_L-1M-1Theta'>
|
507
|
+
<UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
|
508
|
+
<UnitName xml:lang='en'>K*kg^-1*m^-1</UnitName>
|
509
|
+
<UnitSymbol type='HTML'>
|
510
|
+
K·kg
|
511
|
+
<sup>−1</sup>
|
512
|
+
·m
|
513
|
+
<sup>−1</sup>
|
514
|
+
</UnitSymbol>
|
515
|
+
<UnitSymbol type='MathML'>
|
516
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML'>
|
517
|
+
<mrow>
|
518
|
+
<mi mathvariant='normal'>K</mi>
|
519
|
+
<mo>·</mo>
|
520
|
+
<msup>
|
521
|
+
<mrow>
|
522
|
+
<mi mathvariant='normal'>kg</mi>
|
523
|
+
</mrow>
|
524
|
+
<mrow>
|
525
|
+
<mo>−</mo>
|
526
|
+
<mn>1</mn>
|
527
|
+
</mrow>
|
528
|
+
</msup>
|
529
|
+
<mo>·</mo>
|
530
|
+
<msup>
|
531
|
+
<mrow>
|
532
|
+
<mi mathvariant='normal'>m</mi>
|
533
|
+
</mrow>
|
534
|
+
<mrow>
|
535
|
+
<mo>−</mo>
|
536
|
+
<mn>1</mn>
|
537
|
+
</mrow>
|
538
|
+
</msup>
|
539
|
+
</mrow>
|
540
|
+
</math>
|
541
|
+
</UnitSymbol>
|
542
|
+
<RootUnits>
|
543
|
+
<EnumeratedRootUnit unit='kelvin'/>
|
544
|
+
<EnumeratedRootUnit unit='gram' prefix='k' powerNumerator='-1'/>
|
545
|
+
<EnumeratedRootUnit unit='meter' powerNumerator='-1'/>
|
546
|
+
</RootUnits>
|
547
|
+
</Unit>
|
548
|
+
<Prefix xmlns='https://schema.unitsml.org/unitsml/1.0' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
|
549
|
+
<PrefixName xml:lang='en'>kilo</PrefixName>
|
550
|
+
<PrefixSymbol type='ASCII'>k</PrefixSymbol>
|
551
|
+
<PrefixSymbol type='unicode'>k</PrefixSymbol>
|
552
|
+
<PrefixSymbol type='LaTeX'>k</PrefixSymbol>
|
553
|
+
<PrefixSymbol type='HTML'>k</PrefixSymbol>
|
554
|
+
</Prefix>
|
555
|
+
<Dimension xmlns='https://schema.unitsml.org/unitsml/1.0' xml:id='D_L-1M-1Theta'>
|
556
|
+
<Length symbol='L' powerNumerator='-1'/>
|
557
|
+
<Mass symbol='M' powerNumerator='-1'/>
|
558
|
+
<ThermodynamicTemperature symbol='Theta' powerNumerator='1'/>
|
559
|
+
</Dimension>
|
560
|
+
</math>
|
561
|
+
OUTPUT
|
562
|
+
end
|
563
|
+
|
492
564
|
it "deals with notational variants" do
|
493
565
|
expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
|
494
566
|
9 "unitsml(degK)" + 10 "unitsml(K)"
|
@@ -647,7 +719,7 @@ INPUT
|
|
647
719
|
|
648
720
|
it "deals with units division" do
|
649
721
|
expect(xmlpp(Asciimath2UnitsML::Conv.new().Asciimath2UnitsML(<<~INPUT))).to be_equivalent_to xmlpp(<<~OUTPUT)
|
650
|
-
9 "unitsml(A*C^3)" + 13 "unitsml(A/C^-3)"
|
722
|
+
9 "unitsml(A*C^3)" + 13 "unitsml(A/C^-3)" + 2 "unitsml(J/kg*K)"
|
651
723
|
INPUT
|
652
724
|
<math xmlns='http://www.w3.org/1998/Math/MathML'>
|
653
725
|
<mn>9</mn>
|
@@ -712,6 +784,76 @@ INPUT
|
|
712
784
|
</mrow>
|
713
785
|
</msup>
|
714
786
|
</mrow>
|
787
|
+
<mo>+</mo>
|
788
|
+
<mn>2</mn>
|
789
|
+
<mo rspace='thickmathspace'>⁢</mo>
|
790
|
+
<mrow xref='U_J/kg.K'>
|
791
|
+
<mi mathvariant='normal'>J</mi>
|
792
|
+
<mo>/</mo>
|
793
|
+
<mi mathvariant='normal'>kg</mi>
|
794
|
+
<mo>·</mo>
|
795
|
+
<mi mathvariant='normal'>K</mi>
|
796
|
+
</mrow>
|
797
|
+
<Unit xmlns='https://schema.unitsml.org/unitsml/1.0' xml:id='U_NISTu13.u27p10_3e-1/1.u5e-1/1' dimensionURL='#D_L2M0T-2Theta-1'>
|
798
|
+
<UnitSystem name='SI' type='SI_derived' xml:lang='en-US'/>
|
799
|
+
<UnitName xml:lang='en'>joule per kilogram kelvin</UnitName>
|
800
|
+
<UnitSymbol type='HTML'>
|
801
|
+
J·kg
|
802
|
+
<sup>−1</sup>
|
803
|
+
·K
|
804
|
+
<sup>−1</sup>
|
805
|
+
</UnitSymbol>
|
806
|
+
<UnitSymbol type='MathML'>
|
807
|
+
<math xmlns='http://www.w3.org/1998/Math/MathML'>
|
808
|
+
<mrow>
|
809
|
+
<mi mathvariant='normal'>J</mi>
|
810
|
+
<mo>·</mo>
|
811
|
+
<msup>
|
812
|
+
<mrow>
|
813
|
+
<mi mathvariant='normal'>kg</mi>
|
814
|
+
</mrow>
|
815
|
+
<mrow>
|
816
|
+
<mo>−</mo>
|
817
|
+
<mn>1</mn>
|
818
|
+
</mrow>
|
819
|
+
</msup>
|
820
|
+
<mo>·</mo>
|
821
|
+
<msup>
|
822
|
+
<mrow>
|
823
|
+
<mi mathvariant='normal'>K</mi>
|
824
|
+
</mrow>
|
825
|
+
<mrow>
|
826
|
+
<mo>−</mo>
|
827
|
+
<mn>1</mn>
|
828
|
+
</mrow>
|
829
|
+
</msup>
|
830
|
+
</mrow>
|
831
|
+
</math>
|
832
|
+
</UnitSymbol>
|
833
|
+
<RootUnits>
|
834
|
+
<EnumeratedRootUnit unit='joule'/>
|
835
|
+
<EnumeratedRootUnit unit='gram' prefix='k' powerNumerator='-1'/>
|
836
|
+
<EnumeratedRootUnit unit='kelvin' powerNumerator='-1'/>
|
837
|
+
</RootUnits>
|
838
|
+
</Unit>
|
839
|
+
<Prefix xmlns='https://schema.unitsml.org/unitsml/1.0' prefixBase='10' prefixPower='3' xml:id='NISTp10_3'>
|
840
|
+
<PrefixName xml:lang='en'>kilo</PrefixName>
|
841
|
+
<PrefixSymbol type='ASCII'>k</PrefixSymbol>
|
842
|
+
<PrefixSymbol type='unicode'>k</PrefixSymbol>
|
843
|
+
<PrefixSymbol type='LaTeX'>k</PrefixSymbol>
|
844
|
+
<PrefixSymbol type='HTML'>k</PrefixSymbol>
|
845
|
+
</Prefix>
|
846
|
+
<Dimension xmlns='https://schema.unitsml.org/unitsml/1.0' xml:id='NISTd40'>
|
847
|
+
<Length symbol='L' powerNumerator='2'/>
|
848
|
+
<Time symbol='T' powerNumerator='-2'/>
|
849
|
+
<ThermodynamicTemperature symbol='Theta' powerNumerator='-1'/>
|
850
|
+
</Dimension>
|
851
|
+
<Dimension xmlns='https://schema.unitsml.org/unitsml/1.0' xml:id='D_L2M0T-2Theta-1'>
|
852
|
+
<Length symbol='L' powerNumerator='2'/>
|
853
|
+
<Mass symbol='M' powerNumerator='0'/>
|
854
|
+
<Time symbol='T' powerNumerator='-2'/>
|
855
|
+
<ThermodynamicTemperature symbol='Theta' powerNumerator='-1'/>
|
856
|
+
</Dimension>
|
715
857
|
</math>
|
716
858
|
OUTPUT
|
717
859
|
end
|