stepmod-utils 0.3.16 → 0.3.19

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: e40fc2ba271e4bd8e0859cb307831ead927b7bc12154b5845f528694ad18c8f8
4
- data.tar.gz: e1b6f691a70d1e6531a7f841b5a998d49d6c376a84a9da340246b2920bd8459d
3
+ metadata.gz: 4541a1fb0b4b3671d2aadf8cb833e93ca8b45f0c591b0da2df55e4614c2bcbf4
4
+ data.tar.gz: dbf98829e92bfcd54b468691011ab0de3781cf515b4d4b511ec394846f556ac6
5
5
  SHA512:
6
- metadata.gz: e5e62c15d95982deb33e03af65b9720cdb34746adfa36bf5945a2823fb0be9800beff3e8cf4b3e4acd34ebf940bacb0ff2b4a83b31af27e8d01cba2599fcc537
7
- data.tar.gz: c9efdfa5eed962291c9454227e8d2c7c22b4ba665c88745d059f77cdfb5ae2bdb414d32d7c1ee957aec10db634c1f0fbc388851360ae4edb9bf9d721f740dca3
6
+ metadata.gz: 8410dd3702701b592aa67af784813058dcf2299ffe9dd60d45cab59b7035952111e17144b3b3b446e03135ae84a2a7ac5467f155b92ff768aa155d96437f0387
7
+ data.tar.gz: ea2fb98127cb384a70bd5aaf5febab17a92460170c820b250c52c0dca884bdc8d298f5ecdcf54f52ded4d1d22e75cbbce0fc65582499a04413e5e95cc8eb6b85
@@ -10,6 +10,6 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- uses: metanorma/metanorma-build-scripts/.github/workflows/generic-rake.yml@main
13
+ uses: metanorma/ci/.github/workflows/generic-rake.yml@main
14
14
  secrets:
15
15
  pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
@@ -15,10 +15,10 @@ on:
15
15
 
16
16
  jobs:
17
17
  release:
18
- uses: metanorma/metanorma-build-scripts/.github/workflows/rubygems-release.yml@main
18
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
19
19
  with:
20
20
  next_version: ${{ github.event.inputs.next_version }}
21
- event_name: ${{ github.event_name }}
22
21
  secrets:
23
22
  rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
23
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
24
24
 
@@ -27,15 +27,20 @@ files.each_slice(MAX_QUEUE_SIZE) do |batch|
27
27
  batch.each do |file|
28
28
  pool.post do
29
29
  puts("#{Thread.current.object_id}: Queued processing #{file}")
30
- annotated = Stepmod::Utils::StepmodFileAnnotator.new(express_file: file,
31
- resource_docs_cache_file: resource_docs_cache_file, stepmod_dir: stepmod_dir).call
32
- File.open(
33
- File.join(File.dirname(file),
34
- "#{File.basename(file, '.exp')}_annotated.exp"), "w"
35
- ) do |file|
30
+ annotated = Stepmod::Utils::StepmodFileAnnotator.new(
31
+ express_file: file,
32
+ resource_docs_cache_file: resource_docs_cache_file,
33
+ stepmod_dir: stepmod_dir
34
+ ).call
35
+
36
+ annotated_file_name = "#{File.basename(file, '.exp')}_annotated.exp"
37
+ annotated_file_path = File.join(File.dirname(file), annotated_file_name)
38
+
39
+ File.open(annotated_file_path, "w") do |file|
36
40
  file.puts(annotated)
37
41
  end
38
- puts("#{Thread.current.object_id}: Done processing #{file}")
42
+
43
+ puts("#{Thread.current.object_id}: Done processing #{File.basename(file)} => #{annotated_file_path}.")
39
44
  end
40
45
  end
41
46
  pool.shutdown
@@ -106,28 +106,29 @@ def replace_images(content)
106
106
  content
107
107
  end
108
108
 
109
- part_concepts.each do |(bibdata, current_part_concepts)|
110
- current_part_concepts = current_part_concepts.to_a.map do |n|
111
- n.localizations["en"]
112
- end
113
- fn = "03x-stepmod-#{bibdata.part}.adoc"
114
- File.open(fn, "w") do |file|
115
- file.puts("== #{part_to_title(bibdata)}\n\n")
116
- file.puts(replace_images(current_part_concepts.map(&:to_mn_adoc).join("\n")))
117
- end
118
- log "INFO: written to: #{fn}"
119
- end
120
-
121
- File.open("03x-stepmod.adoc", "w") do |file|
122
- part_concepts.sort_by do |(bibdata, current_part_concepts)|
123
- bibdata.part.to_i
124
- end.each do |(bibdata, current_part_concepts)|
125
- fn = "03x-stepmod-#{bibdata.part}.adoc"
126
- file.puts("\ninclude::#{fn}[]\n")
127
- end
128
- end
129
-
130
- log "INFO: written summary file to: 03x-stepmod.adoc"
109
+ ## Skip all Clause 3 terms
110
+ # part_concepts.each do |(bibdata, current_part_concepts)|
111
+ # current_part_concepts = current_part_concepts.to_a.map do |n|
112
+ # n.localizations["en"]
113
+ # end
114
+ # fn = "03x-stepmod-#{bibdata.part}.adoc"
115
+ # File.open(fn, "w") do |file|
116
+ # file.puts("== #{part_to_title(bibdata)}\n\n")
117
+ # file.puts(replace_images(current_part_concepts.map(&:to_mn_adoc).join("\n")))
118
+ # end
119
+ # log "INFO: written to: #{fn}"
120
+ # end
121
+
122
+ # File.open("03x-stepmod.adoc", "w") do |file|
123
+ # part_concepts.sort_by do |(bibdata, current_part_concepts)|
124
+ # bibdata.part.to_i
125
+ # end.each do |(bibdata, current_part_concepts)|
126
+ # fn = "03x-stepmod-#{bibdata.part}.adoc"
127
+ # file.puts("\ninclude::#{fn}[]\n")
128
+ # end
129
+ # end
130
+
131
+ # log "INFO: written summary file to: 03x-stepmod.adoc"
131
132
 
132
133
  part_resources.each do |(bibdata, current_part_resources)|
133
134
  current_part_resources = current_part_resources.to_a.map do |n|
@@ -152,10 +153,13 @@ end
152
153
 
153
154
  log "INFO: written summary file to: 04x-stepmod-entities-resources.adoc"
154
155
 
155
- part_modules.each do |(bibdata, part_modules_arm, part_modules_mim)|
156
+ part_modules.sort_by do |(bibdata, part_modules_arm, part_modules_mim)|
157
+ bibdata.part.to_i
158
+ end.each do |(bibdata, part_modules_arm, part_modules_mim)|
156
159
  fn = "05x-stepmod-entities-modules-#{bibdata.part}.adoc"
157
160
  File.open(fn, "w") do |file|
158
161
  file.puts("")
162
+
159
163
  unless part_modules_arm.empty?
160
164
  schema_name = part_modules_arm.first.first
161
165
  concepts = part_modules_arm.first.last.to_a.map do |n|
@@ -180,6 +184,7 @@ part_modules.each do |(bibdata, part_modules_arm, part_modules_mim)|
180
184
  file.puts(replace_images(concepts.map(&:to_mn_adoc).join("\n")))
181
185
  end
182
186
  end
187
+
183
188
  log "INFO: written to: #{fn}"
184
189
  end
185
190
 
@@ -194,17 +199,18 @@ end
194
199
 
195
200
  log "INFO: written summary file to: 05x-stepmod-entities-modules.adoc"
196
201
 
197
- File.open("031-stepmod-general.adoc", "w") do |file|
198
- file.puts(
199
- replace_images(
200
- general_concepts.to_a.map do |n|
201
- n.localizations["en"]
202
- end.map(&:to_mn_adoc).join("\n")
203
- )
204
- )
205
- end
206
-
207
- log "INFO: written to: 031-stepmod-general.adoc"
202
+ ## Skipping all Clause 3 terms
203
+ # File.open("031-stepmod-general.adoc", "w") do |file|
204
+ # file.puts(
205
+ # replace_images(
206
+ # general_concepts.to_a.map do |n|
207
+ # n.localizations["en"]
208
+ # end.map(&:to_mn_adoc).join("\n")
209
+ # )
210
+ # )
211
+ # end
212
+
213
+ # log "INFO: written to: 031-stepmod-general.adoc"
208
214
 
209
215
  File.open("041-stepmod-entities-resources.adoc", "w") do |file|
210
216
  file.puts(
@@ -23,15 +23,6 @@ module Stepmod
23
23
 
24
24
  return nil if converted_definition.nil? || converted_definition.strip.empty?
25
25
 
26
- if definition_xml.name == "ext_description"
27
- converted_definition = <<~TEXT
28
- #{converted_definition}
29
-
30
- NOTE: This term is incompletely defined in this document.
31
- Reference <<#{reference_anchor}>> for the complete definition.
32
- TEXT
33
- end
34
-
35
26
  # https://github.com/metanorma/stepmod-utils/issues/86
36
27
 
37
28
  # TODO: This portion DOES NOT HANDLE the <synonym> element. WTF??
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ExpressExample < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ <<~TEMPLATE
9
+ (*"#{state[:schema_and_entity]}.__example"
10
+ #{treat_children(node, state).strip}
11
+ *)
12
+ TEMPLATE
13
+ end
14
+ end
15
+
16
+ ReverseAdoc::Converters.register :express_example, ExpressExample.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ExpressNote < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ <<~TEMPLATE
9
+ (*"#{state[:schema_and_entity]}.__note"
10
+ #{treat_children(node, state).strip}
11
+ *)
12
+ TEMPLATE
13
+ end
14
+ end
15
+
16
+ ReverseAdoc::Converters.register :express_note, ExpressNote.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Stepmod
2
+ module Utils
3
+ module Converters
4
+ class ModuleRefExpressDescription < ReverseAdoc::Converters::Base
5
+ def convert(node, _state = {})
6
+ parts = node["linkend"].to_s.split(":").last.split(".")
7
+ "<<express:#{parts.join('.').strip},#{parts.last.strip}>>"
8
+ end
9
+ end
10
+ ReverseAdoc::Converters.register :module_ref,
11
+ ModuleRefExpressDescription.new
12
+ end
13
+ end
14
+ end
@@ -43,18 +43,17 @@ module Stepmod
43
43
 
44
44
  domain = case linkend.first
45
45
  when /_mim$/, /_arm$/
46
- "ISO 10303 application module"
46
+ "application module"
47
47
  # when /_schema$/
48
48
  else
49
- "ISO 10303 resource"
49
+ "resource"
50
50
  end
51
51
 
52
52
  <<~TEMPLATE
53
53
  === #{linkend.last}
54
+ #{domain ? "domain:[#{domain}: #{linkend.first}]" : ''}
54
55
 
55
- #{domain ? "domain:[#{domain}]" : ''}
56
-
57
- #{child_text}
56
+ #{child_text.strip}
58
57
  TEMPLATE
59
58
  end
60
59
  end
@@ -41,7 +41,7 @@ module Stepmod
41
41
  root || (return "")
42
42
 
43
43
  ReverseAdoc.config.with(options) do
44
- result = ReverseAdoc::Converters.lookup(root.name).convert(root)
44
+ result = ReverseAdoc::Converters.lookup(root.name).convert(root, options)
45
45
  Stepmod::Utils::Cleaner.new.tidy(result)
46
46
  end
47
47
  end
@@ -59,7 +59,8 @@ module Stepmod
59
59
  root || (return "")
60
60
 
61
61
  ReverseAdoc.config.with(options) do
62
- result = ReverseAdoc::Converters.lookup(root.name).convert(root)
62
+ result = ReverseAdoc::Converters.lookup(root.name).convert(root, options)
63
+
63
64
  Stepmod::Utils::Cleaner.new.tidy(result)
64
65
  end
65
66
  end
@@ -1,6 +1,8 @@
1
1
  require "json"
2
2
  require "stepmod/utils/smrl_description_converter"
3
3
  require "stepmod/utils/smrl_resource_converter"
4
+ require "stepmod/utils/converters/express_note"
5
+ require "stepmod/utils/converters/express_example"
4
6
 
5
7
  module Stepmod
6
8
  module Utils
@@ -64,7 +66,27 @@ module Stepmod
64
66
  def convert_from_description_text(descriptions_file, description)
65
67
  Dir.chdir(File.dirname(descriptions_file)) do
66
68
  wrapper = "<ext_descriptions>#{description}</ext_descriptions>"
67
- "\n#{Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)}"
69
+ notes = description.xpath("note")
70
+ examples = description.xpath("example")
71
+
72
+ converted_description = <<~DESCRIPTION
73
+
74
+ #{Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper, no_notes_examples: true)}
75
+ DESCRIPTION
76
+
77
+ converted_examples = examples.map do |example|
78
+ Stepmod::Utils::Converters::ExpressExample
79
+ .new
80
+ .convert(example, schema_and_entity: description["linkend"])
81
+ end.join
82
+
83
+ converted_notes = notes.map do |note|
84
+ Stepmod::Utils::Converters::ExpressNote
85
+ .new
86
+ .convert(note, schema_and_entity: description["linkend"])
87
+ end.join
88
+
89
+ "#{converted_description}#{converted_examples}#{converted_notes}"
68
90
  end
69
91
  end
70
92
 
@@ -77,7 +99,7 @@ module Stepmod
77
99
 
78
100
  Dir.chdir(File.dirname(descriptions_file)) do
79
101
  wrapper = "<resource>#{schema}</resource>"
80
- "\n#{Stepmod::Utils::SmrlResourceConverter.convert(wrapper)}"
102
+ "\n#{Stepmod::Utils::SmrlResourceConverter.convert(wrapper, no_notes_examples: true)}"
81
103
  end
82
104
  end
83
105
  end
@@ -3,6 +3,9 @@ require "stepmod/utils/bibdata"
3
3
  require "stepmod/utils/concept"
4
4
  require "glossarist"
5
5
  require "securerandom"
6
+ require "expressir"
7
+ require "expressir/express/parser"
8
+ require "indefinite_article"
6
9
 
7
10
  ReverseAdoc.config.unknown_tags = :bypass
8
11
 
@@ -131,8 +134,8 @@ module Stepmod
131
134
  end
132
135
 
133
136
  unless ACCEPTED_STAGES.include? bibdata.doctype
134
- log "INFO: skipped #{bibdata.docid} as it is not \
135
- one of (#{ACCEPTED_STAGES.join(', ')})."
137
+ log "INFO: skipped #{bibdata.docid} as it is not " \
138
+ "one of (#{ACCEPTED_STAGES.join(', ')})."
136
139
  next
137
140
  end
138
141
 
@@ -197,8 +200,8 @@ module Stepmod
197
200
  log "INFO: FILE PATH IS #{file_path}"
198
201
  case file_path.to_s
199
202
  when /resource.xml$/
200
- log "INFO: Processing resource.xml for #{file_path}"
201
- # Assumption: every schema is only linked by a single resource_docs document.
203
+ log "INFO: Processing resource.xml for #{fpath}"
204
+
202
205
  current_document.xpath("//schema").each do |schema_node|
203
206
  schema_name = schema_node["name"]
204
207
  if parsed_schema_names[schema_name]
@@ -210,19 +213,36 @@ module Stepmod
210
213
  parsed_schema_names[schema_name] = file_path
211
214
  end
212
215
 
213
- Dir["#{stepmod_path}/resources/#{schema_name}/descriptions.xml"].each do |description_xml_path|
214
- log "INFO: Processing resources schema #{description_xml_path}"
215
- description_document = Nokogiri::XML(File.read(description_xml_path)).root
216
- description_document.xpath("//ext_description").each do |ext_description|
217
- # log "INFO: Processing linkend[#{ext_description['linkend']}]"
218
-
219
- concept = Stepmod::Utils::Concept.parse(
220
- ext_description,
221
- reference_anchor: bibdata.anchor,
222
- reference_clause: nil,
223
- file_path: Pathname.new(description_xml_path)
216
+ exp_annotated_path =
217
+ "#{stepmod_path}/resources/#{schema_name}/#{schema_name}_annotated.exp"
218
+
219
+ log "INFO: Processing resources schema #{exp_annotated_path}"
220
+
221
+ if File.exists?(exp_annotated_path)
222
+ repo = Expressir::Express::Parser.from_file(exp_annotated_path)
223
+ schema = repo.schemas.first
224
+
225
+ schema.entities.each do |entity|
226
+ old_definition = entity.remarks.first
227
+
228
+ domain = "resource: #{schema.id}"
229
+ entity_definition = generate_entity_definition(entity, domain, old_definition)
230
+
231
+ reference_anchor = bibdata.anchor
232
+ reference_clause = nil
233
+
234
+ concept = Stepmod::Utils::Concept.new(
235
+ designations: [entity.id],
236
+ definition: old_definition,
237
+ converted_definition: entity_definition,
238
+ id: "#{reference_anchor}.#{reference_clause}",
239
+ reference_anchor: reference_anchor,
240
+ reference_clause: reference_clause,
241
+ file_path: Pathname.new(exp_annotated_path)
224
242
  .relative_path_from(stepmod_path),
243
+ language_code: "en",
225
244
  )
245
+
226
246
  next unless concept
227
247
 
228
248
  if term_special_category(bibdata)
@@ -239,7 +259,7 @@ module Stepmod
239
259
  end
240
260
 
241
261
  when /module.xml$/
242
- log "INFO: Processing module.xml for #{file_path}"
262
+ log "INFO: Processing module.xml for #{fpath}"
243
263
  # Assumption: every schema is only linked by a single module document.
244
264
  # puts current_document.xpath('//module').length
245
265
  schema_name = current_document.xpath("//module").first["name"]
@@ -252,62 +272,90 @@ module Stepmod
252
272
  parsed_schema_names[schema_name] = file_path
253
273
  end
254
274
 
255
- description_xml_path = "#{stepmod_path}/modules/#{schema_name}/arm_descriptions.xml"
256
- log "INFO: Processing modules schema #{description_xml_path}"
257
-
258
- if File.exists?(description_xml_path)
259
- description_document = Nokogiri::XML(
260
- File.read(description_xml_path),
261
- )
262
- .root
263
- description_document.xpath("//ext_description").each do |ext_description|
264
- linkend_schema = ext_description["linkend"].split(".").first
265
- concept = Stepmod::Utils::Concept.parse(
266
- ext_description,
267
- reference_anchor: bibdata.anchor,
268
- reference_clause: nil,
269
- file_path: Pathname.new(description_xml_path)
270
- .relative_path_from(stepmod_path),
271
- )
272
- next unless concept
273
-
274
- current_part_modules_arm[linkend_schema] ||= Glossarist::Collection.new
275
- find_or_initialize_concept(
276
- current_part_modules_arm[linkend_schema], concept
277
- )
278
- # puts part_modules_arm.inspect
279
- parsed_bibliography << bibdata
275
+ exp_annotated_path =
276
+ "#{stepmod_path}/modules/#{schema_name}/arm_annotated.exp"
277
+
278
+ log "INFO: Processing modules schema #{exp_annotated_path}"
279
+
280
+ if File.exists?(exp_annotated_path)
281
+ repo = Expressir::Express::Parser.from_file(exp_annotated_path)
282
+
283
+ repo.schemas.each do |schema|
284
+ schema.entities.each do |entity|
285
+ old_definition = entity.remarks.first
286
+
287
+ # See: metanorma/iso-10303-2#90
288
+ domain = "application object: #{schema.id}"
289
+ entity_definition = generate_entity_definition(entity, domain, old_definition)
290
+
291
+ reference_anchor = bibdata.anchor
292
+ reference_clause = nil
293
+
294
+ concept = Stepmod::Utils::Concept.new(
295
+ designations: [entity.id],
296
+ definition: old_definition,
297
+ converted_definition: entity_definition,
298
+ id: "#{reference_anchor}.#{reference_clause}",
299
+ reference_anchor: reference_anchor,
300
+ reference_clause: reference_clause,
301
+ file_path: Pathname.new(exp_annotated_path)
302
+ .relative_path_from(stepmod_path),
303
+ language_code: "en",
304
+ )
305
+
306
+ next unless concept
307
+
308
+ current_part_modules_arm[schema.id] ||=
309
+ Glossarist::Collection.new
310
+ find_or_initialize_concept(
311
+ current_part_modules_arm[schema.id], concept
312
+ )
313
+
314
+ # puts part_modules_arm.inspect
315
+ parsed_bibliography << bibdata
316
+ end
280
317
  end
281
318
  end
282
319
 
283
- description_xml_path = "#{stepmod_path}/modules/#{schema_name}/mim_descriptions.xml"
284
- log "INFO: Processing modules schema #{description_xml_path}"
285
-
286
- if File.exists?(description_xml_path)
287
- description_document = Nokogiri::XML(
288
- File.read(description_xml_path),
289
- )
290
- .root
291
- description_document.xpath("//ext_description").each do |ext_description|
292
- linkend_schema = ext_description["linkend"].split(".").first
293
-
294
- concept = Stepmod::Utils::Concept.parse(
295
- ext_description,
296
- reference_anchor: bibdata.anchor,
297
- reference_clause: nil,
298
- file_path: Pathname
299
- .new(description_xml_path)
300
- .relative_path_from(stepmod_path),
301
- )
302
- next unless concept
303
-
304
- current_part_modules_mim[linkend_schema] ||=
305
- Glossarist::Collection.new
306
- find_or_initialize_concept(
307
- current_part_modules_mim[linkend_schema], concept
308
- )
309
-
310
- parsed_bibliography << bibdata
320
+ mim_exp_annotated_path = "#{stepmod_path}/modules/#{schema_name}/mim_annotated.exp"
321
+
322
+ log "INFO: Processing modules schema #{mim_exp_annotated_path}"
323
+
324
+ if File.exists?(mim_exp_annotated_path)
325
+ repo = Expressir::Express::Parser.from_file(mim_exp_annotated_path)
326
+
327
+ repo.schemas.each do |schema|
328
+ schema.entities.each do |entity|
329
+ old_definition = entity.remarks.first
330
+
331
+ domain = "application module: #{schema.id}"
332
+ definition = generate_entity_definition(entity, domain, old_definition)
333
+
334
+ reference_anchor = bibdata.anchor
335
+ reference_clause = nil
336
+
337
+ concept = Stepmod::Utils::Concept.new(
338
+ designations: [entity.id],
339
+ definition: old_definition,
340
+ converted_definition: definition,
341
+ id: "#{reference_anchor}.#{reference_clause}",
342
+ reference_anchor: reference_anchor,
343
+ reference_clause: reference_clause,
344
+ file_path: Pathname.new(exp_annotated_path)
345
+ .relative_path_from(stepmod_path),
346
+ language_code: "en",
347
+ )
348
+
349
+ next unless concept
350
+
351
+ current_part_modules_mim[schema.id] ||=
352
+ Glossarist::Collection.new
353
+ find_or_initialize_concept(
354
+ current_part_modules_mim[schema.id], concept
355
+ )
356
+
357
+ parsed_bibliography << bibdata
358
+ end
311
359
  end
312
360
  end
313
361
 
@@ -315,11 +363,11 @@ module Stepmod
315
363
 
316
364
  log "INFO: Completed processing XML file #{fpath}"
317
365
  if current_part_concepts.to_a.empty?
318
- log "INFO: Skipping #{fpath} (#{bibdata.docid}) \
319
- because it contains no concepts."
366
+ log "INFO: Skipping #{fpath} (#{bibdata.docid}) " \
367
+ "because it contains no concepts."
320
368
  elsif current_part_concepts.to_a.length < 3
321
- log "INFO: Skipping #{fpath} (#{bibdata.docid}) \
322
- because it only has #{current_part_concepts.to_a.length} terms."
369
+ log "INFO: Skipping #{fpath} (#{bibdata.docid}) " \
370
+ "because it only has #{current_part_concepts.to_a.length} terms."
323
371
 
324
372
  current_part_concepts.to_a.each do |x|
325
373
  general_concepts.store(x)
@@ -330,15 +378,18 @@ module Stepmod
330
378
  current_part_concepts]
331
379
  end
332
380
  end
381
+
333
382
  unless current_part_resources.to_a.empty?
334
383
  part_resources << [bibdata,
335
384
  current_part_resources]
336
385
  end
386
+
337
387
  if (current_part_modules_arm.to_a.size +
338
388
  current_part_modules_mim.to_a.size).positive?
339
389
  part_modules << [bibdata, current_part_modules_arm,
340
390
  current_part_modules_mim]
341
391
  end
392
+
342
393
  end
343
394
  end
344
395
 
@@ -347,6 +398,170 @@ module Stepmod
347
398
  .store(Glossarist::Concept.new(id: SecureRandom.uuid))
348
399
  concept.add_l10n(localized_concept)
349
400
  end
401
+
402
+ def combine_paragraphs(full_paragraph, next_paragraph)
403
+ # If full_paragraph already contains a period, extract that.
404
+ if m = full_paragraph.match(/\A(?<inner_first>[^\n]*?\.)\s/)
405
+ # puts "CONDITION 1"
406
+ if m[:inner_first]
407
+ return m[:inner_first]
408
+ else
409
+ return full_paragraph
410
+ end
411
+ end
412
+
413
+ # If full_paragraph ends with a period, this is the last.
414
+ if full_paragraph =~ /\.\s*\Z/
415
+ # puts "CONDITION 2"
416
+ return full_paragraph
417
+ end
418
+
419
+ # If next_paragraph is a list
420
+ if next_paragraph.match(/\A\*/)
421
+ # puts "CONDITION 3"
422
+ return full_paragraph + "\n\n" + next_paragraph
423
+ end
424
+
425
+ # If next_paragraph is a continuation of a list
426
+ if next_paragraph.match(/\Awhich/) || next_paragraph.match(/\Athat/)
427
+ # puts "CONDITION 4"
428
+ return full_paragraph + "\n\n" + next_paragraph
429
+ end
430
+
431
+ # puts "CONDITION 5"
432
+ full_paragraph
433
+ end
434
+
435
+ def trim_definition(definition)
436
+ # Unless the first paragraph ends with "between" and is followed by a
437
+ # list, don't split
438
+ paragraphs = definition.split("\n\n")
439
+
440
+ # puts paragraphs.inspect
441
+
442
+ first_paragraph = paragraphs.first
443
+
444
+ if paragraphs.length > 1
445
+ combined = paragraphs[1..-1].inject(first_paragraph) do |acc, p|
446
+ combine_paragraphs(acc, p)
447
+ end
448
+ else
449
+ combined = combine_paragraphs(first_paragraph, "")
450
+ end
451
+
452
+ # puts "combined--------- #{combined}"
453
+
454
+ # Remove comments until end of line
455
+ combined = combined + "\n"
456
+ combined.gsub!(/\n\/\/.*?\n/, "\n")
457
+ combined.strip!
458
+
459
+ combined
460
+ # # TODO: If the definition contains a list immediately after the first paragraph, don't split
461
+ # return definition if definition =~ /\n\* /
462
+
463
+ # unless (
464
+ # first_paragraph =~ /between:?\s*\Z/ ||
465
+ # first_paragraph =~ /include:?\s*\Z/ ||
466
+ # first_paragraph =~ /of:?\s*\Z/ ||
467
+ # first_paragraph =~ /[:;]\s*\Z/
468
+ # ) &&
469
+ # definition =~ /\n\n\*/
470
+
471
+ # # Only taking the first paragraph of the definition
472
+ # first_paragraph
473
+ # end
474
+ end
475
+
476
+ def entity_name_to_text(entity_id)
477
+ entity_id.downcase.gsub(/_/, " ")
478
+ end
479
+
480
+ # rubocop:disable Layout/LineLength
481
+ def generate_entity_definition(entity, domain, old_definition)
482
+ return "" if entity.nil?
483
+
484
+ # See: metanorma/iso-10303-2#90
485
+ # TODO: This is not DRY in case we have to further customize
486
+ entity_text = if domain =~ /\Aapplication object:/
487
+
488
+ if entity.subtype_of.size.zero?
489
+ "application object that represents the " +
490
+ "{{#{entity.id},#{entity_name_to_text(entity.id)}}} entity"
491
+ else
492
+ entity_subtypes = entity.subtype_of.map do |e|
493
+ "{{#{e.id},#{entity_name_to_text(e.id)}}}"
494
+ end
495
+ "application object that is a type of " +
496
+ "#{entity_subtypes.join(' and ')} that represents the " +
497
+ "{{#{entity.id},#{entity_name_to_text(entity.id)}}} entity"
498
+ end
499
+
500
+ else
501
+
502
+ # Not "application object"
503
+ if entity.subtype_of.size.zero?
504
+ "entity data type that represents " +
505
+ entity.id.indefinite_article + " {{#{entity.id}}} entity"
506
+ else
507
+ entity_subtypes = entity.subtype_of.map do |e|
508
+ "{{#{e.id}}}"
509
+ end
510
+ "entity data type that is a type of "+
511
+ "#{entity_subtypes.join(' and ')} that represents " +
512
+ entity.id.indefinite_article + " {{#{entity.id}}} entity"
513
+ end
514
+ end
515
+
516
+ definition = <<~DEFINITION
517
+ === #{entity.id}
518
+ domain:[#{domain}]
519
+
520
+ #{entity_text}
521
+
522
+ DEFINITION
523
+
524
+ unless old_definition.nil? || old_definition.blank?
525
+ old_definition = trim_definition(old_definition)
526
+
527
+ definition << <<~OLD_DEFINITION
528
+ [NOTE]
529
+ --
530
+ #{old_definition.strip}
531
+ --
532
+ OLD_DEFINITION
533
+ end
534
+
535
+ # We no longer add Notes and Examples to the extracted terms
536
+ # definition + format_remark_items(entity.remark_items)
537
+
538
+ definition
539
+ end
540
+
541
+ def format_remark_items(remark_items)
542
+ notes = remark_items.detect { |i| i.id == "__note" }&.remarks
543
+ examples = remark_items.detect { |i| i.id == "__example" }&.remarks
544
+
545
+ formatted_notes = format_remarks(notes, "NOTE", "--")
546
+ formatted_examples = format_remarks(examples, "example", "====")
547
+
548
+ formatted_notes + formatted_examples
549
+ end
550
+ # rubocop:enable Layout/LineLength
551
+
552
+ def format_remarks(remarks, remark_item_name, remark_item_symbol)
553
+ return "" if remarks.nil?
554
+
555
+ remarks.map do |remark|
556
+ <<~REMARK
557
+
558
+ [#{remark_item_name}]
559
+ #{remark_item_symbol}
560
+ #{remark}
561
+ #{remark_item_symbol}
562
+ REMARK
563
+ end.join
564
+ end
350
565
  end
351
566
  end
352
567
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.16".freeze
3
+ VERSION = "0.3.19".freeze
4
4
  end
5
5
  end
@@ -32,7 +32,9 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  spec.add_runtime_dependency "concurrent-ruby"
35
+ spec.add_runtime_dependency "expressir"
35
36
  spec.add_runtime_dependency "glossarist", "~> 0.1.0"
37
+ spec.add_runtime_dependency "indefinite_article"
36
38
  spec.add_runtime_dependency "ptools"
37
39
  spec.add_runtime_dependency "reverse_adoc", ">= 0.3.5"
38
40
  spec.add_runtime_dependency "thor", ">= 0.20.3"
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.16
4
+ version: 0.3.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-21 00:00:00.000000000 Z
11
+ date: 2022-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: expressir
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: glossarist
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: 0.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: indefinite_article
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: ptools
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +206,9 @@ files:
178
206
  - lib/stepmod/utils/converters/em_express_description.rb
179
207
  - lib/stepmod/utils/converters/eqn.rb
180
208
  - lib/stepmod/utils/converters/example.rb
209
+ - lib/stepmod/utils/converters/express_example.rb
181
210
  - lib/stepmod/utils/converters/express_g.rb
211
+ - lib/stepmod/utils/converters/express_note.rb
182
212
  - lib/stepmod/utils/converters/express_ref.rb
183
213
  - lib/stepmod/utils/converters/express_ref_express_description.rb
184
214
  - lib/stepmod/utils/converters/ext_description.rb
@@ -190,6 +220,7 @@ files:
190
220
  - lib/stepmod/utils/converters/ignore.rb
191
221
  - lib/stepmod/utils/converters/introduction.rb
192
222
  - lib/stepmod/utils/converters/module_ref.rb
223
+ - lib/stepmod/utils/converters/module_ref_express_description.rb
193
224
  - lib/stepmod/utils/converters/note.rb
194
225
  - lib/stepmod/utils/converters/ol.rb
195
226
  - lib/stepmod/utils/converters/p.rb
@@ -237,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
268
  - !ruby/object:Gem::Version
238
269
  version: '0'
239
270
  requirements: []
240
- rubygems_version: 3.0.3.1
271
+ rubygems_version: 3.1.6
241
272
  signing_key:
242
273
  specification_version: 4
243
274
  summary: Stepmod-utils is a toolkit that works on STEPmod data.