Class: Plurimath::Utility::IntentEncoding
- Inherits:
-
Utility
- Object
- Utility
- Plurimath::Utility::IntentEncoding
- Defined in:
- lib/plurimath/utility/intent_encoding.rb
Constant Summary collapse
- SUP_TAGS =
%w[msup mover].freeze
- SUB_TAGS =
%w[msub munder].freeze
- INTENT_TEXT_NODES =
%w[mi mo mn].freeze
Class Method Summary collapse
-
.abs_intent(tag, intent_name, _options) ⇒ Object
Abs intent begin.
-
.binomial_fraction_intent(tag, intent_name, _) ⇒ Object
Binomial fraction intent begin.
-
.frac_intent(tag, _, options) ⇒ Object
Frac derivative intent begin.
-
.function_intent(tag, intent_name = ":function", _) ⇒ Object
Function intent begin.
-
.interval_fence_intent(tag, intent_name, options) ⇒ Object
Interval fence intent begin.
- .nary_intent(field, intent_name, _) ⇒ Object
-
.naryand_intent(field, intent_name, options) ⇒ Object
Naryand intent begin.
-
.node_value(node, field_name) ⇒ Object
Intent common code begin.
-
.power_base_intent(field) ⇒ Object
SubSup intent begin.
- .power_or_base_intent(field) ⇒ Object
Class Method Details
.abs_intent(tag, intent_name, _options) ⇒ Object
Abs intent begin
114 115 116 117 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 114 def abs_intent(tag, intent_name, ) tag["intent"] = "#{intent_name}(#{node_value(tag.nodes[1], 'a')})" tag end |
.binomial_fraction_intent(tag, intent_name, _) ⇒ Object
Binomial fraction intent begin
73 74 75 76 77 78 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 73 def binomial_fraction_intent(tag, intent_name, _) numerator = node_value(tag.nodes[1].nodes[0], "t") denominator = node_value(tag.nodes[1].nodes[1], "b") tag["intent"] = "#{intent_name}(#{numerator},#{denominator})" tag end |
.frac_intent(tag, _, options) ⇒ Object
Frac derivative intent begin
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 98 def frac_intent(tag, _, ) num = tag.nodes[0] den = tag.nodes[1] if partial_derivative?( num, den ) return partial_derivative(tag, [:partial_derivative]) end return derivative(tag, [:derivative]) if derivative?(num, den) tag end |
.function_intent(tag, intent_name = ":function", _) ⇒ Object
Function intent begin
66 67 68 69 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 66 def function_intent(tag, intent_name = ":function", _) tag.attributes["intent"] = intent_name tag end |
.interval_fence_intent(tag, intent_name, options) ⇒ Object
Interval fence intent begin
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 82 def interval_fence_intent(tag, intent_name, ) intent = [intent_name] return function_intent(tag, intent, ) if intent_name == :fenced if intent_name == :binomial_coefficient return binomial_fraction_intent(tag, intent, ) end first_value = fence_node_value(tag.nodes[1], "a") second_value = fence_node_value(tag.nodes[3], "b") tag["intent"] = "#{intent}(#{first_value},#{second_value})" tag end |
.nary_intent(field, intent_name, _) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 34 def nary_intent(field, intent_name, _) sub_sup = field.nodes[0] base, power = power_base_intent(sub_sup) base, power = power_or_base_intent(sub_sup) unless base || power naryand = node_value(field.nodes[1], "naryand") field["intent"] = "#{intent_name}(#{base},#{power},#{naryand})" field end |
.naryand_intent(field, intent_name, options) ⇒ Object
Naryand intent begin
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 22 def naryand_intent(field, intent_name, ) if field.name == "mrow" return nary_intent(field, intent_name, ) end base, power = power_base_intent(field) base, power = power_or_base_intent(field) unless base && power field["intent"] = "#{intent_name}(#{base},#{power})" field end |
.node_value(node, field_name) ⇒ Object
Intent common code begin
10 11 12 13 14 15 16 17 18 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 10 def node_value(node, field_name) return unless node return if node.name == "mo" && node.nodes[0] == "⬚" return html_entity_to_unicode(node.nodes.first) if valid_node_value?(node) return all_numeric(node) if all_numeric?(node) node[:arg] = field_name "$#{field_name}" end |
.power_base_intent(field) ⇒ Object
SubSup intent begin
45 46 47 48 49 50 51 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 45 def power_base_intent(field) return nil unless ["munderover", "msubsup"].include?(field.name) base = node_value(field.nodes[1], "l") power = node_value(field.nodes[2], "h") [base, power] end |
.power_or_base_intent(field) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 53 def power_or_base_intent(field) value_node = field.nodes[1] return nil unless SUP_TAGS.include?(field.name) || SUB_TAGS.include?(field.name) if SUP_TAGS.include?(field.name) return [nil, node_value(value_node, "h")] end [node_value(value_node, "l"), nil] end |