stepmod-utils 0.3.19 → 0.3.22

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: 4541a1fb0b4b3671d2aadf8cb833e93ca8b45f0c591b0da2df55e4614c2bcbf4
4
- data.tar.gz: dbf98829e92bfcd54b468691011ab0de3781cf515b4d4b511ec394846f556ac6
3
+ metadata.gz: fc9977f6a7248164968637abc31b264b928a1b6de459e62a25fc9a95a250ec10
4
+ data.tar.gz: 030aa9b15094edaa59fbde8ff7948ff7d05dc96b73130495cedcb5f3e52c3b4d
5
5
  SHA512:
6
- metadata.gz: 8410dd3702701b592aa67af784813058dcf2299ffe9dd60d45cab59b7035952111e17144b3b3b446e03135ae84a2a7ac5467f155b92ff768aa155d96437f0387
7
- data.tar.gz: ea2fb98127cb384a70bd5aaf5febab17a92460170c820b250c52c0dca884bdc8d298f5ecdcf54f52ded4d1d22e75cbbce0fc65582499a04413e5e95cc8eb6b85
6
+ metadata.gz: dca1f9e90a28a17c3cbc6082fb115a705bafe55871256bd2f9112fbd4879c02335a04767d60e3d6e5aaa3a935bf738b9a003542741587b8b4537c8328fe8c17c
7
+ data.tar.gz: 625b2542ab86f94f54829e750d8297307dfc47dadf740c3d96d65cff611478d04d1d267eb6b3e71abffebad876bbdfd982f50e09e2081ff1feb505fdd3f20f97
@@ -10,6 +10,8 @@ module Stepmod
10
10
  file_path
11
11
  )
12
12
 
13
+ # TODO: converted_definition is not supposed to be an attribute, it is
14
+ # supposed to be a method!
13
15
  class << self
14
16
  def parse(definition_xml, reference_anchor:, reference_clause:, file_path:, language_code: "en")
15
17
  converted_definition = Stepmod::Utils::StepmodDefinitionConverter.convert(
@@ -35,6 +37,8 @@ module Stepmod
35
37
  ).strip
36
38
  end
37
39
 
40
+ # TODO: `designations:` should include the `alt:[...]` terms here,
41
+ # they are now only included in definition_xml_converted_definition.
38
42
  new(
39
43
  designations: [designation],
40
44
  definition: definition,
@@ -26,7 +26,8 @@ module Stepmod
26
26
  :part_concepts,
27
27
  :part_resources,
28
28
  :part_modules,
29
- :stdout
29
+ :stdout,
30
+ :git_rev
30
31
 
31
32
  def self.call(stepmod_dir, index_path, stdout = $stdout)
32
33
  new(stepmod_dir, index_path, stdout).call
@@ -65,6 +66,12 @@ module Stepmod
65
66
  log "INFO: STEPmod directory set to #{stepmod_dir}."
66
67
  log "INFO: Detecting paths..."
67
68
 
69
+ # Run `cvs status` to find out version
70
+ log "INFO: Detecting Git SHA..."
71
+ Dir.chdir(stepmod_path) do
72
+ @git_rev = `git rev-parse HEAD` || nil
73
+ end
74
+
68
75
  repo_index = Nokogiri::XML(File.read(@index_path)).root
69
76
 
70
77
  files = []
@@ -145,23 +152,9 @@ module Stepmod
145
152
  next
146
153
  end
147
154
 
148
- revision_string = ""
149
-
150
- # Run `cvs status` to find out version
151
- log "INFO: Detecting Git SHA..."
152
- Dir.chdir(stepmod_path) do
153
- git_sha = `git rev-parse HEAD`
154
-
155
- unless git_sha.empty?
156
- revision_string = "\n// Git: SHA #{git_sha}"
157
- end
158
- end
159
-
160
155
  # read definitions
161
156
  current_part_concepts = Glossarist::Collection.new
162
- definition_index = 0
163
- current_document.xpath("//definition").each do |definition|
164
- definition_index += 1
157
+ current_document.xpath("//definition").each.with_index(1) do |definition, definition_index|
165
158
  term_id = definition["id"]
166
159
  unless term_id.nil?
167
160
  if encountered_terms[term_id]
@@ -178,7 +171,7 @@ module Stepmod
178
171
  definition,
179
172
  reference_anchor: bibdata.anchor,
180
173
  reference_clause: ref_clause,
181
- file_path: fpath + revision_string,
174
+ file_path: fpath,
182
175
  )
183
176
  next unless concept
184
177
 
@@ -197,7 +190,7 @@ module Stepmod
197
190
  current_part_modules_arm = {}
198
191
  current_part_modules_mim = {}
199
192
 
200
- log "INFO: FILE PATH IS #{file_path}"
193
+ # log "INFO: FILE PATH IS #{file_path}"
201
194
  case file_path.to_s
202
195
  when /resource.xml$/
203
196
  log "INFO: Processing resource.xml for #{fpath}"
@@ -272,93 +265,27 @@ module Stepmod
272
265
  parsed_schema_names[schema_name] = file_path
273
266
  end
274
267
 
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
268
+ arm_schema, arm_concepts = parse_annotated_module(
269
+ type: :arm,
270
+ stepmod_path: stepmod_path,
271
+ path: "modules/#{schema_name}/arm_annotated.exp",
272
+ bibdata: bibdata
273
+ )
307
274
 
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
- )
275
+ mim_schema, mim_concepts = parse_annotated_module(
276
+ type: :mim,
277
+ stepmod_path: stepmod_path,
278
+ path: "modules/#{schema_name}/mim_annotated.exp",
279
+ bibdata: bibdata
280
+ )
313
281
 
314
- # puts part_modules_arm.inspect
315
- parsed_bibliography << bibdata
316
- end
317
- end
282
+ if arm_concepts.to_a.size > 0
283
+ current_part_modules_arm[arm_schema] = arm_concepts
318
284
  end
319
285
 
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
359
- end
286
+ if mim_concepts.to_a.size > 0
287
+ current_part_modules_mim[mim_schema] = mim_concepts
360
288
  end
361
-
362
289
  end
363
290
 
364
291
  log "INFO: Completed processing XML file #{fpath}"
@@ -386,13 +313,74 @@ module Stepmod
386
313
 
387
314
  if (current_part_modules_arm.to_a.size +
388
315
  current_part_modules_mim.to_a.size).positive?
316
+
389
317
  part_modules << [bibdata, current_part_modules_arm,
390
318
  current_part_modules_mim]
319
+ parsed_bibliography << bibdata
391
320
  end
392
321
 
393
322
  end
394
323
  end
395
324
 
325
+ def parse_annotated_module(type:, stepmod_path:, path:, bibdata:)
326
+ log "INFO: parse_annotated_module: Processing modules schema #{path}"
327
+
328
+ fpath = File.join(stepmod_path, path)
329
+
330
+ unless File.exists?(fpath)
331
+ log "ERROR: parse_annotated_module: No module schema exists at #{fpath}."
332
+ return
333
+ end
334
+
335
+ repo = Expressir::Express::Parser.from_file(fpath)
336
+
337
+ unless repo
338
+ log "ERROR: parse_annotated_module: failed to parse EXPRESS file at #{path}."
339
+ return
340
+ end
341
+
342
+ # See: metanorma/iso-10303-2#90
343
+ domain_prefix = case type
344
+ when :mim
345
+ "application module"
346
+ when :arm
347
+ "application object"
348
+ end
349
+
350
+ if repo.schemas.length > 1
351
+ raise StandardError.new(
352
+ "ERROR: FATAL: #{fpath} contains more than one schema:" +
353
+ "#{repo.schemas.map(&:id).join(", ")} (not supposed to happen!!)"
354
+ )
355
+ end
356
+
357
+ schema = repo.schemas.first
358
+ collection = Glossarist::Collection.new
359
+ domain = "#{domain_prefix}: #{schema.id}"
360
+
361
+ schema.entities.each do |entity|
362
+ old_definition = entity.remarks.first
363
+ new_definition = generate_entity_definition(entity, domain, old_definition)
364
+
365
+ concept = Stepmod::Utils::Concept.new(
366
+ designations: [entity.id],
367
+ definition: old_definition,
368
+ converted_definition: new_definition,
369
+ # TODO: Find a proper ID for this
370
+ id: "#{bibdata.anchor}.",
371
+ reference_anchor: bibdata.anchor,
372
+ reference_clause: nil,
373
+ file_path: path,
374
+ language_code: "en",
375
+ )
376
+
377
+ next unless concept
378
+ find_or_initialize_concept(collection, concept)
379
+ end
380
+
381
+ [schema.id, collection]
382
+ end
383
+
396
384
  def find_or_initialize_concept(collection, localized_concept)
397
385
  concept = collection
398
386
  .store(Glossarist::Concept.new(id: SecureRandom.uuid))
@@ -456,7 +444,9 @@ module Stepmod
456
444
  combined.gsub!(/\n\/\/.*?\n/, "\n")
457
445
  combined.strip!
458
446
 
459
- combined
447
+ express_reference_to_mention(combined)
448
+
449
+ # combined
460
450
  # # TODO: If the definition contains a list immediately after the first paragraph, don't split
461
451
  # return definition if definition =~ /\n\* /
462
452
 
@@ -473,44 +463,48 @@ module Stepmod
473
463
  # end
474
464
  end
475
465
 
466
+ # Replace `<<express:{schema}.{entity},{render}>>` with {{entity,render}}
467
+ def express_reference_to_mention(description)
468
+ # TODO: Use Expressir to check whether the "entity" is really an
469
+ # EXPRESS ENTITY. If not, skip the mention.
470
+ description.gsub(/<<express:([^,]+),([^>]+)>>/) do |match|
471
+ "{{#{Regexp.last_match[1].split('.').last},#{Regexp.last_match[2]}}}"
472
+ end
473
+ end
474
+
476
475
  def entity_name_to_text(entity_id)
477
476
  entity_id.downcase.gsub(/_/, " ")
478
477
  end
479
478
 
479
+ def entity_ref(entity_id)
480
+ if entity_id == entity_name_to_text(entity_id)
481
+ "{{#{entity_id}}}"
482
+ else
483
+ "{{#{entity_id},#{entity_name_to_text(entity_id)}}}"
484
+ end
485
+ end
486
+
480
487
  # rubocop:disable Layout/LineLength
481
488
  def generate_entity_definition(entity, domain, old_definition)
482
489
  return "" if entity.nil?
483
490
 
484
491
  # 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
-
492
+ entity_type = if domain_type = domain.match(/\A(application object):/)
493
+ domain_type[1]
500
494
  else
495
+ "entity data type"
496
+ end
501
497
 
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"
498
+ entity_text = if entity.subtype_of.size.zero?
499
+ "#{entity_type} " +
500
+ "that represents the " + entity_ref(entity.id) + " entity"
501
+ else
502
+ entity_subtypes = entity.subtype_of.map do |e|
503
+ "{{#{e.id}}}"
513
504
  end
505
+ "#{entity_type} that is a type of " +
506
+ "#{entity_subtypes.join(' and ')} " +
507
+ "that represents the " + entity_ref(entity.id) + " entity"
514
508
  end
515
509
 
516
510
  definition = <<~DEFINITION
@@ -521,6 +515,7 @@ module Stepmod
521
515
 
522
516
  DEFINITION
523
517
 
518
+ # If there is a definition, we add it as the first NOTE
524
519
  unless old_definition.nil? || old_definition.blank?
525
520
  old_definition = trim_definition(old_definition)
526
521
 
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.19".freeze
3
+ VERSION = "0.3.22".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.19
4
+ version: 0.3.22
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-09-10 00:00:00.000000000 Z
11
+ date: 2022-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby