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 +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/.github/workflows/release.yml +2 -2
- data/exe/stepmod-annotate-all +12 -7
- data/exe/stepmod-extract-terms +40 -34
- data/lib/stepmod/utils/concept.rb +0 -9
- data/lib/stepmod/utils/converters/express_example.rb +19 -0
- data/lib/stepmod/utils/converters/express_note.rb +19 -0
- data/lib/stepmod/utils/converters/module_ref_express_description.rb +14 -0
- data/lib/stepmod/utils/converters/stepmod_ext_description.rb +4 -5
- data/lib/stepmod/utils/smrl_description_converter.rb +1 -1
- data/lib/stepmod/utils/smrl_resource_converter.rb +2 -1
- data/lib/stepmod/utils/stepmod_file_annotator.rb +24 -2
- data/lib/stepmod/utils/terms_extractor.rb +288 -73
- data/lib/stepmod/utils/version.rb +1 -1
- data/stepmod-utils.gemspec +2 -0
- metadata +34 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4541a1fb0b4b3671d2aadf8cb833e93ca8b45f0c591b0da2df55e4614c2bcbf4
|
4
|
+
data.tar.gz: dbf98829e92bfcd54b468691011ab0de3781cf515b4d4b511ec394846f556ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8410dd3702701b592aa67af784813058dcf2299ffe9dd60d45cab59b7035952111e17144b3b3b446e03135ae84a2a7ac5467f155b92ff768aa155d96437f0387
|
7
|
+
data.tar.gz: ea2fb98127cb384a70bd5aaf5febab17a92460170c820b250c52c0dca884bdc8d298f5ecdcf54f52ded4d1d22e75cbbce0fc65582499a04413e5e95cc8eb6b85
|
data/.github/workflows/rake.yml
CHANGED
@@ -15,10 +15,10 @@ on:
|
|
15
15
|
|
16
16
|
jobs:
|
17
17
|
release:
|
18
|
-
uses: metanorma/
|
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
|
|
data/exe/stepmod-annotate-all
CHANGED
@@ -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(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
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
|
data/exe/stepmod-extract-terms
CHANGED
@@ -106,28 +106,29 @@ def replace_images(content)
|
|
106
106
|
content
|
107
107
|
end
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
|
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.
|
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
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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
|
-
"
|
46
|
+
"application module"
|
47
47
|
# when /_schema$/
|
48
48
|
else
|
49
|
-
"
|
49
|
+
"resource"
|
50
50
|
end
|
51
51
|
|
52
52
|
<<~TEMPLATE
|
53
53
|
=== #{linkend.last}
|
54
|
+
#{domain ? "domain:[#{domain}: #{linkend.first}]" : ''}
|
54
55
|
|
55
|
-
#{
|
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
|
-
|
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 #{
|
201
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
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 #{
|
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
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
)
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
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
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
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
|
data/stepmod-utils.gemspec
CHANGED
@@ -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.
|
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-
|
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.
|
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.
|