Sha256: 57c280dbd1850d336aa0aab1e9ae5df56ad26302868e0a4113c4da13c0868746
Contents?: true
Size: 1.69 KB
Versions: 13
Compression:
Stored size: 1.69 KB
Contents
require "plurimath" require "stepmod/utils" module Stepmod module Utils class EquationLogger attr_accessor :anchor, :document, :equation, :equation_converted, :equation_converted_with_bold_and_italics def initialize @logger = Logger.new(logger_file_path) end def log Stepmod::Utils.increment_eqn_counter @logger.info do <<~MESSAGE =================== Equation #{Stepmod::Utils.eqn_counter} Start =================== Document: #{document} Nearest Anchor: #{anchor} Formula (original): #{equation} ------------------ Status: #{valid_asciimath?(equation_converted)} Formula (asciimath): #{equation_converted} ------------------ Status: #{valid_asciimath?(equation_converted_with_bold_and_italics)} Formula (asciimath with bold and italics included): #{equation_converted_with_bold_and_italics} =================== Equation #{Stepmod::Utils.eqn_counter} End =================== MESSAGE end end private def logger_file_path File.join(Stepmod::Utils.eqn_log_dir, "stepmod-utils.log.txt") end def valid_asciimath?(equation) extracted_equation = extract_equation_from_stem(equation) Plurimath::Math.parse(extracted_equation, :asciimath).to_mathml "valid" rescue StandardError "invalid" end def extract_equation_from_stem(stem) stem.gsub(/\[stem\]|\+\+\+\+/, "").strip end end end end
Version data entries
13 entries across 13 versions & 1 rubygems