unitsml 0.5.1 → 0.6.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 +4 -4
- data/.github/workflows/rake.yml +8 -0
- data/.github/workflows/release.yml +7 -1
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +498 -0
- data/Gemfile +16 -11
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/docs/README.adoc +2 -2
- data/lib/unitsml/dimension.rb +49 -35
- data/lib/unitsml/errors/base_error.rb +8 -0
- data/lib/unitsml/errors/plurimath_load_error.rb +1 -1
- data/lib/unitsml/errors.rb +8 -0
- data/lib/unitsml/extender.rb +21 -16
- data/lib/unitsml/fenced.rb +30 -10
- data/lib/unitsml/fenced_numeric.rb +13 -0
- data/lib/unitsml/formula.rb +29 -29
- data/lib/unitsml/intermediate_exp_rules.rb +58 -17
- data/lib/unitsml/model/dimension.rb +4 -14
- data/lib/unitsml/model/dimension_quantities/quantity.rb +2 -0
- data/lib/unitsml/model/dimension_quantities.rb +17 -0
- data/lib/unitsml/model/prefix.rb +4 -8
- data/lib/unitsml/model/prefixes/name.rb +5 -4
- data/lib/unitsml/model/prefixes/symbol.rb +3 -2
- data/lib/unitsml/model/prefixes.rb +10 -0
- data/lib/unitsml/model/quantities/name.rb +4 -3
- data/lib/unitsml/model/quantities.rb +9 -0
- data/lib/unitsml/model/quantity.rb +5 -7
- data/lib/unitsml/model/unit.rb +4 -9
- data/lib/unitsml/model/units/enumerated_root_unit.rb +1 -0
- data/lib/unitsml/model/units/name.rb +4 -3
- data/lib/unitsml/model/units/root_units.rb +3 -2
- data/lib/unitsml/model/units/symbol.rb +2 -1
- data/lib/unitsml/model/units/system.rb +4 -3
- data/lib/unitsml/model/units.rb +13 -0
- data/lib/unitsml/model.rb +15 -0
- data/lib/unitsml/namespace.rb +8 -0
- data/lib/unitsml/number.rb +79 -0
- data/lib/unitsml/parse.rb +20 -19
- data/lib/unitsml/parser.rb +13 -14
- data/lib/unitsml/prefix.rb +10 -10
- data/lib/unitsml/sqrt.rb +3 -3
- data/lib/unitsml/transform.rb +133 -71
- data/lib/unitsml/unit.rb +41 -33
- data/lib/unitsml/unitsdb/dimension.rb +3 -3
- data/lib/unitsml/unitsdb/dimensions.rb +2 -4
- data/lib/unitsml/unitsdb/prefixes.rb +0 -2
- data/lib/unitsml/unitsdb/quantities.rb +0 -2
- data/lib/unitsml/unitsdb/unit.rb +2 -2
- data/lib/unitsml/unitsdb/units.rb +2 -4
- data/lib/unitsml/unitsdb.rb +14 -9
- data/lib/unitsml/utility.rb +111 -73
- data/lib/unitsml/version.rb +3 -1
- data/lib/unitsml.rb +51 -33
- data/unitsdb/Gemfile +6 -0
- data/unitsdb/README.adoc +193 -11
- data/unitsdb/dimensions.yaml +360 -8
- data/unitsdb/prefixes.yaml +104 -4
- data/unitsdb/quantities.yaml +602 -0
- data/unitsdb/schemas/dimensions-schema.yaml +2 -6
- data/unitsdb/schemas/prefixes-schema.yaml +2 -6
- data/unitsdb/schemas/quantities-schema.yaml +2 -5
- data/unitsdb/schemas/scales-schema.yaml +2 -5
- data/unitsdb/schemas/unit_systems-schema.yaml +2 -6
- data/unitsdb/schemas/units-schema.yaml +2 -6
- data/unitsdb/spec/units_spec.rb +3 -1
- data/unitsdb/unit_systems.yaml +4 -0
- data/unitsdb/units.yaml +957 -6
- data/unitsdb/validate_schemas.rb +32 -37
- data/unitsml.gemspec +3 -1
- metadata +29 -17
- data/lib/unitsml/error.rb +0 -8
data/lib/unitsml/dimension.rb
CHANGED
|
@@ -9,63 +9,59 @@ module Unitsml
|
|
|
9
9
|
@power_numerator = power_numerator
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def ==(
|
|
13
|
-
self.class ==
|
|
14
|
-
dimension_name ==
|
|
15
|
-
power_numerator ==
|
|
12
|
+
def ==(other)
|
|
13
|
+
self.class == other.class &&
|
|
14
|
+
dimension_name == other&.dimension_name &&
|
|
15
|
+
power_numerator == other&.power_numerator
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def dim_instance
|
|
19
|
-
@
|
|
19
|
+
@dim_instance ||= Unitsdb.dimensions.find_parsables_by_id(dimension_name)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def dim_symbols
|
|
23
|
-
dim_instance.send(
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def to_mathml(
|
|
27
|
-
# MathML key's value in unitsdb/dimensions.yaml
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if power_numerator
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
),
|
|
37
|
-
]
|
|
38
|
-
)
|
|
39
|
-
end
|
|
23
|
+
dim_instance.send(dim_instance.processed_keys.last).symbols.first
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_mathml(options)
|
|
27
|
+
# MathML key's value in unitsdb/dimensions.yaml
|
|
28
|
+
# file includes mi tags only.
|
|
29
|
+
value = ::Mml::V4::Mi.from_xml(dim_symbols.mathml)
|
|
30
|
+
method_name = if power_numerator
|
|
31
|
+
value = msup_tag(value, options)
|
|
32
|
+
:msup
|
|
33
|
+
else
|
|
34
|
+
:mi
|
|
35
|
+
end
|
|
40
36
|
{ method_name: method_name, value: value }
|
|
41
37
|
end
|
|
42
38
|
|
|
43
|
-
def to_latex(
|
|
44
|
-
power_numerator_generic_code(:latex)
|
|
39
|
+
def to_latex(options)
|
|
40
|
+
power_numerator_generic_code(:latex, options)
|
|
45
41
|
end
|
|
46
42
|
|
|
47
|
-
def to_asciimath(
|
|
48
|
-
power_numerator_generic_code(:ascii)
|
|
43
|
+
def to_asciimath(options)
|
|
44
|
+
power_numerator_generic_code(:ascii, options)
|
|
49
45
|
end
|
|
50
46
|
|
|
51
|
-
def to_unicode(
|
|
52
|
-
power_numerator_generic_code(:unicode)
|
|
47
|
+
def to_unicode(options)
|
|
48
|
+
power_numerator_generic_code(:unicode, options)
|
|
53
49
|
end
|
|
54
50
|
|
|
55
|
-
def to_html(
|
|
51
|
+
def to_html(options)
|
|
56
52
|
value = dim_symbols.html
|
|
57
|
-
value = "#{value}
|
|
53
|
+
value = "#{value}#{html_numerator_conversion(options)}" if power_numerator
|
|
58
54
|
value
|
|
59
55
|
end
|
|
60
56
|
|
|
61
57
|
def generate_id
|
|
62
|
-
"#{dimension_name.split('_').last}#{power_numerator}"
|
|
58
|
+
"#{dimension_name.split('_').last}#{power_numerator&.raw_value}"
|
|
63
59
|
end
|
|
64
60
|
|
|
65
61
|
def to_xml(_)
|
|
66
62
|
attributes = {
|
|
67
63
|
symbol: dim_instance.processed_symbol,
|
|
68
|
-
power_numerator: power_numerator || 1
|
|
64
|
+
power_numerator: power_numerator&.raw_value || 1
|
|
69
65
|
}
|
|
70
66
|
Model::DimensionQuantities.const_get(modelize(element_name)).new(attributes)
|
|
71
67
|
end
|
|
@@ -75,20 +71,38 @@ module Unitsml
|
|
|
75
71
|
end
|
|
76
72
|
|
|
77
73
|
def modelize(value)
|
|
78
|
-
value&.split(
|
|
74
|
+
value&.split('_')&.map(&:capitalize)&.join
|
|
79
75
|
end
|
|
80
76
|
|
|
81
77
|
private
|
|
82
78
|
|
|
83
|
-
def
|
|
79
|
+
def html_numerator_conversion(options)
|
|
80
|
+
"<sup>#{power_numerator.to_html(options)}</sup>"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def power_numerator_generic_code(method_name, options)
|
|
84
84
|
value = dim_symbols.public_send(method_name)
|
|
85
85
|
return value unless power_numerator
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
method_name = :asciimath if method_name == :ascii
|
|
88
|
+
"#{value}^#{power_numerator&.public_send(:"to_#{method_name}", options)}"
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
def element_name
|
|
91
92
|
dim_instance.processed_keys.first
|
|
92
93
|
end
|
|
94
|
+
|
|
95
|
+
def msup_tag(value, options)
|
|
96
|
+
mathml = power_numerator.to_mathml(options)
|
|
97
|
+
msup = ::Mml::V4::Msup.new(
|
|
98
|
+
mrow_value: [::Mml::V4::Mrow.new(mi_value: [value])]
|
|
99
|
+
)
|
|
100
|
+
[mathml].flatten.each do |record|
|
|
101
|
+
record_values = msup.public_send("#{record[:method_name]}_value") || []
|
|
102
|
+
record_values += [record[:value]]
|
|
103
|
+
msup.public_send("#{record[:method_name]}_value=", record_values)
|
|
104
|
+
end
|
|
105
|
+
msup
|
|
106
|
+
end
|
|
93
107
|
end
|
|
94
108
|
end
|
data/lib/unitsml/extender.rb
CHANGED
|
@@ -8,22 +8,22 @@ module Unitsml
|
|
|
8
8
|
@symbol = symbol
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def ==(
|
|
12
|
-
self.class ==
|
|
13
|
-
symbol ==
|
|
11
|
+
def ==(other)
|
|
12
|
+
self.class == other.class &&
|
|
13
|
+
symbol == other&.symbol
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def to_mathml(options)
|
|
17
|
-
rspace =
|
|
18
|
-
extender = multiplier(options[:multiplier] ||
|
|
17
|
+
rspace = 'thickmathspace' if options[:multiplier] == :space
|
|
18
|
+
extender = multiplier(options[:multiplier] || '⋅', unicode: true)
|
|
19
19
|
{
|
|
20
20
|
method_name: :mo,
|
|
21
|
-
value: ::Mml::Mo.new(value: extender, rspace: rspace)
|
|
21
|
+
value: ::Mml::V4::Mo.new(value: extender, rspace: rspace)
|
|
22
22
|
}
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def to_latex(options)
|
|
26
|
-
multiplier(options[:multiplier] ||
|
|
26
|
+
multiplier(options[:multiplier] || '/')
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def to_asciimath(options)
|
|
@@ -31,12 +31,11 @@ module Unitsml
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def to_html(options)
|
|
34
|
-
multiplier(options[:multiplier] ||
|
|
34
|
+
multiplier(options[:multiplier] || '⋅', unicode: true, html: true)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def to_unicode(options)
|
|
38
|
-
extender = options[:multiplier] ||
|
|
39
|
-
symbol == "*" ? "·" : symbol
|
|
38
|
+
extender = options[:multiplier] || unicode_extender
|
|
40
39
|
multiplier(extender)
|
|
41
40
|
end
|
|
42
41
|
|
|
@@ -45,16 +44,22 @@ module Unitsml
|
|
|
45
44
|
def multiplier(extender, unicode: false, html: false)
|
|
46
45
|
case extender
|
|
47
46
|
when :space
|
|
48
|
-
|
|
49
|
-
" "
|
|
50
|
-
else
|
|
51
|
-
unicode ? "⁢" : " "
|
|
52
|
-
end
|
|
47
|
+
space_extender(html, unicode)
|
|
53
48
|
when :nospace
|
|
54
|
-
unicode ?
|
|
49
|
+
unicode ? '⁢' : ''
|
|
55
50
|
else
|
|
56
51
|
unicode ? Utility.string_to_html_entity(extender) : extender
|
|
57
52
|
end
|
|
58
53
|
end
|
|
54
|
+
|
|
55
|
+
def space_extender(html, unicode)
|
|
56
|
+
return ' ' if html
|
|
57
|
+
|
|
58
|
+
unicode ? '⁢' : ' '
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def unicode_extender
|
|
62
|
+
symbol == '*' ? '·' : symbol
|
|
63
|
+
end
|
|
59
64
|
end
|
|
60
65
|
end
|
data/lib/unitsml/fenced.rb
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Unitsml
|
|
2
4
|
class Fenced
|
|
5
|
+
include FencedNumeric
|
|
6
|
+
|
|
3
7
|
attr_reader :open_paren, :value, :close_paren
|
|
4
8
|
|
|
5
9
|
def initialize(open_paren, value, close_paren)
|
|
@@ -8,11 +12,11 @@ module Unitsml
|
|
|
8
12
|
@close_paren = close_paren
|
|
9
13
|
end
|
|
10
14
|
|
|
11
|
-
def ==(
|
|
12
|
-
self.class ==
|
|
13
|
-
open_paren ==
|
|
14
|
-
value ==
|
|
15
|
-
close_paren ==
|
|
15
|
+
def ==(other)
|
|
16
|
+
self.class == other.class &&
|
|
17
|
+
open_paren == other&.open_paren &&
|
|
18
|
+
value == other&.value &&
|
|
19
|
+
close_paren == other&.close_paren
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
def to_asciimath(options = {})
|
|
@@ -27,15 +31,31 @@ module Unitsml
|
|
|
27
31
|
mathml = value.to_mathml(options)
|
|
28
32
|
return mathml unless options[:explicit_parenthesis]
|
|
29
33
|
|
|
30
|
-
fenced = ::Mml::Mrow.new(mo_value: [::Mml::Mo.new(value: open_paren)])
|
|
34
|
+
fenced = ::Mml::V4::Mrow.new(mo_value: [::Mml::V4::Mo.new(value: open_paren)])
|
|
31
35
|
fenced.ordered = true
|
|
32
|
-
fenced.element_order ||= [xml_order_element(
|
|
36
|
+
fenced.element_order ||= [xml_order_element('mo')]
|
|
33
37
|
[mathml].flatten.each { |record| add_math_element(fenced, record) }
|
|
34
|
-
fenced.mo_value << ::Mml::Mo.new(value: close_paren)
|
|
35
|
-
fenced.element_order << xml_order_element(
|
|
38
|
+
fenced.mo_value << ::Mml::V4::Mo.new(value: close_paren)
|
|
39
|
+
fenced.element_order << xml_order_element('mo')
|
|
36
40
|
{ method_name: :mrow, value: fenced }
|
|
37
41
|
end
|
|
38
42
|
|
|
43
|
+
def negative?
|
|
44
|
+
value.negative?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update_negative_sign
|
|
48
|
+
value.update_negative_sign
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def float_to_display
|
|
52
|
+
value.float_to_display
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def raw_value
|
|
56
|
+
value.raw_value
|
|
57
|
+
end
|
|
58
|
+
|
|
39
59
|
def to_html(options = {})
|
|
40
60
|
fenced_conversion_for(lang: :html, options: options)
|
|
41
61
|
end
|
|
@@ -64,7 +84,7 @@ module Unitsml
|
|
|
64
84
|
end
|
|
65
85
|
|
|
66
86
|
def xml_order_element(tag_name)
|
|
67
|
-
Lutaml::
|
|
87
|
+
Lutaml::Xml::Element.new('Element', tag_name)
|
|
68
88
|
end
|
|
69
89
|
|
|
70
90
|
def fenced_conversion_for(lang:, options:)
|
data/lib/unitsml/formula.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require "unitsml/utility"
|
|
3
|
+
require 'mml'
|
|
4
|
+
require 'htmlentities'
|
|
6
5
|
|
|
7
6
|
module Unitsml
|
|
8
7
|
class Formula
|
|
@@ -20,25 +19,25 @@ module Unitsml
|
|
|
20
19
|
@norm_text = norm_text
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
def ==(
|
|
24
|
-
self.class ==
|
|
25
|
-
value ==
|
|
26
|
-
explicit_value ==
|
|
27
|
-
root ==
|
|
22
|
+
def ==(other)
|
|
23
|
+
self.class == other.class &&
|
|
24
|
+
value == other&.value &&
|
|
25
|
+
explicit_value == other&.explicit_value &&
|
|
26
|
+
root == other.root
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
def to_mathml(options = {})
|
|
31
30
|
if root
|
|
32
31
|
options = update_options(options)
|
|
33
32
|
nullify_mml_models if plurimath_available?
|
|
34
|
-
math = ::Mml::
|
|
33
|
+
math = ::Mml::V4::Math.new(display: 'block')
|
|
35
34
|
math.ordered = true
|
|
36
35
|
math.element_order ||= []
|
|
37
36
|
value.each { |instance| process_value(math, instance.to_mathml(options)) }
|
|
38
|
-
|
|
39
|
-
generated_math = math.to_xml.gsub(/&(.*?)(?=<\/)/, '&\1')
|
|
37
|
+
generated_math = math.to_xml.gsub(%r{&(.*?)(?=</)}, '&\1')
|
|
40
38
|
reset_mml_models if plurimath_available?
|
|
41
|
-
|
|
39
|
+
|
|
40
|
+
generated_math.force_encoding('UTF-8')
|
|
42
41
|
else
|
|
43
42
|
value.map { |obj| obj.to_mathml(options) }
|
|
44
43
|
end
|
|
@@ -87,19 +86,20 @@ module Unitsml
|
|
|
87
86
|
|
|
88
87
|
def extract_dimensions(formula)
|
|
89
88
|
formula.each_with_object([]) do |term, dimensions|
|
|
90
|
-
|
|
89
|
+
case term
|
|
90
|
+
when Dimension
|
|
91
91
|
dimensions << term
|
|
92
|
-
|
|
92
|
+
when Sqrt
|
|
93
93
|
if term.value.is_a?(Dimension)
|
|
94
94
|
sqrt_term = term.value.dup
|
|
95
|
-
sqrt_term.power_numerator =
|
|
95
|
+
sqrt_term.power_numerator = Number.new('0.5')
|
|
96
96
|
dimensions << sqrt_term
|
|
97
97
|
elsif term.value.is_a?(Fenced)
|
|
98
98
|
dimensions.concat(Array(term.value.dimensions_extraction))
|
|
99
99
|
end
|
|
100
|
-
|
|
100
|
+
when Formula
|
|
101
101
|
dimensions.concat(extract_dimensions(term.value))
|
|
102
|
-
|
|
102
|
+
when Fenced
|
|
103
103
|
dimensions.concat(Array(term.dimensions_extraction))
|
|
104
104
|
end
|
|
105
105
|
end
|
|
@@ -124,20 +124,20 @@ module Unitsml
|
|
|
124
124
|
|
|
125
125
|
def units(options)
|
|
126
126
|
all_units = extract_units(value)
|
|
127
|
-
norm_text = all_units.map(&:xml_postprocess_name).join(
|
|
127
|
+
norm_text = all_units.map(&:xml_postprocess_name).join('*')
|
|
128
128
|
dims = Utility.units2dimensions(extract_units(value))
|
|
129
129
|
[
|
|
130
130
|
Utility.unit(all_units, self, dims, norm_text, explicit_value&.dig(:name), options),
|
|
131
131
|
Utility.prefixes(all_units, options),
|
|
132
132
|
*unique_dimensions(dims, norm_text),
|
|
133
|
-
Utility.quantity(norm_text, explicit_value&.dig(:quantity))
|
|
133
|
+
Utility.quantity(norm_text, explicit_value&.dig(:quantity))
|
|
134
134
|
].join
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
def unique_dimensions(dims, norm_text)
|
|
138
138
|
[
|
|
139
139
|
Utility.dimension(norm_text),
|
|
140
|
-
Utility.dimension_components(dims)
|
|
140
|
+
Utility.dimension_components(dims)
|
|
141
141
|
].uniq
|
|
142
142
|
end
|
|
143
143
|
|
|
@@ -145,31 +145,31 @@ module Unitsml
|
|
|
145
145
|
dim_id = dims.map(&:generate_id).join
|
|
146
146
|
attributes = { id: "D_#{dim_id}" }
|
|
147
147
|
dims.each { |dim| attributes.merge!(dim.xml_instances_hash(options)) }
|
|
148
|
-
Model::Dimension.new(attributes).to_xml
|
|
148
|
+
Model::Dimension.new(attributes).to_xml.force_encoding('UTF-8')
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
def sort_dims(values)
|
|
152
|
-
dims_hash = Utility::
|
|
152
|
+
dims_hash = Utility::DIM2D
|
|
153
153
|
values.sort do |first, second|
|
|
154
154
|
dims_hash.dig(first.dimension_name, :order) <=> dims_hash.dig(second.dimension_name, :order)
|
|
155
155
|
end
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
def prefixes(options)
|
|
159
|
-
norm_text = @norm_text&.split(
|
|
160
|
-
prefix_object = Unit.new(
|
|
159
|
+
norm_text = @norm_text&.split('-')&.first
|
|
160
|
+
prefix_object = Unit.new('', prefix: Prefix.new(norm_text))
|
|
161
161
|
[
|
|
162
162
|
Utility.prefixes([prefix_object], options),
|
|
163
163
|
Utility.dimension(norm_text),
|
|
164
|
-
Utility.quantity(norm_text, explicit_value&.dig(:quantity))
|
|
164
|
+
Utility.quantity(norm_text, explicit_value&.dig(:quantity))
|
|
165
165
|
].join
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
def ensure_plurimath_defined!
|
|
169
169
|
return if plurimath_available?
|
|
170
170
|
|
|
171
|
-
require
|
|
172
|
-
rescue LoadError
|
|
171
|
+
require 'plurimath'
|
|
172
|
+
rescue LoadError
|
|
173
173
|
raise Errors::PlurimathLoadError
|
|
174
174
|
end
|
|
175
175
|
|
|
@@ -178,7 +178,7 @@ module Unitsml
|
|
|
178
178
|
method_value = math_instance.public_send(:"#{method_name}_value") || []
|
|
179
179
|
method_value += Array(child_hash[:value])
|
|
180
180
|
math_instance.public_send(:"#{method_name}_value=", method_value)
|
|
181
|
-
math_instance.element_order << Lutaml::
|
|
181
|
+
math_instance.element_order << Lutaml::Xml::Element.new('Element', method_name.to_s)
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
def plurimath_available?
|
|
@@ -192,7 +192,7 @@ module Unitsml
|
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
def reset_mml_models
|
|
195
|
-
::Mml::Configuration.custom_models = Plurimath::Mathml::Parser::CONFIGURATION
|
|
195
|
+
::Mml::V4::Configuration.custom_models = Plurimath::Mathml::Parser::CONFIGURATION
|
|
196
196
|
end
|
|
197
197
|
|
|
198
198
|
def process_value(math, mathml_instances)
|
|
@@ -1,35 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Unitsml
|
|
2
4
|
module IntermediateExpRules
|
|
3
5
|
include Parslet
|
|
4
6
|
|
|
5
7
|
# Rules for slashed number
|
|
6
|
-
rule(:slashed_number_int_exp)
|
|
8
|
+
rule(:slashed_number_int_exp) do
|
|
9
|
+
slashed_number | (opening_paren >> slashed_number_named_int_exp.as(:int_exp) >> closing_paren)
|
|
10
|
+
end
|
|
11
|
+
rule(:slashed_number_named_int_exp) do
|
|
12
|
+
(opening_paren.as(:open_paren) >> slashed_number_int_exp >> closing_paren.as(:close_paren)) |
|
|
13
|
+
slashed_number_int_exp
|
|
14
|
+
end
|
|
7
15
|
|
|
8
16
|
# Rules for prefixes_units
|
|
9
|
-
rule(:
|
|
10
|
-
|
|
11
|
-
rule(:
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
rule(:wrapper_prefixes_units_value) { int_exp_prefixes_units | prefixes_units_int_exp }
|
|
18
|
+
|
|
19
|
+
rule(:extended_prefixed_units) { extender >> spaces? >> prefixes_units_int_exp.as(:sequence) }
|
|
20
|
+
|
|
21
|
+
rule(:int_exp_prefixes_units) do
|
|
22
|
+
opening_paren >> spaces? >> named_int_exp_prefixes_units.as(:int_exp) >> spaces? >> closing_paren
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
rule(:implicit_extended) do
|
|
26
|
+
prefixes_units.as(:first_set) >> spaces.as(:extender) >> prefixes_units.as(:second_set) |
|
|
27
|
+
int_exp_prefixes_units.as(:first_int_exp_set) >> spaces? >> int_exp_prefixes_units.as(:second_int_exp_set) |
|
|
28
|
+
prefixes_units.as(:first_set) >> spaces? >> int_exp_prefixes_units.as(:second_int_exp_set) |
|
|
29
|
+
int_exp_prefixes_units.as(:first_int_exp_set) >> spaces? >> prefixes_units.as(:second_set)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
rule(:prefixes_units_int_exp) do
|
|
33
|
+
implicit_extended.as(:implicit_extended) >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
34
|
+
implicit_extended.as(:implicit_extended) >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
35
|
+
int_exp_prefixes_units >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
36
|
+
prefixes_units >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
37
|
+
int_exp_prefixes_units >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
38
|
+
prefixes_units >> prefixes_units_int_exp.as(:sequence).maybe
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
rule(:prefixes_units_named_int_exp) do
|
|
42
|
+
opening_paren.as(:open_paren) >> spaces? >> wrapper_prefixes_units_value.as(:int_exp) >> spaces? >> closing_paren.as(:close_paren)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
rule(:named_int_exp_prefixes_units) do
|
|
46
|
+
prefixes_units_named_int_exp.as(:int_exp) >> (prefixes_units_int_exp | extended_prefixed_units).maybe |
|
|
47
|
+
prefixes_units_int_exp
|
|
14
48
|
end
|
|
15
49
|
|
|
16
50
|
# Rules for dimension_rules
|
|
17
|
-
rule(:dimension_rules_int_exp)
|
|
18
|
-
|
|
51
|
+
rule(:dimension_rules_int_exp) do
|
|
52
|
+
dimension_rules.as(:first_set) >> spaces.as(:extender) >> dimension_rules.as(:second_set) >> dimension_rules_int_exp.maybe |
|
|
53
|
+
dimension_rules.as(:first_set) >> spaces? >> int_exp_dimension_rules.as(:second_int_exp_set) >> dimension_rules_int_exp.maybe |
|
|
54
|
+
int_exp_dimension_rules.as(:first_int_exp_set) >> spaces? >> dimension_rules.as(:second_set) >> dimension_rules_int_exp.maybe |
|
|
55
|
+
int_exp_dimension_rules.as(:first_int_exp_set) >> spaces? >> int_exp_dimension_rules.as(:second_int_exp_set) >> dimension_rules_int_exp.maybe |
|
|
56
|
+
int_exp_dimension_rules |
|
|
57
|
+
dimension_rules
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
rule(:int_exp_dimension_rules) do
|
|
61
|
+
opening_paren >> dimension_rules_named_exp.as(:int_exp) >> closing_paren >> extended_dimension_rules.maybe
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
rule(:extended_dimension_rules) { spaces? >> extender >> spaces? >> dimension_rules_int_exp.as(:sequence) }
|
|
19
65
|
rule(:dimension_rules_named_exp) do
|
|
20
|
-
|
|
21
|
-
|
|
66
|
+
((opening_paren.as(:open_paren) >> dimension_rules_int_exp.as(:int_exp) >> closing_paren.as(:close_paren)).as(:int_exp) >> spaces? >> (dimension_rules_int_exp | extended_dimension_rules).as(:sequence).maybe) |
|
|
67
|
+
dimension_rules_int_exp
|
|
22
68
|
end
|
|
23
69
|
|
|
24
70
|
# Rules for dimensions
|
|
25
|
-
rule(:sqrt_dimensions) {
|
|
26
|
-
rule(:powered_dimensions) { dimensions >> power.maybe }
|
|
27
|
-
rule(:dimensions_int_exp) { powered_dimensions | (str("(") >> dimensions_named_exp.as(:intermediate_exp) >> str(")")) }
|
|
28
|
-
rule(:dimensions_named_exp) { powered_dimensions | (str("(").as(:open_parenthesis) >> dimensions_int_exp.as(:int_exp) >> str(")").as(:close_parenthesis)) }
|
|
71
|
+
rule(:sqrt_dimensions) { sqrt >> opening_paren >> dimension_rules_int_exp.as(:sqrt) >> closing_paren }
|
|
29
72
|
|
|
30
73
|
# Rules for sequence
|
|
31
|
-
rule(:sqrt_sequence) {
|
|
32
|
-
rule(:sequence_int_exp) { sequence | (str("(") >> sequence_named_exp.as(:intermediate_exp)>> str(")")) }
|
|
33
|
-
rule(:sequence_named_exp) { sequence | (str("(").as(:open_parenthesis) >> sequence_int_exp.as(:int_exp) >> str(")").as(:close_parenthesis)) }
|
|
74
|
+
rule(:sqrt_sequence) { sqrt >> opening_paren >> prefixes_units_int_exp.as(:sqrt) >> closing_paren }
|
|
34
75
|
end
|
|
35
76
|
end
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "unitsml/model/dimension_quantities/quantity"
|
|
4
|
-
require "unitsml/model/dimension_quantities/length"
|
|
5
|
-
require "unitsml/model/dimension_quantities/mass"
|
|
6
|
-
require "unitsml/model/dimension_quantities/time"
|
|
7
|
-
require "unitsml/model/dimension_quantities/electric_current"
|
|
8
|
-
require "unitsml/model/dimension_quantities/thermodynamic_temperature"
|
|
9
|
-
require "unitsml/model/dimension_quantities/amount_of_substance"
|
|
10
|
-
require "unitsml/model/dimension_quantities/luminous_intensity"
|
|
11
|
-
require "unitsml/model/dimension_quantities/plane_angle"
|
|
12
|
-
|
|
13
3
|
module Unitsml
|
|
14
4
|
module Model
|
|
15
5
|
class Dimension < Lutaml::Model::Serializable
|
|
16
|
-
attribute :id, :
|
|
6
|
+
attribute :id, :xml_id
|
|
17
7
|
attribute :length, DimensionQuantities::Length
|
|
18
8
|
attribute :mass, DimensionQuantities::Mass
|
|
19
9
|
attribute :time, DimensionQuantities::Time
|
|
@@ -24,10 +14,10 @@ module Unitsml
|
|
|
24
14
|
attribute :plane_angle, DimensionQuantities::PlaneAngle
|
|
25
15
|
|
|
26
16
|
xml do
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
namespace ::Unitsml::Namespace
|
|
18
|
+
element 'Dimension'
|
|
29
19
|
|
|
30
|
-
map_attribute :id, to: :id
|
|
20
|
+
map_attribute :id, to: :id
|
|
31
21
|
map_element :Length, to: :length
|
|
32
22
|
map_element :Mass, to: :mass
|
|
33
23
|
map_element :Time, to: :time
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Unitsml
|
|
4
|
+
module Model
|
|
5
|
+
module DimensionQuantities
|
|
6
|
+
autoload :AmountOfSubstance, "#{__dir__}/dimension_quantities/amount_of_substance"
|
|
7
|
+
autoload :ElectricCurrent, "#{__dir__}/dimension_quantities/electric_current"
|
|
8
|
+
autoload :Length, "#{__dir__}/dimension_quantities/length"
|
|
9
|
+
autoload :LuminousIntensity, "#{__dir__}/dimension_quantities/luminous_intensity"
|
|
10
|
+
autoload :Mass, "#{__dir__}/dimension_quantities/mass"
|
|
11
|
+
autoload :PlaneAngle, "#{__dir__}/dimension_quantities/plane_angle"
|
|
12
|
+
autoload :Quantity, "#{__dir__}/dimension_quantities/quantity"
|
|
13
|
+
autoload :ThermodynamicTemperature, "#{__dir__}/dimension_quantities/thermodynamic_temperature"
|
|
14
|
+
autoload :Time, "#{__dir__}/dimension_quantities/time"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/unitsml/model/prefix.rb
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "unitsml/model/prefixes/name"
|
|
4
|
-
require "unitsml/model/prefixes/symbol"
|
|
5
|
-
|
|
6
|
-
|
|
7
3
|
module Unitsml
|
|
8
4
|
module Model
|
|
9
5
|
class Prefix < Lutaml::Model::Serializable
|
|
10
6
|
attribute :name, Prefixes::Name
|
|
11
|
-
attribute :id, :
|
|
7
|
+
attribute :id, :xml_id
|
|
12
8
|
attribute :symbol, Prefixes::Symbol, collection: true
|
|
13
9
|
attribute :prefix_base, :string
|
|
14
10
|
attribute :prefix_power, :string
|
|
15
11
|
|
|
16
12
|
xml do
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
namespace ::Unitsml::Namespace
|
|
14
|
+
element 'Prefix'
|
|
19
15
|
|
|
20
16
|
map_attribute :prefixBase, to: :prefix_base
|
|
21
17
|
map_attribute :prefixPower, to: :prefix_power
|
|
22
|
-
map_attribute :id, to: :id
|
|
18
|
+
map_attribute :id, to: :id
|
|
23
19
|
map_element :PrefixName, to: :name
|
|
24
20
|
map_element :PrefixSymbol, to: :symbol
|
|
25
21
|
end
|