stepmod-utils 0.3.29 → 0.3.31

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: 20464f99d7ac2bb1ef98259e6e66d356fde298ca671e67587a57e072fdaad77c
4
- data.tar.gz: 21ef21a08bd1dd78dca12c5f960ff8b715dbfbb3183a2d6ae3bb2da39300f53a
3
+ metadata.gz: e7459842ad5de4eed3337c26d6267a5d85e6255f8a730a443d27dfd93ec76bbf
4
+ data.tar.gz: e43d507c19b7027d0c22f6bb0e7fba544db9443a7a4df36162e3b8af3f2a28c7
5
5
  SHA512:
6
- metadata.gz: e941853286cd6888c10323d8dce31b8347764e9588805eeae62248f8b1bcbf5c0f4e9324a24886704580dc874aa8ff92abc4d921a6bac224db3ff1983aa14707
7
- data.tar.gz: 12ef57a910098c8f9cd9f98ad0af39072b6fb7496a6cbb7b238b401ee8f2f8dabaa4296ae2caaa3e5f24e54ce76674a76c8c8aa83c627b51e17d49706963c1b2
6
+ metadata.gz: a547cb2ee89f17a9d869dbc19aa6c74ee15a830c5bb88836166c4bf7d61532268508982e171ff318f2cb163b4041187d3e8638141a26e9d340433ebcb1b3ae58
7
+ data.tar.gz: 61e26c2579d309560b5336868e1c75f3b18cca9cd036272f990e8d872118e779ff1b4969ac55c84c3f8fa9c39ae76d93cac86f8ac290d068f9acde029cd4f1ec
data/README.adoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = STEPmod utilities
2
2
 
3
- image:https://img.shields.io/gem/v/metanorma.svg["Gem Version", link="https://rubygems.org/gems/metanorma"]
3
+ image:https://img.shields.io/gem/v/stepmod-utils.svg["Gem Version", link="https://rubygems.org/gems/stepmod-utils"]
4
4
  image:https://github.com/metanorma/stepmod-utils/workflows/ubuntu/badge.svg["Ubuntu Build Status", link="https://github.com/metanorma/stepmod-utils/actions?query=workflow%3Aubuntu"]
5
5
  image:https://github.com/metanorma/stepmod-utils/workflows/macos/badge.svg["OSX Build Status", link="https://github.com/metanorma/stepmod-utils/actions?query=workflow%3Amacos"]
6
6
  image:https://github.com/metanorma/stepmod-utils/workflows/windows/badge.svg["Windows Build Status", link="https://github.com/metanorma/stepmod-utils/actions?query=workflow%3Awindows"]
@@ -111,6 +111,173 @@ expg_image:contract_schemaexpg1.xml[]
111
111
  expg_image:contract_schemaexpg2.xml[]
112
112
  ----
113
113
 
114
+ == Convertion of all schema history information into independent per-schema YAML files
115
+
116
+ Command:
117
+
118
+ [source,sh]
119
+ ----
120
+ $ stepmod-extract-changes -p {stepmod-data-directory}
121
+ ----
122
+
123
+ === Examples
124
+
125
+ Given the following XML
126
+
127
+ [source,xml]
128
+ ----
129
+ <change version="4">
130
+ <arm.changes>
131
+ <arm.modifications>
132
+ <modified.object type="TYPE" name="ap242_requirement_assignment_item" />
133
+ <!-- ... -->
134
+ </arm.modifications>
135
+ </arm.changes>
136
+ <mim.changes>
137
+ <mim.additions>
138
+ <modified.object type="CONSTANT" name="ap242_shape_representation_reference_types" />
139
+ <!-- ... -->
140
+ </mim.additions>
141
+ <mim.modifications>
142
+ <modified.object type="CONSTANT" name="deprecated_interfaced_data_types" />
143
+ <!-- ... -->
144
+ </mim.modifications>
145
+ <mim.deletions>
146
+ <modified.object type="RULE" name="subtype_mandatory_shape_representation" />
147
+ </mim.deletions>
148
+ </mim.changes>
149
+
150
+ <arm_longform.changes>
151
+ <arm.additions>
152
+ <modified.object type="TYPE" name="advanced_face_model" />
153
+ <!-- ... -->
154
+ </arm.additions>
155
+ <arm.modifications>
156
+ <modified.object type="TYPE" name="assembly_constraint_select">
157
+ <description>
158
+ <ul>
159
+ <li>Remove SELECT value 'ENTITY Binary_assembly_constraint'</li>
160
+ <!-- ... -->
161
+ </ul>
162
+ </description>
163
+ </modified.object>
164
+ <!-- ... -->
165
+ </arm.modifications>
166
+ <arm.deletions>
167
+ <modified.object type="TYPE" name="axis_placement_mapping_source" />
168
+ </arm.deletions>
169
+ </arm_longform.changes>
170
+
171
+ <mim_longform.changes>
172
+ <mim.additions>
173
+ <modified.object type="CONSTANT" name="ap242_shape_representation_reference_types" />
174
+ </mim.additions>
175
+
176
+ <mim.modifications>
177
+ <modified.object type="CONSTANT" name="deprecated_constructed_data_types">
178
+ <description>
179
+ CONSTANT 'deprecated_constructed_data_types': Expression Changed
180
+ </description>
181
+ </modified.object>
182
+ <!-- ... -->
183
+ </mim.modifications>
184
+
185
+ <mim.deletions>
186
+ <modified.object type="TYPE" name="connected_edge_with_length_set_items" />
187
+ <!-- ... -->
188
+ </mim.deletions>
189
+ </mim_longform.changes>
190
+
191
+ </change>
192
+ ----
193
+
194
+ Will Generate 4 files:
195
+
196
+ - arm.changes.yml
197
+ - mim.changes.yml
198
+ - arm_lf.changes.yml
199
+ - mim_lf.changes.yml
200
+
201
+ `arm.changes.yml`:
202
+
203
+ [source,yaml]
204
+ ----
205
+ ---
206
+ schema: Ap242_managed_model_based_3d_engineering_arm
207
+ change_edition:
208
+ - version: 4
209
+ description:
210
+ modifications:
211
+ - type: TYPE
212
+ name: ap242_requirement_assignment_item
213
+ ----
214
+
215
+
216
+ `mim.changes.yml`:
217
+
218
+ [source,yaml]
219
+ ----
220
+ ---
221
+ schema: Ap242_managed_model_based_3d_engineering_mim
222
+ change_edition:
223
+ - version: 4
224
+ description:
225
+ additions:
226
+ - type: CONSTANT
227
+ name: ap242_shape_representation_reference_types
228
+ modifications:
229
+ - type: CONSTANT
230
+ name: deprecated_interfaced_data_types
231
+ deletions:
232
+ - type: RULE
233
+ name: subtype_mandatory_shape_representation
234
+ ----
235
+
236
+ `arm_lf.changes.yml`:
237
+
238
+ [source,yaml]
239
+ ----
240
+ ---
241
+ schema: Ap242_managed_model_based_3d_engineering_arm_LF
242
+ change_edition:
243
+ - version: 4
244
+ description:
245
+ additions:
246
+ - type: TYPE
247
+ name: advanced_face_model
248
+ modifications:
249
+ - type: TYPE
250
+ name: assembly_constraint_select
251
+ descriptions:
252
+ - Remove SELECT value 'ENTITY Binary_assembly_constraint'
253
+ deletions:
254
+ - type: TYPE
255
+ name: axis_placement_mapping_source
256
+ ----
257
+
258
+ `mim_lf.changes.yml`:
259
+
260
+ [source,yaml]
261
+ ----
262
+ ---
263
+ schema: Ap242_managed_model_based_3d_engineering_mim_LF
264
+ change_edition:
265
+ - version: 4
266
+ description:
267
+ additions:
268
+ - type: CONSTANT
269
+ name: ap242_shape_representation_reference_types
270
+ modifications:
271
+ - type: CONSTANT
272
+ name: deprecated_constructed_data_types
273
+ description: |
274
+ CONSTANT 'deprecated_constructed_data_types': Expression Changed
275
+ deletions:
276
+ - type: TYPE
277
+ name: connected_edge_with_length_set_items
278
+ ----
279
+
280
+
114
281
  == Git repository
115
282
 
116
283
  If the STEPmod repository is a Git repository, term extract will work.
@@ -2,8 +2,10 @@
2
2
 
3
3
  require "concurrent"
4
4
  require "stepmod/utils/stepmod_file_annotator"
5
+ require "fileutils"
5
6
 
6
7
  stepmod_dir = ARGV.first || Dir.pwd
8
+ stepmod_dir = Pathname.new(stepmod_dir.gsub("\\", "/"))
7
9
 
8
10
  def all_express_files(stepmod_dir)
9
11
  index_file = File.read(File.join(stepmod_dir, "repository_index.xml"))
@@ -32,34 +34,38 @@ end
32
34
  MAX_THREADS = 1 #[2, Concurrent.processor_count].max * 2
33
35
  MAX_QUEUE_SIZE = MAX_THREADS * 4
34
36
  # https://github.com/ruby-concurrency/concurrent-ruby/blob/master/docs-source/thread_pools.md
35
- pool = Concurrent::ThreadPoolExecutor.new(
36
- min_threads: MAX_THREADS,
37
- max_threads: MAX_THREADS,
38
- max_queue: MAX_QUEUE_SIZE,
39
- fallback_policy: :caller_runs,
40
- )
37
+ # pool = Concurrent::ThreadPoolExecutor.new(
38
+ # min_threads: MAX_THREADS,
39
+ # max_threads: MAX_THREADS,
40
+ # max_queue: MAX_QUEUE_SIZE,
41
+ # fallback_policy: :caller_runs,
42
+ # )
41
43
 
42
44
  files = all_express_files(stepmod_dir)
43
45
 
44
- files.each_slice(MAX_QUEUE_SIZE) do |batch|
45
- puts("Queueing next batch")
46
- batch.each do |file|
47
- pool.post do
48
- puts "#{Thread.current.object_id}: Queued processing #{file}"
49
- annotated = Stepmod::Utils::StepmodFileAnnotator.new(
50
- express_file: file,
51
- stepmod_dir: stepmod_dir
52
- ).call
53
-
54
- annotated_file_name = "#{File.basename(file, '.exp')}_annotated.exp"
55
- annotated_file_path = File.join(File.dirname(file), annotated_file_name)
56
-
57
- File.open(annotated_file_path, "w") do |file|
58
- file.puts(annotated)
59
- end
60
-
61
- puts "#{Thread.current.object_id}: Done processing #{File.basename(file)} => #{annotated_file_path}."
62
- end
46
+ files.each do |file|
47
+ puts "#{Thread.current.object_id}: Processing #{file}"
48
+
49
+ result = Stepmod::Utils::StepmodFileAnnotator.new(
50
+ express_file: file,
51
+ stepmod_dir: stepmod_dir,
52
+ ).call
53
+
54
+ annotated_file_name = "#{File.basename(file, '.exp')}_annotated.exp"
55
+ annotated_file_path = File.join(File.dirname(file), annotated_file_name)
56
+
57
+ File.open(annotated_file_path, "w") do |annotated_file|
58
+ annotated_file.puts(result[:annotated_text])
59
+ end
60
+
61
+ result[:images_references].each do |source, destination|
62
+ source_path = File.join(stepmod_dir, "data", source)
63
+ destination_path = File.join(File.dirname(file), destination)
64
+
65
+ next if File.exist?(destination_path) || !File.exist?(source_path)
66
+
67
+ FileUtils.cp(source_path, destination_path)
63
68
  end
64
- pool.shutdown
69
+
70
+ puts "#{Thread.current.object_id}: Done processing #{File.basename(file)} => #{annotated_file_path}."
65
71
  end
@@ -86,7 +86,7 @@ else
86
86
  )
87
87
  end
88
88
 
89
- default_output_dir = File.join(stepmod_dir, "output_yaml")
89
+ default_output_dir = File.join(File.expand_path("..", stepmod_dir), "output_yaml")
90
90
  output_dir = options[:output_dir] || default_output_dir
91
91
  unless File.directory?(output_dir)
92
92
  FileUtils.mkdir_p(output_dir)
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # encoding: UTF-8
4
+
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
12
+ require "rubygems/specification"
13
+
14
+ module Gem
15
+ class Specification
16
+ def this; self; end
17
+ end
18
+ end
19
+
20
+ require "bundler/setup"
21
+ require "optparse"
22
+
23
+ def log(message)
24
+ puts "[stepmod-utils] #{message}"
25
+ end
26
+
27
+ options = {}
28
+ OptionParser.new do |opts|
29
+ opts.banner = "Usage: #{$0} [options]"
30
+
31
+ opts.on(
32
+ "--stepmod-data-dir STEPMOD_DATA_DIR",
33
+ String,
34
+ "Path to STEPmod data directory",
35
+ ) do |path|
36
+ options[:stepmod_dir] = path
37
+ end
38
+
39
+ opts.on(
40
+ "--srl-docs-dir SRL_DOCS_DIR",
41
+ String,
42
+ "Path to output srl docs",
43
+ ) do |path|
44
+ options[:srl_output_docs_dir] = path
45
+ end
46
+
47
+ opts.on(
48
+ "--srl-schemas-dir SRL_SCHEMAS_DIR",
49
+ String,
50
+ "Path to output srl schemas",
51
+ ) do |path|
52
+ options[:srl_output_schemas_dir] = path
53
+ end
54
+
55
+ opts.on(
56
+ "-s",
57
+ "--stepmod2mn-executeable STEPMOD2MN_EXECUTEABLE",
58
+ String,
59
+ "Path to STEPMOD2MN_EXECUTEABLE",
60
+ ) do |path|
61
+ options[:stepmod2mn_path] = path
62
+ end
63
+
64
+ opts.on_tail("-h", "--help", "Show this message") do
65
+ puts opts
66
+ exit
67
+ end
68
+ end.parse!
69
+
70
+ stepmod2mn_path = options[:stepmod2mn_path]
71
+ if stepmod2mn_path.nil?
72
+ raise StandardError.new(
73
+ "stepmod2mn executeable is required, set with the `-s` option.",
74
+ )
75
+ end
76
+
77
+ stepmod_dir = options[:stepmod_dir] || "stepmod"
78
+ if stepmod_dir.nil?
79
+ raise StandardError.new(
80
+ "stepmod data directory required, set with the `--stepmod_dir` option.",
81
+ )
82
+ end
83
+
84
+ migrate_docs_command = %(stepmod-srl-migrate-docs -s "#{stepmod2mn_path}" --stepmod-data-dir "#{stepmod_dir}")
85
+ migrate_docs_command += %( --srl-docs-dir #{options[:srl_output_docs_dir]}) if options[:srl_output_docs_dir]
86
+
87
+ migrate_schemas_command = %(stepmod-srl-migrate-schemas -s "#{stepmod2mn_path}" --stepmod-data-dir "#{stepmod_dir}")
88
+ migrate_schemas_command += %( --srl-schemas-dir #{options[:srl_output_schemas_dir]}) if options[:srl_output_schemas_dir]
89
+
90
+ log("--- START Migrate Docs ---")
91
+ system migrate_docs_command
92
+ log("--- END Migrate Docs ---")
93
+
94
+ log("--- START Migrate Schemas ---")
95
+ system migrate_schemas_command
96
+ log("--- END Migrate Schemas ---")
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # encoding: UTF-8
4
+
5
+ require "fileutils"
6
+ # resolve bin path, ignoring symlinks
7
+ require "pathname"
8
+ bin_file = Pathname.new(__FILE__).realpath
9
+
10
+ # add self to libpath
11
+ $:.unshift File.expand_path("../../lib", bin_file)
12
+
13
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
14
+ require "rubygems/specification"
15
+
16
+ module Gem
17
+ class Specification
18
+ def this; self; end
19
+ end
20
+ end
21
+
22
+ require "bundler/setup"
23
+ require "optparse"
24
+
25
+ def log(message)
26
+ puts "[stepmod-utils] #{message}"
27
+ end
28
+
29
+ options = {}
30
+ OptionParser.new do |opts|
31
+ opts.banner = "Usage: #{$0} [options]"
32
+
33
+ opts.on(
34
+ "--stepmod-data-dir STEPMOD_DATA_DIR",
35
+ String,
36
+ "Path to STEPmod data directory",
37
+ ) do |path|
38
+ options[:stepmod_dir] = path
39
+ end
40
+
41
+ opts.on(
42
+ "--srl-docs-dir SRL_DOCS_DIR",
43
+ String,
44
+ "Path to output srl docs",
45
+ ) do |path|
46
+ options[:srl_output_docs_dir] = path
47
+ end
48
+
49
+ opts.on(
50
+ "-s",
51
+ "--stepmod2mn-executeable STEPMOD2MN_EXECUTEABLE",
52
+ String,
53
+ "Path to STEPMOD2MN_EXECUTEABLE",
54
+ ) do |path|
55
+ options[:stepmod2mn_path] = path
56
+ end
57
+
58
+ opts.on_tail("-h", "--help", "Show this message") do
59
+ puts opts
60
+ exit
61
+ end
62
+ end.parse!
63
+
64
+ stepmod2mn_path = options[:stepmod2mn_path]
65
+ if stepmod2mn_path.nil?
66
+ raise StandardError.new(
67
+ "stepmod2mn executeable is required, set with the `-s` option.",
68
+ )
69
+ else
70
+ log "stepmod2mn executeable path: `#{stepmod2mn_path}`"
71
+ end
72
+
73
+ stepmod_dir = options[:stepmod_dir] || "stepmod/data"
74
+ log "STEPmod data path: `#{stepmod_dir}`"
75
+
76
+ srl_output_docs_dir = options[:srl_output_docs_dir] || "documents"
77
+ unless File.directory?(srl_output_docs_dir)
78
+ FileUtils.mkdir_p(srl_output_docs_dir)
79
+ end
80
+ log "SRL output docs directory path: `#{srl_output_docs_dir}`"
81
+
82
+ system "java -Xss5m -jar #{stepmod2mn_path} #{stepmod_dir} --output #{srl_output_docs_dir}"
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # encoding: UTF-8
4
+
5
+ require "fileutils"
6
+ # resolve bin path, ignoring symlinks
7
+ require "pathname"
8
+ bin_file = Pathname.new(__FILE__).realpath
9
+
10
+ # add self to libpath
11
+ $:.unshift File.expand_path("../../lib", bin_file)
12
+
13
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
14
+ require "rubygems/specification"
15
+
16
+ module Gem
17
+ class Specification
18
+ def this; self; end
19
+ end
20
+ end
21
+
22
+ require "bundler/setup"
23
+ require "optparse"
24
+
25
+ def log(message, indent = 0)
26
+ indent_spaces = " " * (indent * 2)
27
+ puts "[stepmod-utils] #{indent_spaces}#{message}"
28
+ end
29
+
30
+ def copy_files_to_schemas(path, output_dir)
31
+ schema_name = path.dirname.basename
32
+ file_name = path.basename
33
+
34
+ new_dir = File.join(output_dir, schema_name)
35
+ new_file_path = File.join(new_dir, file_name.to_s.gsub("_annotated.exp", ".exp"))
36
+
37
+ unless Dir.exist?(new_dir)
38
+ FileUtils.mkdir_p(new_dir)
39
+ end
40
+
41
+ FileUtils.copy_file(path, new_file_path)
42
+ log("Copied #{path.basename} to #{new_file_path}", 1)
43
+ end
44
+
45
+ options = {}
46
+ OptionParser.new do |opts|
47
+ opts.banner = "Usage: #{$0} [options]"
48
+
49
+ opts.on(
50
+ "--stepmod-data-dir STEPMOD_DATA_DIR",
51
+ String,
52
+ "Path to STEPmod data directory",
53
+ ) do |path|
54
+ options[:stepmod_dir] = path
55
+ end
56
+
57
+ opts.on(
58
+ "--srl-schemas-dir SRL_SCHEMAS_DIR",
59
+ String,
60
+ "Path to output srl schemas",
61
+ ) do |path|
62
+ options[:srl_output_schemas_dir] = path
63
+ end
64
+
65
+ opts.on(
66
+ "-s",
67
+ "--stepmod2mn-executeable STEPMOD2MN_EXECUTEABLE",
68
+ String,
69
+ "Path to STEPMOD2MN_EXECUTEABLE",
70
+ ) do |path|
71
+ options[:stepmod2mn_path] = path
72
+ end
73
+
74
+ opts.on_tail("-h", "--help", "Show this message") do
75
+ puts opts
76
+ exit
77
+ end
78
+ end.parse!
79
+
80
+ stepmod2mn_path = options[:stepmod2mn_path]
81
+ if stepmod2mn_path.nil?
82
+ raise StandardError.new(
83
+ "stepmod2mn executeable is required, set with the `-s` option.",
84
+ )
85
+ else
86
+ log "stepmod2mn executeable path: `#{stepmod2mn_path}`"
87
+ end
88
+
89
+ stepmod_dir = options[:stepmod_dir] || "stepmod/data"
90
+ log "STEPmod data path: `#{stepmod_dir}`"
91
+
92
+ srl_output_schemas_dir = options[:srl_output_schemas_dir] || "schemas"
93
+ unless File.directory?(srl_output_schemas_dir)
94
+ FileUtils.mkdir_p(srl_output_schemas_dir)
95
+ end
96
+ log "SRL output schemas directory path: `#{srl_output_schemas_dir}`"
97
+
98
+ system "java -Xss5m -jar #{stepmod2mn_path} #{stepmod_dir} --output #{srl_output_schemas_dir} --svg"
99
+
100
+ system "stepmod-annotate-all #{stepmod_dir}"
101
+
102
+ Dir.glob("#{stepmod_dir}/data/**/*_annotated.exp").each do |filepath|
103
+ path = Pathname.new(filepath)
104
+ copy_files_to_schemas(path, srl_output_schemas_dir)
105
+ end
106
+
107
+ system "stepmod-extract-changes -p #{stepmod_dir}"
108
+
109
+ Dir.glob("#{stepmod_dir}/data/**/*.changes.yaml").each do |filepath|
110
+ path = Pathname.new(filepath)
111
+ copy_files_to_schemas(path, srl_output_schemas_dir)
112
+ end
113
+
114
+ log("Done")
@@ -18,15 +18,16 @@ module Stepmod
18
18
  return "" unless File.file?(file)
19
19
 
20
20
  image_document = Nokogiri::XML(File.read(file))
21
- svg_path = File.basename(image_document.xpath("//img").first["src"],
21
+ svg_filename = File.basename(image_document.xpath("//img").first["src"],
22
22
  ".*")
23
23
  <<~SVGMAP
24
24
 
25
25
  *)
26
26
  (*"#{state.fetch(:schema_name)}.__expressg"
27
+ [[#{svg_filename}]]
27
28
  [.svgmap]
28
29
  ====
29
- image::#{svg_path}.svg[]
30
+ image::#{svg_filename}.svg[]
30
31
 
31
32
  #{image_document.xpath('//img.area').map.with_index(1) { |n, i| schema_reference(n['href'], i) }.join("\n")}
32
33
  ====
@@ -21,6 +21,7 @@ module Stepmod
21
21
  @resource_docs_cache = resource_docs_schemas(stepmod_dir)
22
22
  @stepmod_dir = stepmod_dir || Dir.pwd
23
23
  @added_bibdata = {}
24
+ @images_references = {}
24
25
 
25
26
  @schema_name = Expressir::Express::Parser.from_file(express_file)
26
27
  .schemas
@@ -29,11 +30,11 @@ module Stepmod
29
30
  end
30
31
 
31
32
  def resource_docs_schemas(stepmod_dir)
32
- filepath = File.join(stepmod_dir, "data/resource_docs/*/resource.xml")
33
+ filepath = File.join(stepmod_dir, "data", "resource_docs", "*", "resource.xml")
33
34
 
34
35
  schemas = {}
35
36
  Dir.glob(filepath).each do |resource_docs_file|
36
- match = resource_docs_file.match("data/resource_docs/([^/]+)/resource.xml")
37
+ match = resource_docs_file.match("data[/\]resource_docs[/\]([^/\]+)[/\]resource.xml")
37
38
  resource_docs_dir = match.captures[0]
38
39
 
39
40
  resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
@@ -55,6 +56,7 @@ module Stepmod
55
56
  output_express = File.read(express_file)
56
57
  converted_description = ""
57
58
  base_linked = ""
59
+ processed_images_cache = {}
58
60
 
59
61
  if File.exist?(descriptions_file)
60
62
  descriptions = Nokogiri::XML(File.read(descriptions_file)).root
@@ -82,6 +84,10 @@ module Stepmod
82
84
  descriptions_file, description
83
85
  )
84
86
  end
87
+
88
+ schema_base_dir = resource_docs_cache[base_linked]
89
+ add_images_references(converted_description, schema_base_dir, processed_images_cache)
90
+
85
91
  # Add converted description from exact linked path
86
92
  if resource_docs_dir && added_resource_descriptions[description["linkend"]].nil?
87
93
  output_express << convert_from_resource_file(resource_docs_dir,
@@ -112,7 +118,10 @@ module Stepmod
112
118
  converted_description
113
119
  end
114
120
 
115
- sanitize(output_express)
121
+ {
122
+ annotated_text: sanitize(output_express),
123
+ images_references: @images_references,
124
+ }
116
125
  rescue StandardError => e
117
126
  puts "[ERROR]!!! #{e.message}"
118
127
  puts e.backtrace
@@ -124,6 +133,25 @@ module Stepmod
124
133
  file_content.gsub("(*)", "(`*`)")
125
134
  end
126
135
 
136
+ def add_images_references(description, schema_base_dir, processed_images_cache)
137
+ referenced_images = description.scan(/image::(.*?)\[\]/).flatten
138
+
139
+ referenced_images.each do |referenced_image|
140
+ next unless schema_base_dir
141
+
142
+ image_file_path = File.join("resource_docs", schema_base_dir, referenced_image)
143
+ new_image_file_path = referenced_image
144
+
145
+ if processed_images_cache[new_image_file_path]
146
+ processed_images_cache[new_image_file_path] = true
147
+ next
148
+ end
149
+
150
+ processed_images_cache[new_image_file_path] = true
151
+ @images_references[image_file_path] = new_image_file_path
152
+ end
153
+ end
154
+
127
155
  def convert_from_description_text(descriptions_file, description)
128
156
  Dir.chdir(File.dirname(descriptions_file)) do
129
157
  wrapper = "<ext_descriptions>#{description}</ext_descriptions>"
@@ -243,13 +243,15 @@ module Stepmod
243
243
  bibdata: bibdata,
244
244
  # See: metanorma/iso-10303-2#90
245
245
  domain_prefix: "application module",
246
+ schema_type: type,
246
247
  )
247
248
  when "module_mim"
248
249
  mim_concepts = parse_annotated_module(
249
250
  schema: schema,
250
251
  bibdata: bibdata,
251
252
  # See: metanorma/iso-10303-2#90
252
- domain_prefix: "application object",
253
+ domain_prefix: "application module",
254
+ schema_type: type,
253
255
  )
254
256
  when "resource"
255
257
  parse_annotated_resource(schema: schema, bibdata: bibdata)
@@ -268,7 +270,7 @@ module Stepmod
268
270
  }[match.captures[0]] || "resource"
269
271
  end
270
272
 
271
- def parse_annotated_module(schema:, bibdata:, domain_prefix:)
273
+ def parse_annotated_module(schema:, bibdata:, domain_prefix:, schema_type:)
272
274
  log "INFO: parse_annotated_module: " \
273
275
  "Processing modules schema #{schema.file}"
274
276
 
@@ -285,6 +287,7 @@ module Stepmod
285
287
  "name" => schema.id,
286
288
  "type" => "module",
287
289
  "path" => extract_file_path(entity.parent.file),
290
+ "schema_type" => schema_type
288
291
  },
289
292
  document: {
290
293
  "type" => "module",
@@ -330,6 +333,7 @@ module Stepmod
330
333
  "name" => schema.id,
331
334
  "type" => "resource",
332
335
  "path" => extract_file_path(entity.parent.file),
336
+ "schema_type" => "resource"
333
337
  },
334
338
  document: {
335
339
  "type" => "resource",
@@ -363,7 +367,8 @@ module Stepmod
363
367
  # rubocop:disable Metrics/MethodLength
364
368
  def generate_concept_from_entity(entity:, schema:, domain:, bibdata:, document:)
365
369
  old_definition = trim_definition(entity.remarks.first)
366
- definition = generate_entity_definition(entity, domain)
370
+ schema_type = schema["schema_type"]
371
+ definition = generate_entity_definition(entity, domain, schema_type)
367
372
 
368
373
  notes = [old_definition].reject { |note| redundant_note?(note) }
369
374
 
@@ -515,15 +520,20 @@ module Stepmod
515
520
  # end
516
521
 
517
522
  # rubocop:disable Layout/LineLength
518
- def generate_entity_definition(entity, domain)
523
+ def generate_entity_definition(entity, domain, schema_type)
519
524
  return "" if entity.nil?
520
525
 
521
526
  # See: metanorma/iso-10303-2#90
522
- entity_type = if domain_type = domain.match(/\A(application object):/)
523
- "{{#{domain_type[1]}}}"
524
- else
525
- "{{entity data type}}"
526
- end
527
+ entity_type = case schema_type
528
+ when "module_arm"
529
+ "{{application object}}"
530
+ when "module_mim"
531
+ "{{entity data type}}"
532
+ when "resource", "business_object_model"
533
+ "{{entity data type}}"
534
+ else
535
+ raise Error.new("[stepmod-utils] encountered unsupported schema_type")
536
+ end
527
537
 
528
538
  if entity.subtype_of.size.zero?
529
539
  "#{entity_type} " \
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.29".freeze
3
+ VERSION = "0.3.31".freeze
4
4
  end
5
5
  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.29
4
+ version: 0.3.31
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-07-07 00:00:00.000000000 Z
11
+ date: 2023-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -175,6 +175,9 @@ executables:
175
175
  - stepmod-convert-express-resource
176
176
  - stepmod-extract-changes
177
177
  - stepmod-extract-concepts
178
+ - stepmod-srl-migrate
179
+ - stepmod-srl-migrate-docs
180
+ - stepmod-srl-migrate-schemas
178
181
  extensions: []
179
182
  extra_rdoc_files: []
180
183
  files:
@@ -197,6 +200,9 @@ files:
197
200
  - exe/stepmod-convert-express-resource
198
201
  - exe/stepmod-extract-changes
199
202
  - exe/stepmod-extract-concepts
203
+ - exe/stepmod-srl-migrate
204
+ - exe/stepmod-srl-migrate-docs
205
+ - exe/stepmod-srl-migrate-schemas
200
206
  - lib/stepmod/utils.rb
201
207
  - lib/stepmod/utils/bibdata.rb
202
208
  - lib/stepmod/utils/change.rb