stepmod-utils 0.3.19 → 0.3.20
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 +4 -4
- data/lib/stepmod/utils/concept.rb +4 -0
- data/lib/stepmod/utils/terms_extractor.rb +93 -104
- data/lib/stepmod/utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a0c01510a286c5aa7e3b0a32a910b7b3637726e01cb7433f8552ef6758f3fa5
|
4
|
+
data.tar.gz: 0a3fd286cb1f42a4d5cb52989616cb36cc39cffd49c0cd6a7219685b9b83dfba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cca0b6de2ee2109e0f11f144406a14f58a54cbd2030ae15180d897a923bf8c98de36b9f8c1d59445a2cde22a1cc2c9ac70474f6b1262fb6a7faa4bec460a631
|
7
|
+
data.tar.gz: c4c78c48c121619e7e47fda0a86caeaec622535cd5c57468e1316998fa4ab7a2c73549fe227c0a7df2bde4ea69f32852b52018304cfabe6c129241f8a2b54484
|
@@ -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
|
-
|
163
|
-
current_document.xpath("//definition").each do |definition|
|
164
|
-
definition_index += 1
|
157
|
+
current_document.xpath("//definition").each_with_index 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
|
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
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
315
|
-
|
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
|
-
|
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))
|
@@ -483,23 +471,23 @@ module Stepmod
|
|
483
471
|
|
484
472
|
# See: metanorma/iso-10303-2#90
|
485
473
|
# TODO: This is not DRY in case we have to further customize
|
486
|
-
entity_text = if
|
474
|
+
entity_text = if domain_type = domain.match(/\A(application.*?):/)
|
487
475
|
|
488
476
|
if entity.subtype_of.size.zero?
|
489
|
-
"
|
477
|
+
"#{domain_type[1]} that represents the " +
|
490
478
|
"{{#{entity.id},#{entity_name_to_text(entity.id)}}} entity"
|
491
479
|
else
|
492
480
|
entity_subtypes = entity.subtype_of.map do |e|
|
493
481
|
"{{#{e.id},#{entity_name_to_text(e.id)}}}"
|
494
482
|
end
|
495
|
-
"
|
483
|
+
"#{domain_type[1]} that is a type of " +
|
496
484
|
"#{entity_subtypes.join(' and ')} that represents the " +
|
497
485
|
"{{#{entity.id},#{entity_name_to_text(entity.id)}}} entity"
|
498
486
|
end
|
499
487
|
|
500
488
|
else
|
501
489
|
|
502
|
-
# Not "application object"
|
490
|
+
# Not "application object" or "application module"
|
503
491
|
if entity.subtype_of.size.zero?
|
504
492
|
"entity data type that represents " +
|
505
493
|
entity.id.indefinite_article + " {{#{entity.id}}} entity"
|
@@ -521,6 +509,7 @@ module Stepmod
|
|
521
509
|
|
522
510
|
DEFINITION
|
523
511
|
|
512
|
+
# If there is a definition, we add it as the first NOTE
|
524
513
|
unless old_definition.nil? || old_definition.blank?
|
525
514
|
old_definition = trim_definition(old_definition)
|
526
515
|
|
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.
|
4
|
+
version: 0.3.20
|
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-
|
11
|
+
date: 2022-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|