stepmod-utils 0.3.8 → 0.3.12

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: 6201c720f31faffdd6646d74a3c150733f3219bd756d9ba9743e5a27c1db4495
4
- data.tar.gz: b1bafce759e91f5923d030fe0b5b0f74f2b719a832d53ac300db6b38e3e221d0
3
+ metadata.gz: cede4c978acf6fd33ac7bae2dd5a0020e8f0e9f5ac06e1562f089dd2aa702ee5
4
+ data.tar.gz: d4cdb2bf5abe663d7089c6d74a939fab72b698ef64a3029695cfd467a423f74d
5
5
  SHA512:
6
- metadata.gz: 206becea0d17c930418426618aa5234e420a4aba77e63a9448890245dd637ca044ad5540073e509ca8d672a701bc31b1b9576ad671f21a0da7f620f917c83b68
7
- data.tar.gz: 4f564a4b188082f6a20e41bb424c50950a2efce588fd1c48adaceb3a1068c7b4d5fa2388c758491f1d8814cceaefaee8f842337ae57d49873cb4e2bcb43933b1
6
+ metadata.gz: 9f9db582dd4c85836ed96c8916024d9cf75c8019a512305634df73af0be3dbe9faf53ea2e8b516afe7417f0c68a50f5b27303d5034cf627fcdbacf4e05a3f1c5
7
+ data.tar.gz: 52cd06f6cd0a044d4e904a6daa85d2802a9731b1b2aa13643087b71c60f3c106f67623dca248a00c970f48875faf415776b3f48de74bf51539b6a3c94b9f57f2
@@ -53,6 +53,22 @@ def part_to_title(bibdata)
53
53
  end
54
54
  end
55
55
 
56
+ IMAGE_REPLACEMENTS = {
57
+ 'image::eq01.gif[]' => 'stem:[H(A,B) = max {h(A, B), h(B,A)}]',
58
+ 'image::eq02.gif[]' => 'stem:[max_{a in A} { min_{b in B} d(a,b) }]',
59
+ 'image::vector_z_c.gif[]' => 'stem:[bar z_{c}]',
60
+ 'image::one_direction_repeat_factor_expression.gif[]' => 'stem:[I + k cdot R;  k = -1, 1]',
61
+ 'image::two_direction_repeat_factor_expression.gif[]' => 'stem:[I + k_1 cdot R_1 + k_2 cdot R_2;  k_1, k_2 = -1, 0, 1, k^2_1 + k^2_2 != 0]'
62
+ }
63
+
64
+ def replace_images(content)
65
+ IMAGE_REPLACEMENTS.each_pair do |k, v|
66
+ content.gsub!(k, v)
67
+ end
68
+
69
+ content
70
+ end
71
+
56
72
  def log(message)
57
73
  puts "[stepmod-utils] #{message}"
58
74
  end
@@ -64,23 +80,45 @@ part_concepts.each do |(bibdata, current_part_concepts)|
64
80
  fn = "03x-stepmod-#{bibdata.part}.adoc"
65
81
  File.open(fn, "w") do |file|
66
82
  file.puts("== #{part_to_title(bibdata)}\n\n")
67
- file.puts(current_part_concepts.map(&:to_mn_adoc).join("\n"))
83
+ file.puts(replace_images(current_part_concepts.map(&:to_mn_adoc).join("\n")))
68
84
  end
69
85
  log "INFO: written to: #{fn}"
70
86
  end
71
87
 
88
+ File.open("03x-stepmod.adoc", "w") do |file|
89
+ part_concepts.sort_by do |(bibdata, current_part_concepts)|
90
+ bibdata.part.to_i
91
+ end.each do |(bibdata, current_part_concepts)|
92
+ fn = "03x-stepmod-#{bibdata.part}.adoc"
93
+ file.puts("\ninclude::#{fn}[]\n")
94
+ end
95
+ end
96
+
97
+ log "INFO: written summary file to: 03x-stepmod.adoc"
98
+
72
99
  part_resources.each do |(bibdata, current_part_resources)|
73
100
  current_part_resources = current_part_resources.to_a.map do |n|
74
101
  n.localizations["en"]
75
102
  end
76
103
  fn = "04x-stepmod-entities-resources-#{bibdata.part}.adoc"
77
104
  File.open(fn, "w") do |file|
78
- file.puts("== #{part_to_title(bibdata)}\n\n")
79
- file.puts(current_part_resources.map(&:to_mn_adoc).join("\n"))
105
+ # file.puts("== #{part_to_title(bibdata)}\n\n")
106
+ file.puts(replace_images(current_part_resources.map(&:to_mn_adoc).join("\n")))
80
107
  end
81
108
  log "INFO: written to: #{fn}"
82
109
  end
83
110
 
111
+ File.open("04x-stepmod-entities-resources.adoc", "w") do |file|
112
+ part_resources.sort_by do |(bibdata, current_part_resources)|
113
+ bibdata.part.to_i
114
+ end.each do |(bibdata, current_part_resources)|
115
+ fn = "04x-stepmod-entities-resources-#{bibdata.part}.adoc"
116
+ file.puts("\ninclude::#{fn}[]\n")
117
+ end
118
+ end
119
+
120
+ log "INFO: written summary file to: 04x-stepmod-entities-resources.adoc"
121
+
84
122
  part_modules.each do |(bibdata, part_modules_arm, part_modules_mim)|
85
123
  fn = "05x-stepmod-entities-modules-#{bibdata.part}.adoc"
86
124
  File.open(fn, "w") do |file|
@@ -106,23 +144,43 @@ part_modules.each do |(bibdata, part_modules_arm, part_modules_mim)|
106
144
  n.localizations["en"]
107
145
  end
108
146
  file.puts("== #{schema_name}\n\n")
109
- file.puts(concepts.map(&:to_mn_adoc).join("\n"))
147
+ file.puts(replace_images(concepts.map(&:to_mn_adoc).join("\n")))
110
148
  end
111
149
  end
112
150
  log "INFO: written to: #{fn}"
113
151
  end
114
152
 
153
+ File.open("05x-stepmod-entities-modules.adoc", "w") do |file|
154
+ part_modules.sort_by do |(bibdata, part_modules_arm, part_modules_mim)|
155
+ bibdata.part.to_i
156
+ end.each do |(bibdata, part_modules_arm, part_modules_mim)|
157
+ fn = "05x-stepmod-entities-modules-#{bibdata.part}.adoc"
158
+ file.puts("\ninclude::#{fn}[]\n")
159
+ end
160
+ end
161
+
162
+ log "INFO: written summary file to: 05x-stepmod-entities-modules.adoc"
163
+
115
164
  File.open("031-stepmod-general.adoc", "w") do |file|
116
- file.puts(general_concepts.to_a.map do |n|
117
- n.localizations["en"]
118
- end.map(&:to_mn_adoc).join("\n"))
165
+ file.puts(
166
+ replace_images(
167
+ general_concepts.to_a.map do |n|
168
+ n.localizations["en"]
169
+ end.map(&:to_mn_adoc).join("\n")
170
+ )
171
+ )
119
172
  end
173
+
120
174
  log "INFO: written to: 031-stepmod-general.adoc"
121
175
 
122
176
  File.open("041-stepmod-entities-resources.adoc", "w") do |file|
123
- file.puts(resource_concepts.to_a.map do |n|
124
- n.localizations["en"]
125
- end.map(&:to_mn_adoc).join("\n"))
177
+ file.puts(
178
+ replace_images(
179
+ resource_concepts.to_a.map do |n|
180
+ n.localizations["en"]
181
+ end.map(&:to_mn_adoc).join("\n")
182
+ )
183
+ )
126
184
  end
127
185
  log "INFO: written to: 041-stepmod-entities-resources.adoc"
128
186
 
@@ -31,7 +31,10 @@ module Stepmod
31
31
  Reference <<#{reference_anchor}>> for the complete definition.
32
32
  TEXT
33
33
  end
34
+
34
35
  # https://github.com/metanorma/stepmod-utils/issues/86
36
+
37
+ # TODO: This portion DOES NOT HANDLE the <synonym> element. WTF??
35
38
  if definition_xml.name == "definition"
36
39
  designation = definition_designation(definition_xml)
37
40
  definition = definition_xml_definition(definition_xml,
@@ -40,6 +43,7 @@ module Stepmod
40
43
  designation, definition
41
44
  ).strip
42
45
  end
46
+
43
47
  new(
44
48
  designations: [designation],
45
49
  definition: definition,
@@ -53,20 +57,36 @@ module Stepmod
53
57
  end
54
58
 
55
59
  def definition_designation(definition_xml)
56
- alts = definition_xml.xpath(".//def/p").map(&:text)
60
+ # We take the <p> that is an alternative term (length<=20).
61
+ # Add in the <synonym> elements.
62
+ alts = definition_xml.xpath(".//synonym").map(&:text) +
63
+ definition_xml.xpath(".//def/p").map(&:text).reject do |text|
64
+ text.length > 20
65
+ end
66
+
67
+ term = Stepmod::Utils::Converters::Term
68
+ .new
69
+ .convert(
70
+ definition_xml.xpath(".//term").first
71
+ )
72
+
57
73
  {
58
- accepted: definition_xml.xpath(".//term").first&.text,
74
+ # [4..-1] because we want to skip the initial `=== {title}`
75
+ accepted: term[4..-1],
59
76
  alt: alts,
60
77
  }
61
78
  end
62
79
 
63
80
  def definition_xml_definition(definition_xml, reference_anchor)
81
+ # We reject the <p> that was considered an alternative term (length<=20)
64
82
  text_nodes = definition_xml
65
83
  .xpath(".//def")
66
84
  .first
67
85
  .children
68
- .reject { |n| n.name == "p" }
86
+ .reject { |n| n.name == "p" && n.text.length <= 20 }
87
+
69
88
  wrapper = "<def>#{text_nodes.map(&:to_s).join}</def>"
89
+
70
90
  Stepmod::Utils::Converters::Def
71
91
  .new
72
92
  .convert(
@@ -83,15 +103,18 @@ module Stepmod
83
103
  if designation[:alt].length.positive?
84
104
  alt_notation = "alt:[#{designation[:alt].map(&:strip).join(',')}]"
85
105
  end
106
+
86
107
  result = <<~TEXT
87
- === #{designation[:accepted]}
108
+ === #{designation[:accepted].strip}
88
109
  TEXT
110
+
89
111
  if alt_notation
90
112
  result += <<~TEXT
91
113
 
92
114
  #{alt_notation}
93
115
  TEXT
94
116
  end
117
+
95
118
  <<~TEXT
96
119
  #{result}
97
120
  #{definition}
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "uri"
4
-
5
3
  module Stepmod
6
4
  module Utils
7
5
  module Converters
@@ -31,9 +29,7 @@ module Stepmod
31
29
  name = title if name.empty?
32
30
  href = "link:#{href}" unless href.to_s&.match?(URI::DEFAULT_PARSER.make_regexp)
33
31
  link = "#{href}[#{name}]"
34
- # link.prepend(' ')
35
32
  " #{link}"
36
-
37
33
  end
38
34
  end
39
35
  end
@@ -5,7 +5,7 @@ module Stepmod
5
5
  module Converters
6
6
  class ExpressRef < ReverseAdoc::Converters::Base
7
7
  def convert(node, _state = {})
8
- " *#{node['linkend'].to_s.split('.').last}*"
8
+ " *#{node['linkend'].to_s.split('.').last}* "
9
9
  end
10
10
  end
11
11
  ReverseAdoc::Converters.register :express_ref, ExpressRef.new
@@ -19,7 +19,7 @@ module Stepmod
19
19
  " {{#{normalized_ref(ref)}}} "
20
20
  elsif
21
21
  ref = node["linkend"].split(":").first
22
- " *#{ref}*"
22
+ " *#{ref}* "
23
23
  end
24
24
  end
25
25
 
@@ -9,10 +9,12 @@ module Stepmod
9
9
  anchor = id ? "[[#{id}]]\n" : ""
10
10
  ol_count = state.fetch(:ol_count, 0) + 1
11
11
  attrs = ol_attrs(node)
12
- "\n\n#{anchor}#{attrs}#{treat_children(node,
13
- state.merge(
14
- ol_count: ol_count, tdsinglepara: true,
15
- ))}\n"
12
+ children_s = treat_children(node, state.merge(
13
+ ol_count: ol_count,
14
+ tdsinglepara: true,
15
+ ))
16
+
17
+ "\n\n#{anchor}#{attrs}#{children_s}\n"
16
18
  # Why do we add this?
17
19
  # res = "\n" + res if node.parent && node.parent.name == 'note'
18
20
  end
@@ -13,8 +13,28 @@ module Stepmod
13
13
  child_text = treat_children(node, state).strip
14
14
  return nil if child_text.empty?
15
15
 
16
- # Only taking the first paragraph of the definition
17
- child_text = child_text.split("\n").first
16
+ # Unless the first paragraph ends with "between" and is followed by a
17
+ # list, don't split
18
+ first_child = child_text.split("\n").first
19
+
20
+ unless (
21
+ first_child =~ /between:?\s*\Z/ ||
22
+ first_child =~ /include:?\s*\Z/ ||
23
+ first_child =~ /of:?\s*\Z/ ||
24
+ first_child =~ /[:;]\s*\Z/
25
+ ) &&
26
+ child_text =~ /\n\n\*/
27
+
28
+ # Only taking the first paragraph of the definition
29
+ child_text = first_child
30
+ end
31
+
32
+ # TEMP: Remove any whitespace (" ", not newlines) after an immediate
33
+ # newline due to:
34
+ # https://github.com/metanorma/iso-10303-2/issues/71
35
+ if child_text =~ /\n\ +/
36
+ child_text = child_text.gsub(/\n\ +/, "\n")
37
+ end
18
38
 
19
39
  # # Only taking the first sentence
20
40
  # if child_text.contains?(".")
@@ -11,8 +11,10 @@ module Stepmod
11
11
  if content.strip.empty? || state[:already_strong]
12
12
  content
13
13
  else
14
- handle_express_escape_seq(node,
15
- "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}")
14
+ handle_express_escape_seq(
15
+ node,
16
+ "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}"
17
+ )
16
18
  end
17
19
  end
18
20
 
@@ -6,10 +6,19 @@ module Stepmod
6
6
  module Utils
7
7
  module Converters
8
8
  class Term < ReverseAdoc::Converters::Base
9
+
10
+ # We strip all the children in the case for "stem:[d]-manifold"
11
+ # vs "stem:[d] -manifold"
12
+ def treat_children(node, state)
13
+ res = node.children.map { |child| treat(child, state) }
14
+ res.map(&:strip).reject(&:empty?).join("")
15
+ end
16
+
9
17
  def convert(node, state = {})
10
18
  first_child = node.children.find do |child|
11
19
  child.name == "text" && !child.text.to_s.strip.empty?
12
20
  end
21
+
13
22
  unless first_child &&
14
23
  node.text.split(";").length == 2 &&
15
24
  defined?(Stepmod::Utils::Converters::Synonym)
@@ -25,10 +34,10 @@ module Stepmod
25
34
  private
26
35
 
27
36
  def treat_acronym(term_def)
28
- return term_def if term_def !~ /.+\(.+?\)$/
37
+ return term_def.strip if term_def !~ /.+\(.+?\)$/
29
38
 
30
39
  _, term_text, term_acronym = term_def.match(/(.+?)(\(.+\))$/).to_a
31
- "#{term_text}\nalt:[#{term_acronym.gsub(/\(|\)/, '')}]"
40
+ "#{term_text.strip}\nalt:[#{term_acronym.gsub(/\(|\)/, '')}]"
32
41
  end
33
42
  end
34
43
 
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.8".freeze
3
+ VERSION = "0.3.12".freeze
4
4
  end
5
5
  end
@@ -34,10 +34,9 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "concurrent-ruby"
35
35
  spec.add_runtime_dependency "glossarist", "~> 0.1.0"
36
36
  spec.add_runtime_dependency "ptools"
37
- spec.add_runtime_dependency "reverse_adoc", ">= 0.2.9"
37
+ spec.add_runtime_dependency "reverse_adoc", ">= 0.3.5"
38
38
  spec.add_runtime_dependency "thor", ">= 0.20.3"
39
- spec.add_development_dependency "byebug", "~> 11.1"
40
- spec.add_development_dependency "rubocop", "1.12"
39
+ spec.add_development_dependency "rubocop"
41
40
  spec.add_development_dependency "rubocop-performance"
42
41
  spec.add_development_dependency "rubocop-rails"
43
42
  end
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.3.8
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-26 00:00:00.000000000 Z
11
+ date: 2021-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.9
61
+ version: 0.3.5
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.9
68
+ version: 0.3.5
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,34 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.20.3
83
- - !ruby/object:Gem::Dependency
84
- name: byebug
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '11.1'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '11.1'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rubocop
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - '='
87
+ - - ">="
102
88
  - !ruby/object:Gem::Version
103
- version: '1.12'
89
+ version: '0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - '='
94
+ - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: '1.12'
96
+ version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: rubocop-performance
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -236,7 +222,7 @@ homepage: https://github.com/metanorma/stepmod-utils
236
222
  licenses:
237
223
  - BSD-2-Clause
238
224
  metadata: {}
239
- post_install_message:
225
+ post_install_message:
240
226
  rdoc_options: []
241
227
  require_paths:
242
228
  - lib
@@ -251,8 +237,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
237
  - !ruby/object:Gem::Version
252
238
  version: '0'
253
239
  requirements: []
254
- rubygems_version: 3.0.3.1
255
- signing_key:
240
+ rubygems_version: 3.2.22
241
+ signing_key:
256
242
  specification_version: 4
257
243
  summary: Stepmod-utils is a toolkit that works on STEPmod data.
258
244
  test_files: []