stepmod-utils 0.3.8 → 0.3.9

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: 8838f07a6b887ff87b6067b7a82b02e605bfc97c81ed345642b68c9d8d4e6a5b
4
+ data.tar.gz: 213824aa6f2b832d941d6575005f7c43c60f5332a1c285f973efa05d52090b86
5
5
  SHA512:
6
- metadata.gz: 206becea0d17c930418426618aa5234e420a4aba77e63a9448890245dd637ca044ad5540073e509ca8d672a701bc31b1b9576ad671f21a0da7f620f917c83b68
7
- data.tar.gz: 4f564a4b188082f6a20e41bb424c50950a2efce588fd1c48adaceb3a1068c7b4d5fa2388c758491f1d8814cceaefaee8f842337ae57d49873cb4e2bcb43933b1
6
+ metadata.gz: '088fe0671024dd6e5fb69960c379d52e25345546ba5f87b8167d37e26fd8315074ba7b7028757d610a1c18fffe560485cc65937157cad72a32445dfef836a415'
7
+ data.tar.gz: 176cde1360b6f3a229c05eb50fe606892d106101dab6e3e7c1aafb15467602d9650107151a58eb9f3ac56a2f93411ccd3131e749a3974c247f6c4cdc76f5e414
@@ -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,7 +80,7 @@ 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
@@ -76,7 +92,7 @@ part_resources.each do |(bibdata, current_part_resources)|
76
92
  fn = "04x-stepmod-entities-resources-#{bibdata.part}.adoc"
77
93
  File.open(fn, "w") do |file|
78
94
  file.puts("== #{part_to_title(bibdata)}\n\n")
79
- file.puts(current_part_resources.map(&:to_mn_adoc).join("\n"))
95
+ file.puts(replace_images(current_part_resources.map(&:to_mn_adoc).join("\n")))
80
96
  end
81
97
  log "INFO: written to: #{fn}"
82
98
  end
@@ -106,23 +122,32 @@ part_modules.each do |(bibdata, part_modules_arm, part_modules_mim)|
106
122
  n.localizations["en"]
107
123
  end
108
124
  file.puts("== #{schema_name}\n\n")
109
- file.puts(concepts.map(&:to_mn_adoc).join("\n"))
125
+ file.puts(replace_images(concepts.map(&:to_mn_adoc).join("\n")))
110
126
  end
111
127
  end
112
128
  log "INFO: written to: #{fn}"
113
129
  end
114
130
 
115
131
  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"))
132
+ file.puts(
133
+ replace_images(
134
+ general_concepts.to_a.map do |n|
135
+ n.localizations["en"]
136
+ end.map(&:to_mn_adoc).join("\n")
137
+ )
138
+ )
119
139
  end
140
+
120
141
  log "INFO: written to: 031-stepmod-general.adoc"
121
142
 
122
143
  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"))
144
+ file.puts(
145
+ replace_images(
146
+ resource_concepts.to_a.map do |n|
147
+ n.localizations["en"]
148
+ end.map(&:to_mn_adoc).join("\n")
149
+ )
150
+ )
126
151
  end
127
152
  log "INFO: written to: 041-stepmod-entities-resources.adoc"
128
153
 
@@ -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}
@@ -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,11 @@ 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
+ # If it contains a list, don't split
17
+ unless child_text =~ /\n\* /
18
+ # Only taking the first paragraph of the definition
19
+ child_text = child_text.split("\n").first
20
+ end
18
21
 
19
22
  # # Only taking the first sentence
20
23
  # 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.9".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,7 +1,7 @@
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.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -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