stepmod-utils 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1342ffe0c2b8463d7563761080df38410a31f68ced0ad56e032beb1b3f1bfd6a
4
- data.tar.gz: 5324d7df8dc68fd682e1b9b6947fb10cc26f294c852621433bec30875f31edd0
3
+ metadata.gz: 296bedce77d49f689fc8161ed77ddd424a1b9022e775af93f6447b296f4dbcd6
4
+ data.tar.gz: 8993deac9d2b6bd9bb5bd2eec97467cd689c538e68c71854ac0d4f9fb34690e9
5
5
  SHA512:
6
- metadata.gz: edca6ad9e40f5b3eeea360ee18b99732dc9f9c0e6d8875144bdbb2f085fc5bafb877629f1b5876e60415d44af92cbbbd4ccfa40805bfa62e6a9f3f4957dcf35c
7
- data.tar.gz: 52690eb5dc833108259a41c6d5493b31330665b852e9b027c5a1a7d436c5119f1dcf588d7031e3096357cfd969f434a4d67009bbaeebc0c11eb5f78eba7d62f4
6
+ metadata.gz: 56091728db55f406000ad1d1de90840d847535cb1e5407ee9425e3ded01ccf486938a441d9e52364c3cba7d7b6418492a7fd84f0575a2662a676e59b42d954e3
7
+ data.tar.gz: 8149e8f62391e52989a51de7bf95d661b8f73d9f687387cb29ad943b7d1c7b8afec89996c39cea23b446e66114fcff37a20a4e0e3bcf5bffb73fdae6a75496a6
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,7 +55,7 @@ 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
@@ -92,6 +97,24 @@ module Stepmod
92
97
  end
93
98
  end
94
99
  end
100
+
101
+ def equation_logger
102
+ @equation_logger ||= Stepmod::Utils::EquationLogger.new
103
+ end
104
+
105
+ def log_equation(node, state, equation_converted)
106
+ equation_converted_with_bold_and_italics = stem_converted(node.clone, state.merge(convert_bold_and_italics: true))
107
+
108
+ return if equation_converted_with_bold_and_italics == equation_converted
109
+
110
+ equation_logger.anchor = state[:schema_and_entity] || state[:schema_name]
111
+ equation_logger.document = state[:descriptions_file]
112
+ equation_logger.equation = node.to_s
113
+ equation_logger.equation_converted = equation_converted
114
+ equation_logger.equation_converted_with_bold_and_italics = equation_converted_with_bold_and_italics
115
+
116
+ equation_logger.log
117
+ end
95
118
  end
96
119
 
97
120
  ReverseAdoc::Converters.register :eqn, Eqn.new
@@ -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] ? '**' : '*'
@@ -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.11".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.11
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: 2023-12-23 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