Class: Plurimath::Utility::IntentEncoding
- Inherits:
-
Plurimath::Utility
- Object
- Plurimath::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
Constants inherited from Plurimath::Utility
ALIGNMENT_LETTERS, FONT_STYLES, MASK_CLASSES, MGLYPH_ATTRS, MPADDED_ATTRS, MUNDER_CLASSES, PARENTHESIS, TABLE_SUPPORTED_ATTRS, TEXT_CLASSES, UNARY_CLASSES, UNICODEMATH_MENCLOSE_FUNCTIONS, UNICODE_REGEX
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
Methods inherited from Plurimath::Utility
accent_value, all_symbols_classes, asciimath_symbol_object, attr_is_accent, attr_is_function, base_is_prime?, base_is_sub_or_sup?, base_recursion, binary_function_classes, capitalize, enclosure_attrs, fenceable_classes, filter_math_zone_values, filter_table_data, filter_values, find_pos_chr, frac_values, fractions, get_class, get_paren_class, get_symbol_class, get_table_class, hexcode_in_input, html_entity_to_unicode, identity_matrix, join_attr_value, latex_table_curly_paren, left_right_objects, math_display_text_objects, mathml_unary_classes, mrow_left_right, multiscript, nary_fonts, nil_to_none_object, notations_to_mask, organize_options, organize_table, organize_tds, ox_element, paren_able?, paren_files, parens_hash, populate_function_classes, pr_element, primes_constants, recursion_fraction, recursive_sub, recursive_sup, rpr_element, sequence_slashed_values, slashed_values, string_to_html_entity, sub_sup_method?, sup_recursion, symbol_object, symbol_prime?, symbol_to_text, symbol_value, symbols_class, symbols_files, symbols_hash, table_options, table_separator, table_td, td_value, td_values, ternary_function_classes, text_classes, transform_accents, unary_function_classes, unfenced_value, unicode_accents, unicode_fractions, update_nodes, updated_primes, valid_class, valid_paren?, validate_left_right, validate_math_zone
Class Method Details
.abs_intent(tag, intent_name, _options) ⇒ Object
Abs intent begin
100 101 102 103 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 100 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
67 68 69 70 71 72 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 67 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
89 90 91 92 93 94 95 96 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 89 def frac_intent(tag, _, ) num = tag.nodes[0] den = tag.nodes[1] return partial_derivative(tag, [:partial_derivative]) if partial_derivative?(num, den) return derivative(tag, [:derivative]) if derivative?(num, den) tag end |
.function_intent(tag, intent_name = ":function", _) ⇒ Object
Function intent begin
60 61 62 63 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 60 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
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 76 def interval_fence_intent(tag, intent_name, ) intent = [intent_name] return function_intent(tag, intent, ) if intent_name == :fenced return binomial_fraction_intent(tag, intent, ) if intent_name == :binomial_coefficient 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
31 32 33 34 35 36 37 38 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 31 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 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 22 def naryand_intent(field, intent_name, ) return nary_intent(field, intent_name, ) if field.name == "mrow" 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
42 43 44 45 46 47 48 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 42 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
50 51 52 53 54 55 56 |
# File 'lib/plurimath/utility/intent_encoding.rb', line 50 def power_or_base_intent(field) value_node = field.nodes[1] return nil unless SUP_TAGS.include?(field.name) || SUB_TAGS.include?(field.name) return [nil, node_value(value_node, "h")] if SUP_TAGS.include?(field.name) [node_value(value_node, "l"), nil] end |