plurimath 0.10.5 → 0.10.7
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 14c446bc1c84d523b37daea2d902eb69ecc7a5ee9b586dc425da9780b8d84560
|
|
4
|
+
data.tar.gz: 69f9e89f24bb17ebb5d9b2d8b9f5f91faeb7469d0b838b8e20e63b7fadef08c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1f55afb6b629f26a4766bbc5839cce6814b5d47c743c91c7c232639d13ea3411c5b73531976b094b5de57157ef12f6df0ce1586f33c1a529916c9af4c275ec1
|
|
7
|
+
data.tar.gz: 8c07b342deb4e97f1993a5825ea5d53cdb1e8f96ccd65e37efdee90d1b4b960773bbcb41737df348ca1ca2c055e222f30837c173d234334fc368d0e30375fd21
|
data/Gemfile
CHANGED
|
@@ -4,9 +4,9 @@ source "https://rubygems.org"
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
gem "canon"
|
|
7
|
-
gem "lutaml-model", github: "lutaml/lutaml-model", branch: "main"
|
|
7
|
+
#gem "lutaml-model", github: "lutaml/lutaml-model", branch: "main"
|
|
8
8
|
gem "oga"
|
|
9
|
-
gem "omml", github: "plurimath/omml", branch: "main"
|
|
9
|
+
#gem "omml", github: "plurimath/omml", branch: "main"
|
|
10
10
|
gem "opal-rspec", "~> 1.1.0a"
|
|
11
11
|
gem "ox"
|
|
12
12
|
gem "rake", "~> 12.0"
|
|
@@ -8,10 +8,18 @@ module Plurimath
|
|
|
8
8
|
# Use each_mixed_content to get children in document order.
|
|
9
9
|
def ordered_children(node)
|
|
10
10
|
children = []
|
|
11
|
-
node.each_mixed_content
|
|
11
|
+
node.each_mixed_content do |child|
|
|
12
|
+
next if whitespace_text_child?(child)
|
|
13
|
+
|
|
14
|
+
children << child
|
|
15
|
+
end
|
|
12
16
|
children
|
|
13
17
|
end
|
|
14
18
|
|
|
19
|
+
def whitespace_text_child?(child)
|
|
20
|
+
child.is_a?(String) && child.strip.empty?
|
|
21
|
+
end
|
|
22
|
+
|
|
15
23
|
def text_value(value)
|
|
16
24
|
return if value.nil?
|
|
17
25
|
return value if value.is_a?(String)
|
|
@@ -27,7 +35,7 @@ module Plurimath
|
|
|
27
35
|
# before building the Plurimath AST.
|
|
28
36
|
def content_children(node)
|
|
29
37
|
ordered_children(node).reject do |child|
|
|
30
|
-
child.is_a?(Mml::
|
|
38
|
+
child.is_a?(Mml::Base::Malignmark) || child.is_a?(Mml::Base::Maligngroup)
|
|
31
39
|
end
|
|
32
40
|
end
|
|
33
41
|
|
|
@@ -62,11 +70,11 @@ module Plurimath
|
|
|
62
70
|
end
|
|
63
71
|
|
|
64
72
|
def ms_token_element?(node)
|
|
65
|
-
node.is_a?(Mml::
|
|
66
|
-
node.is_a?(Mml::
|
|
67
|
-
node.is_a?(Mml::
|
|
68
|
-
node.is_a?(Mml::
|
|
69
|
-
node.is_a?(Mml::
|
|
73
|
+
node.is_a?(Mml::Base::Mi) ||
|
|
74
|
+
node.is_a?(Mml::Base::Mn) ||
|
|
75
|
+
node.is_a?(Mml::Base::Mo) ||
|
|
76
|
+
node.is_a?(Mml::Base::Ms) ||
|
|
77
|
+
node.is_a?(Mml::Base::Mtext)
|
|
70
78
|
end
|
|
71
79
|
|
|
72
80
|
def normalize_phantom_child(child)
|
|
@@ -204,7 +212,7 @@ module Plurimath
|
|
|
204
212
|
end
|
|
205
213
|
|
|
206
214
|
def convert_multiscript_child(child)
|
|
207
|
-
return Math::Function::None.new if child.is_a?(Mml::
|
|
215
|
+
return Math::Function::None.new if child.is_a?(Mml::Base::None)
|
|
208
216
|
return Math::Function::None.new if child.respond_to?(:value) && Array(child.value).join.empty?
|
|
209
217
|
|
|
210
218
|
mml_to_plurimath(child) || Math::Function::None.new
|
|
@@ -222,12 +230,19 @@ module Plurimath
|
|
|
222
230
|
end
|
|
223
231
|
|
|
224
232
|
def split_multiscript_children(children, post_element_count)
|
|
233
|
+
pre_children = Array(children[(post_element_count + 1)..])
|
|
234
|
+
.reject { |child| prescript_marker?(child) }
|
|
235
|
+
|
|
225
236
|
[
|
|
226
237
|
convert_multiscript_children(children[1..post_element_count]),
|
|
227
|
-
convert_multiscript_children(
|
|
238
|
+
convert_multiscript_children(pre_children),
|
|
228
239
|
]
|
|
229
240
|
end
|
|
230
241
|
|
|
242
|
+
def prescript_marker?(child)
|
|
243
|
+
child.is_a?(Mml::Base::Mprescripts)
|
|
244
|
+
end
|
|
245
|
+
|
|
231
246
|
def split_script_pairs(children, compact: false)
|
|
232
247
|
pairs = children.each_slice(2).to_a
|
|
233
248
|
subscripts = pairs.map { |pair| pair[0] if pair[0] }
|
|
@@ -474,8 +474,6 @@ module Plurimath
|
|
|
474
474
|
def msgroup_to_msgroup(sgroup)
|
|
475
475
|
content = ordered_children(sgroup).filter_map do |child|
|
|
476
476
|
if child.is_a?(String)
|
|
477
|
-
next if child.strip.empty?
|
|
478
|
-
|
|
479
477
|
Plurimath::Math::Function::Text.new(child)
|
|
480
478
|
else
|
|
481
479
|
mml_to_plurimath(child)
|
data/lib/plurimath/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: plurimath
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bigdecimal
|
|
@@ -1818,7 +1818,6 @@ files:
|
|
|
1818
1818
|
- lib/plurimath/mathml/formula_transformation.rb
|
|
1819
1819
|
- lib/plurimath/mathml/parser.rb
|
|
1820
1820
|
- lib/plurimath/mathml/translator.rb
|
|
1821
|
-
- lib/plurimath/mathml/utility/formula_transformation.rb
|
|
1822
1821
|
- lib/plurimath/number_formatter.rb
|
|
1823
1822
|
- lib/plurimath/omml.rb
|
|
1824
1823
|
- lib/plurimath/omml/formula_transformation.rb
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Plurimath
|
|
4
|
-
class Mathml
|
|
5
|
-
module Utility
|
|
6
|
-
module FormulaTransformation
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
def filter_values(value, array_to_instance: false,
|
|
10
|
-
replacing_order: true)
|
|
11
|
-
return value unless value.is_a?(Array)
|
|
12
|
-
return array_to_instance ? nil : value if value.empty?
|
|
13
|
-
|
|
14
|
-
if is_a?(Math::Formula) && value.length == 1 && value.first.is_mstyle?
|
|
15
|
-
@displaystyle = value.first.displaystyle
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
if value.length == 1 && value.all?(Math::Formula)
|
|
19
|
-
if array_to_instance
|
|
20
|
-
filter_values(value.first.value, array_to_instance: true)
|
|
21
|
-
else
|
|
22
|
-
value.first
|
|
23
|
-
end
|
|
24
|
-
elsif value.is_a?(Array) && value.any?(Math::Formula::Mrow)
|
|
25
|
-
value.each_with_index do |element, index|
|
|
26
|
-
next unless element.is_a?(Math::Formula::Mrow)
|
|
27
|
-
|
|
28
|
-
value[index] = filter_values(
|
|
29
|
-
Array(element),
|
|
30
|
-
array_to_instance: true,
|
|
31
|
-
replacing_order: replacing_order,
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
value
|
|
35
|
-
elsif value_is_ternary_or_nary?(value)
|
|
36
|
-
value.first.parameter_three = value.delete_at(1)
|
|
37
|
-
filter_values(
|
|
38
|
-
Array(value),
|
|
39
|
-
array_to_instance: array_to_instance,
|
|
40
|
-
replacing_order: replacing_order,
|
|
41
|
-
)
|
|
42
|
-
elsif ternary_naryable?(value)
|
|
43
|
-
[
|
|
44
|
-
Math::Function::Nary.new(
|
|
45
|
-
value.first.parameter_one,
|
|
46
|
-
value.first.parameter_two,
|
|
47
|
-
value.first.parameter_three,
|
|
48
|
-
value.last,
|
|
49
|
-
),
|
|
50
|
-
]
|
|
51
|
-
elsif overset_naryable?(value)
|
|
52
|
-
[
|
|
53
|
-
Math::Function::Nary.new(
|
|
54
|
-
value.first.parameter_two,
|
|
55
|
-
nil,
|
|
56
|
-
value.first.parameter_one,
|
|
57
|
-
value.last,
|
|
58
|
-
{ type: "undOvr" },
|
|
59
|
-
),
|
|
60
|
-
]
|
|
61
|
-
elsif power_naryable?(value)
|
|
62
|
-
[
|
|
63
|
-
Math::Function::Nary.new(
|
|
64
|
-
value.first.parameter_one,
|
|
65
|
-
nil,
|
|
66
|
-
value.first.parameter_two,
|
|
67
|
-
value.last,
|
|
68
|
-
{ type: "subSup" },
|
|
69
|
-
),
|
|
70
|
-
]
|
|
71
|
-
elsif array_to_instance && replacing_order
|
|
72
|
-
value.length > 1 ? Math::Formula.new(value) : value.first
|
|
73
|
-
else
|
|
74
|
-
value
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def validate_symbols(value)
|
|
79
|
-
case value
|
|
80
|
-
when Array
|
|
81
|
-
array_validations(value)
|
|
82
|
-
when Math::Symbols::Symbol
|
|
83
|
-
return value if value.value.nil?
|
|
84
|
-
|
|
85
|
-
instance = mathml_symbol_to_class(value.value)
|
|
86
|
-
if value&.options&.any? && instance.is_a?(Math::Symbols::Symbol)
|
|
87
|
-
instance.options = value.options
|
|
88
|
-
end
|
|
89
|
-
instance
|
|
90
|
-
when String
|
|
91
|
-
mathml_symbol_to_class(value)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def array_validations(value)
|
|
96
|
-
value.each_with_index do |val, index|
|
|
97
|
-
next unless val.is_a?(Math::Symbols::Symbol)
|
|
98
|
-
|
|
99
|
-
unless val.value.nil?
|
|
100
|
-
value[index] =
|
|
101
|
-
mathml_symbol_to_class(val.value)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
value
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def mathml_symbol_to_class(symbol)
|
|
108
|
-
Plurimath::Utility.mathml_unary_classes(
|
|
109
|
-
Array(symbol),
|
|
110
|
-
lang: :mathml,
|
|
111
|
-
)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def value_is_ternary_or_nary?(value)
|
|
115
|
-
return false if value.any?(String)
|
|
116
|
-
|
|
117
|
-
value.length >= 2 &&
|
|
118
|
-
value.first.is_ternary_function? &&
|
|
119
|
-
value.first.parameter_three.nil? &&
|
|
120
|
-
(!value.first.parameter_one.nil? || !value.first.parameter_two.nil?)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def ternary_naryable?(value)
|
|
124
|
-
value.length == 2 &&
|
|
125
|
-
value.first.is_a?(Math::Function::PowerBase) &&
|
|
126
|
-
value.first.parameter_one.is_nary_symbol?
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def overset_naryable?(value)
|
|
130
|
-
value.length == 2 &&
|
|
131
|
-
value.first.is_a?(Math::Function::Overset) &&
|
|
132
|
-
value.first.parameter_two.is_nary_symbol?
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def power_naryable?(value)
|
|
136
|
-
value.length == 2 &&
|
|
137
|
-
value.first.is_a?(Math::Function::Power) &&
|
|
138
|
-
value.first.parameter_one.is_nary_symbol?
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|