plurimath 0.2.5 → 0.2.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: 8815a416877ce1bf419cb3ef8a53c33d632301bab0f44c207d0a749ab9520d41
4
- data.tar.gz: cd5791b5628324b4ba4a3fd7e7bd2e11f472395ae322923ede64a724177010cc
3
+ metadata.gz: 2ea66a26d225e41e692ad7d708c2b7d673de51d5398a504b183dea1bcaceb197
4
+ data.tar.gz: f9c4710c348e0bf351138f45d55c53da5f0525a90439c317c823d4c838d8ef5f
5
5
  SHA512:
6
- metadata.gz: 2098b3a7724f79b848a2252ca1337186f0845684b903cfbd4edbafeed3b04790082dedcfdd8054ab2106044067602fd12f5cbbe66a44d3cc90eac45bb2adc03f
7
- data.tar.gz: cfd50426d4e71486d1434b684d517f3643c44a46b726427b6511e70fdb2408c46fff64e5b1a33dff139b9c4b0c292b0f8b762ff802a693ca06d93e3a9c004fc6
6
+ metadata.gz: 0af365c1786b6de865615fa5843ca3446556619ce99d1fb931455dc77e3a5a8f532c79c5eea4c3120b43805437f61a11b70aa5eec5bbf73855eac22c572ac706
7
+ data.tar.gz: d66fcf0ca35d06b2ebb64da22b6b9a99499ff2a7164cac69becc847dcc5bf3ba7c4d0329bb0f5df45b5f31b3f913629173f2532e16643d9842866286040fb2f8
@@ -3561,7 +3561,7 @@ module Plurimath
3561
3561
  cosh: :unary,
3562
3562
  ddot: :unary,
3563
3563
  mbox: :unary,
3564
- text: :unary,
3564
+ text: :text,
3565
3565
  '"': :symbols,
3566
3566
  sum: :power_base,
3567
3567
  inf: :power_base,
@@ -197,6 +197,8 @@ module Plurimath
197
197
  (slashed_value(first_value, :underover))
198
198
  when :binary
199
199
  (slashed_value(first_value, :binary) >> intermediate_exp.as(:first_value) >> intermediate_exp.as(:second_value)).as(:binary)
200
+ when :text
201
+ (slashed_value(first_value, :text) >> (str("{") >> (match("[^\}]").repeat).as(:first_value) >> str("}")))
200
202
  end
201
203
  end
202
204
 
@@ -357,6 +357,11 @@ module Plurimath
357
357
  )
358
358
  end
359
359
 
360
+ rule(text: simple(:text),
361
+ first_value: simple(:first_value)) do
362
+ Math::Function::Text.new(first_value)
363
+ end
364
+
360
365
  rule(unary: simple(:unary),
361
366
  first_value: simple(:first_value)) do
362
367
  Utility.get_class(
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "binary_function"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Semantics < BinaryFunction
9
+ def to_mathml_without_math_tag
10
+ first_value = parameter_one&.to_mathml_without_math_tag
11
+ second_value = other_tags(parameter_two)
12
+ Utility.update_nodes(
13
+ Utility.ox_element("semantics"),
14
+ second_value.insert(0, first_value),
15
+ )
16
+ end
17
+
18
+ def to_latex
19
+ parameter_one&.to_latex
20
+ end
21
+
22
+ def to_asciimath
23
+ parameter_one&.to_asciimath
24
+ end
25
+
26
+ protected
27
+
28
+ def other_tags(array)
29
+ contented = []
30
+ array&.each do |hash|
31
+ hash.each do |tag, content|
32
+ tag_element = Utility.ox_element(tag&.to_s)
33
+ contented << Utility.update_nodes(
34
+ tag_element,
35
+ content&.map(&:to_mathml_without_math_tag),
36
+ )
37
+ end
38
+ end
39
+ contented
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -42,9 +42,9 @@ module Plurimath
42
42
  "&#x3a8;": "Psi",
43
43
  "&#x3c9;": "omega",
44
44
  "&#x3a9;": "omega",
45
- "&#x22c5;": "dot",
45
+ "&#x22c5;": "cdot",
46
46
  "&#x2219;": "*",
47
- "&#xb7;": ".",
47
+ "&#x2e;": ".",
48
48
  "&#x2217;": "**",
49
49
  "&#x22c6;": "***",
50
50
  "&#xd7;": "xx",
@@ -6,6 +6,7 @@ module Plurimath
6
6
  class Mathml
7
7
  class Parser
8
8
  attr_accessor :text
9
+ SUPPORTED_ATTRIBUTES = %w[columnlines mathvariant mathcolor notation close open].freeze
9
10
 
10
11
  def initialize(text)
11
12
  @text = text
@@ -28,7 +29,7 @@ module Plurimath
28
29
  elsif !node.attributes.empty?
29
30
  {
30
31
  node.name.to_sym => {
31
- attributes: node.attributes.transform_keys(&:to_sym),
32
+ attributes: validate_attributes(node.attributes),
32
33
  value: parse_nodes(node.nodes),
33
34
  },
34
35
  }
@@ -37,6 +38,11 @@ module Plurimath
37
38
  end
38
39
  end
39
40
  end
41
+
42
+ def validate_attributes(attributes)
43
+ attributes&.select! { |key, _| SUPPORTED_ATTRIBUTES.include?(key&.to_s) }
44
+ attributes&.transform_keys(&:to_sym) if attributes&.any?
45
+ end
40
46
  end
41
47
  end
42
48
  end
@@ -6,13 +6,9 @@ module Plurimath
6
6
  rule(mi: simple(:mi)) { mi }
7
7
  rule(mo: simple(:mo)) { mo }
8
8
  rule(mo: sequence(:mo)) { Utility.mathml_unary_classes(mo) }
9
- rule(xref: simple(:xref)) { nil }
10
9
  rule(mtd: sequence(:mtd)) { Math::Function::Td.new(mtd) }
11
10
  rule(mtr: sequence(:mtr)) { Math::Function::Tr.new(mtr) }
12
- rule(accent: simple(:acc)) { nil }
13
11
  rule(none: sequence(:none)) { nil }
14
- rule(maxsize: simple(:att)) { nil }
15
- rule(minsize: simple(:att)) { nil }
16
12
  rule(notation: simple(:att)) { Math::Function::Menclose.new(att) }
17
13
  rule(mtable: simple(:table)) { table }
18
14
  rule(msqrt: sequence(:sqrt)) { Math::Function::Sqrt.new(sqrt.first) }
@@ -25,7 +21,6 @@ module Plurimath
25
21
  rule(mfenced: simple(:mfenced)) { mfenced }
26
22
  rule(mtable: sequence(:mtable)) { Math::Function::Table.new(mtable) }
27
23
  rule(mscarry: sequence(:scarry)) { nil }
28
- rule(displaystyle: simple(:att)) { nil }
29
24
  rule(menclose: simple(:enclose)) { enclose }
30
25
  rule(mlabeledtr: sequence(:mtr)) { Math::Function::Tr.new(mtr) }
31
26
  rule(mpadded: sequence(:padded)) { Utility.filter_values(padded) }
@@ -204,10 +199,10 @@ module Plurimath
204
199
  )
205
200
  end
206
201
 
207
- rule(mtext: sequence(:mtext)) do
202
+ rule(mtext: subtree(:mtext)) do
208
203
  entities = HTMLEntities.new
209
204
  symbols = Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
210
- text = entities.encode(mtext.first, :hexadecimal)
205
+ text = entities.encode(mtext.flatten.join, :hexadecimal)
211
206
  symbols.each do |code, string|
212
207
  text.gsub!(code.downcase, "unicode[:#{string}]")
213
208
  end
@@ -227,7 +222,7 @@ module Plurimath
227
222
  rule(mfenced: sequence(:fenced)) do
228
223
  Math::Function::Fenced.new(
229
224
  Math::Symbol.new("("),
230
- fenced,
225
+ fenced.compact,
231
226
  Math::Symbol.new(")"),
232
227
  )
233
228
  end
@@ -281,14 +276,21 @@ module Plurimath
281
276
 
282
277
  rule(attributes: simple(:attrs),
283
278
  value: subtree(:value)) do
284
- Utility.join_attr_value(attrs, value.flatten)
279
+ Utility.join_attr_value(attrs, value&.flatten&.compact)
280
+ end
281
+
282
+ rule(semantics: subtree(:value)) do
283
+ Math::Function::Semantics.new(
284
+ value.shift,
285
+ value,
286
+ )
285
287
  end
286
288
 
287
289
  rule(attributes: subtree(:attrs),
288
290
  value: sequence(:value)) do
289
291
  Utility.join_attr_value(
290
292
  attrs.is_a?(Hash) ? nil : attrs,
291
- value.flatten,
293
+ value&.flatten.compact,
292
294
  )
293
295
  end
294
296
  end
@@ -315,7 +315,7 @@ module Plurimath
315
315
  attrs.parameter_two = filter_values(value)
316
316
  attrs
317
317
  elsif attrs.is_a?(Math::Function::Fenced)
318
- attrs.parameter_two = value
318
+ attrs.parameter_two = value.compact
319
319
  attrs
320
320
  elsif attrs.is_a?(Math::Function::FontStyle)
321
321
  attrs.parameter_one = filter_values(value)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.2.5"
4
+ VERSION = "0.2.7"
5
5
  end
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.2.5
4
+ version: 0.2.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: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2023-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -158,6 +158,7 @@ files:
158
158
  - lib/plurimath/math/function/scarry.rb
159
159
  - lib/plurimath/math/function/sec.rb
160
160
  - lib/plurimath/math/function/sech.rb
161
+ - lib/plurimath/math/function/semantics.rb
161
162
  - lib/plurimath/math/function/sin.rb
162
163
  - lib/plurimath/math/function/sinh.rb
163
164
  - lib/plurimath/math/function/sqrt.rb