stepmod-utils 0.4.10 → 0.4.12

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: 1342ffe0c2b8463d7563761080df38410a31f68ced0ad56e032beb1b3f1bfd6a
4
- data.tar.gz: 5324d7df8dc68fd682e1b9b6947fb10cc26f294c852621433bec30875f31edd0
3
+ metadata.gz: 277e199cae63ff4916555e4d208672a1d561809e7abb921eff70e022e781e5c1
4
+ data.tar.gz: c4762ca7dc28641cbca3c1eebcc393940963d702acd83ef183ad42bf44fb6944
5
5
  SHA512:
6
- metadata.gz: edca6ad9e40f5b3eeea360ee18b99732dc9f9c0e6d8875144bdbb2f085fc5bafb877629f1b5876e60415d44af92cbbbd4ccfa40805bfa62e6a9f3f4957dcf35c
7
- data.tar.gz: 52690eb5dc833108259a41c6d5493b31330665b852e9b027c5a1a7d436c5119f1dcf588d7031e3096357cfd969f434a4d67009bbaeebc0c11eb5f78eba7d62f4
6
+ metadata.gz: 8999ccb49cae3922ed4c8ef8cdeece7f80ede6501dfe75219d6e6ba0749013850ccfcd6a0d55ecb479441e3210e5a1064a17cbfff9d0348c273b5e999670ae05
7
+ data.tar.gz: '039013eaddf84f1afc779b4311c254ace92513a0652418b1648d8da0dbbdb7cc86cad0efb4ba11670a5d5df4b8b56889e788cc73f4a98098e8b27857e74b9e6b'
data/.gitignore CHANGED
@@ -13,3 +13,5 @@
13
13
  Gemfile.lock
14
14
 
15
15
  .rubocop-https*
16
+
17
+ stepmod-utils.log.txt
@@ -40,6 +40,14 @@ OptionParser.new do |opts|
40
40
  options[:srl_output_docs_dir] = path
41
41
  end
42
42
 
43
+ opts.on(
44
+ "--eqn-log LOG_FILE_DIR",
45
+ String,
46
+ "Path to the directory for log file for equations",
47
+ ) do |path|
48
+ options[:eqn_log_dir] = path
49
+ end
50
+
43
51
  opts.on_tail("-h", "--help", "Show this message") do
44
52
  puts opts
45
53
  exit
@@ -67,6 +75,9 @@ unless File.exist?(srl_output_docs_dir) && File.directory?(srl_output_docs_dir)
67
75
  raise StandardError.new("--documents directory for SRL documents (generated by stepmod2mn) does not exist yet, please run stepmod2mn")
68
76
  end
69
77
 
78
+ eqn_log_dir = File.expand_path(options[:eqn_log_dir] || ".")
79
+ Stepmod::Utils.eqn_log_dir = eqn_log_dir
80
+
70
81
  def all_express_files(stepmod_dir)
71
82
  index_file = File.read(File.join(stepmod_dir, "repository_index.xml"))
72
83
  index = Nokogiri::XML(index_file).root
@@ -18,7 +18,9 @@ module Stepmod
18
18
  treat(equation, state.merge(equation: true, already_italic: true))
19
19
  end
20
20
 
21
- content = if content.strip.empty? || state[:already_italic] || state[:equation]
21
+ content = if state[:equation] && state[:convert_bold_and_italics]
22
+ "ii(#{content.strip})"
23
+ elsif content.strip.empty? || state[:already_italic] || state[:equation]
22
24
  content
23
25
  else
24
26
  "#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "stepmod/utils/html_to_asciimath"
4
+ require "stepmod/utils/equation_logger"
4
5
 
5
6
  module Stepmod
6
7
  module Utils
@@ -14,7 +15,11 @@ module Stepmod
14
15
  return definition_converted(cloned_node, state)
15
16
  end
16
17
 
17
- stem_converted(cloned_node, state)
18
+ equation_converted = stem_converted(cloned_node, state)
19
+
20
+ log_equation(node, state, equation_converted)
21
+
22
+ equation_converted
18
23
  end
19
24
 
20
25
  private
@@ -50,11 +55,11 @@ module Stepmod
50
55
  end
51
56
 
52
57
  def stem_converted(cloned_node, state)
53
- remove_tags_not_in_context(cloned_node)
58
+ remove_tags_not_in_context(cloned_node) unless state[:convert_bold_and_italics]
54
59
  internal_content = treat_children(cloned_node, state.merge(equation: true))
55
60
  content = Stepmod::Utils::HtmlToAsciimath.new.call(internal_content)
56
61
  res = <<~TEMPLATE
57
-
62
+ #{source_type_comment(cloned_node)}
58
63
  [stem]
59
64
  ++++
60
65
  #{remove_trash_symbols(content.strip)}
@@ -66,6 +71,10 @@ module Stepmod
66
71
  res
67
72
  end
68
73
 
74
+ def source_type_comment(node)
75
+ "\n// source type is bigeqn\n" if node.name == "bigeqn"
76
+ end
77
+
69
78
  def remove_trash_symbols(content)
70
79
  content
71
80
  .gsub(/ /, "")
@@ -92,9 +101,28 @@ module Stepmod
92
101
  end
93
102
  end
94
103
  end
104
+
105
+ def equation_logger
106
+ @equation_logger ||= Stepmod::Utils::EquationLogger.new
107
+ end
108
+
109
+ def log_equation(node, state, equation_converted)
110
+ equation_converted_with_bold_and_italics = stem_converted(node.clone, state.merge(convert_bold_and_italics: true))
111
+
112
+ return if equation_converted_with_bold_and_italics == equation_converted
113
+
114
+ equation_logger.anchor = state[:schema_and_entity] || state[:schema_name]
115
+ equation_logger.document = state[:descriptions_file]
116
+ equation_logger.equation = node.to_s
117
+ equation_logger.equation_converted = equation_converted
118
+ equation_logger.equation_converted_with_bold_and_italics = equation_converted_with_bold_and_italics
119
+
120
+ equation_logger.log
121
+ end
95
122
  end
96
123
 
97
124
  ReverseAdoc::Converters.register :eqn, Eqn.new
125
+ ReverseAdoc::Converters.register :bigeqn, Eqn.new
98
126
  end
99
127
  end
100
128
  end
@@ -20,7 +20,9 @@ module Stepmod
20
20
  treat(equation, state.merge(equation: true, already_strong: true))
21
21
  end
22
22
 
23
- content = if content.strip.empty? || state[:already_strong] || state[:equation]
23
+ content = if state[:equation] && state[:convert_bold_and_italics]
24
+ "bb(#{content.strip})"
25
+ elsif content.strip.empty? || state[:already_strong] || state[:equation]
24
26
  content
25
27
  else
26
28
  strong_tag = state[:non_flanking_whitesapce] ? '**' : '*'
@@ -4,7 +4,6 @@ module Stepmod
4
4
  module Utils
5
5
  module Converters
6
6
  class Table < Stepmod::Utils::Converters::Base
7
-
8
7
  def self.pattern(state, id)
9
8
  if state[:schema_and_entity].nil?
10
9
  raise StandardError.new("[table]: no state given, #{id}")
@@ -23,8 +22,14 @@ module Stepmod
23
22
  title = node["caption"].to_s
24
23
  title = ".#{title}\n" unless title.empty?
25
24
  attrs = style(node)
26
- "\n\n#{anchor}#{attrs}#{title}|===\n#{treat_children(node,
27
- state)}\n|===\n"
25
+
26
+ <<~TABLE
27
+
28
+
29
+ #{anchor}#{attrs}#{title}|===
30
+ #{treat_children(node, state.merge(inside_table: true))}
31
+ |===
32
+ TABLE
28
33
  end
29
34
 
30
35
  def frame(node)
@@ -8,7 +8,7 @@ module Stepmod
8
8
  if node.text.strip.empty?
9
9
  treat_empty(node, state)
10
10
  else
11
- treat_text(node)
11
+ treat_text(node, state)
12
12
  end
13
13
  end
14
14
 
@@ -27,21 +27,25 @@ module Stepmod
27
27
  end
28
28
  end
29
29
 
30
- def treat_text(node)
30
+ def treat_text(node, state)
31
31
  text = node.text
32
32
  text = preserve_nbsp(text)
33
33
  text = remove_inner_newlines(text)
34
34
  text = remove_border_newlines(text)
35
35
 
36
36
  text = preserve_keychars_within_backticks(text)
37
- preserve_tags(text)
37
+
38
+ text = preserve_pipes_within_tables(text, state)
39
+ preserve_tags(text, state)
38
40
  end
39
41
 
40
42
  def preserve_nbsp(text)
41
43
  text.gsub(/\u00A0/, "&nbsp;")
42
44
  end
43
45
 
44
- def preserve_tags(text)
46
+ def preserve_tags(text, state)
47
+ return text if state[:inside_table]
48
+
45
49
  text.gsub(/[<>]/, ">" => '\>', "<" => '\<')
46
50
  end
47
51
 
@@ -58,6 +62,12 @@ module Stepmod
58
62
  match.gsub('\_', "_").gsub('\*', "*")
59
63
  end
60
64
  end
65
+
66
+ def preserve_pipes_within_tables(text, state)
67
+ return text unless state[:inside_table]
68
+
69
+ text.gsub("|", "\\|")
70
+ end
61
71
  end
62
72
 
63
73
  ReverseAdoc::Converters.register :text, Text.new
@@ -0,0 +1,67 @@
1
+ require "plurimath"
2
+ require "stepmod/utils"
3
+
4
+ module Stepmod
5
+ module Utils
6
+ class EquationLogger
7
+ attr_accessor :anchor,
8
+ :document,
9
+ :equation,
10
+ :equation_converted,
11
+ :equation_converted_with_bold_and_italics
12
+
13
+ def initialize
14
+ @logger = Logger.new(logger_file_path)
15
+ end
16
+
17
+ def log
18
+ Stepmod::Utils.increment_eqn_counter
19
+ @logger.info do
20
+ <<~MESSAGE
21
+
22
+ =================== Equation #{Stepmod::Utils.eqn_counter} Start ===================
23
+ Document: #{document}
24
+ Nearest Anchor: #{anchor}
25
+
26
+ Formula (original):
27
+ #{equation}
28
+
29
+ ------------------
30
+
31
+ Status: #{valid_asciimath?(equation_converted)}
32
+ Formula (asciimath):
33
+ #{equation_converted}
34
+
35
+ ------------------
36
+
37
+ Status: #{valid_asciimath?(equation_converted_with_bold_and_italics)}
38
+ Formula (asciimath with bold and italics included):
39
+ #{equation_converted_with_bold_and_italics}
40
+
41
+ =================== Equation #{Stepmod::Utils.eqn_counter} End ===================
42
+
43
+
44
+ MESSAGE
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def logger_file_path
51
+ File.join(Stepmod::Utils.eqn_log_dir, "stepmod-utils.log.txt")
52
+ end
53
+
54
+ def valid_asciimath?(equation)
55
+ extracted_equation = extract_equation_from_stem(equation)
56
+ Plurimath::Math.parse(extracted_equation, :asciimath).to_mathml
57
+ "valid"
58
+ rescue StandardError
59
+ "invalid"
60
+ end
61
+
62
+ def extract_equation_from_stem(stem)
63
+ stem.gsub(/\[stem\]|\+\+\+\+/, "").strip
64
+ end
65
+ end
66
+ end
67
+ end
@@ -166,7 +166,7 @@ module Stepmod
166
166
 
167
167
  converted_description = <<~DESCRIPTION
168
168
 
169
- #{Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper, no_notes_examples: true)}
169
+ #{Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper, no_notes_examples: true, descriptions_file: descriptions_file)}
170
170
  DESCRIPTION
171
171
 
172
172
  if description["linkend"].nil?
@@ -176,25 +176,25 @@ module Stepmod
176
176
  converted_figures = figures.map do |figure|
177
177
  Stepmod::Utils::Converters::ExpressFigure
178
178
  .new
179
- .convert(figure, schema_and_entity: description["linkend"])
179
+ .convert(figure, schema_and_entity: description["linkend"], descriptions_file: descriptions_file)
180
180
  end.join
181
181
 
182
182
  converted_tables = tables.map do |table|
183
183
  Stepmod::Utils::Converters::ExpressTable
184
184
  .new
185
- .convert(table, schema_and_entity: description["linkend"])
185
+ .convert(table, schema_and_entity: description["linkend"], descriptions_file: descriptions_file)
186
186
  end.join
187
187
 
188
188
  converted_notes = notes.map do |note|
189
189
  Stepmod::Utils::Converters::ExpressNote
190
190
  .new
191
- .convert(note, schema_and_entity: description["linkend"])
191
+ .convert(note, schema_and_entity: description["linkend"], descriptions_file: descriptions_file)
192
192
  end.join
193
193
 
194
194
  converted_examples = examples.map do |example|
195
195
  Stepmod::Utils::Converters::ExpressExample
196
196
  .new
197
- .convert(example, schema_and_entity: description["linkend"])
197
+ .convert(example, schema_and_entity: description["linkend"], descriptions_file: descriptions_file)
198
198
  end.join
199
199
 
200
200
  [
@@ -358,6 +358,7 @@ module Stepmod
358
358
  {
359
359
  no_notes_examples: false,
360
360
  schema_and_entity: linked,
361
+ descriptions_file: descriptions_file,
361
362
  },
362
363
  )
363
364
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.4.10".freeze
3
+ VERSION = "0.4.12".freeze
4
4
  end
5
5
  end
data/lib/stepmod/utils.rb CHANGED
@@ -3,6 +3,28 @@ require "stepmod/utils/version"
3
3
  module Stepmod
4
4
  module Utils
5
5
  class Error < StandardError; end
6
- # Your code goes here...
6
+
7
+ @@eqn_log_dir = "."
8
+ @@eqn_counter = 0
9
+
10
+ def self.root
11
+ File.expand_path("../..", __dir__)
12
+ end
13
+
14
+ def self.eqn_log_dir=(eqn_log_dir)
15
+ @@eqn_log_dir = eqn_log_dir
16
+ end
17
+
18
+ def self.eqn_log_dir
19
+ @@eqn_log_dir
20
+ end
21
+
22
+ def self.eqn_counter
23
+ @@eqn_counter
24
+ end
25
+
26
+ def self.increment_eqn_counter
27
+ @@eqn_counter += 1
28
+ end
7
29
  end
8
30
  end
@@ -35,12 +35,14 @@ Gem::Specification.new do |spec|
35
35
  spec.add_runtime_dependency "expressir"
36
36
  spec.add_runtime_dependency "glossarist", "~> 2.0"
37
37
  spec.add_runtime_dependency "indefinite_article"
38
+ spec.add_runtime_dependency "plurimath"
38
39
  spec.add_runtime_dependency "ptools"
39
40
  spec.add_runtime_dependency "pubid-iso"
40
41
  spec.add_runtime_dependency "octokit"
41
42
  spec.add_runtime_dependency "down"
42
43
  spec.add_runtime_dependency "reverse_adoc", ">= 0.3"
43
44
  spec.add_runtime_dependency "thor", ">= 0.20"
45
+ spec.add_runtime_dependency "unitsml"
44
46
  spec.add_development_dependency "rubocop"
45
47
  spec.add_development_dependency "rubocop-performance"
46
48
  spec.add_development_dependency "rubocop-rails"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.12
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-12-22 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: plurimath
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: ptools
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0.20'
167
+ - !ruby/object:Gem::Dependency
168
+ name: unitsml
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: rubocop
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -293,6 +321,7 @@ files:
293
321
  - lib/stepmod/utils/converters/term.rb
294
322
  - lib/stepmod/utils/converters/text.rb
295
323
  - lib/stepmod/utils/converters/uof.rb
324
+ - lib/stepmod/utils/equation_logger.rb
296
325
  - lib/stepmod/utils/express_bibdata.rb
297
326
  - lib/stepmod/utils/html_to_asciimath.rb
298
327
  - lib/stepmod/utils/smrl_description_converter.rb