stepmod-utils 0.2.4 → 0.3.1
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 +3 -12
- data/.github/workflows/release.yml +7 -2
- data/Makefile +4 -1
- data/exe/stepmod-annotate-all +2 -2
- data/exe/stepmod-extract-terms +162 -13
- data/lib/stepmod/utils/bibdata.rb +2 -0
- data/lib/stepmod/utils/concept.rb +15 -2
- data/lib/stepmod/utils/converters/arm.rb +22 -0
- data/lib/stepmod/utils/converters/def.rb +1 -0
- data/lib/stepmod/utils/converters/eqn.rb +8 -7
- data/lib/stepmod/utils/converters/express_g.rb +5 -2
- data/lib/stepmod/utils/converters/ext_description.rb +1 -0
- data/lib/stepmod/utils/converters/fund_cons.rb +7 -1
- data/lib/stepmod/utils/converters/introduction.rb +1 -1
- data/lib/stepmod/utils/converters/ol.rb +1 -1
- data/lib/stepmod/utils/converters/schema.rb +1 -0
- data/lib/stepmod/utils/converters/stepmod_ext_description.rb +22 -0
- data/lib/stepmod/utils/converters/strong.rb +21 -1
- data/lib/stepmod/utils/converters/sub.rb +8 -0
- data/lib/stepmod/utils/converters/sup.rb +6 -0
- data/lib/stepmod/utils/converters/table.rb +62 -0
- data/lib/stepmod/utils/converters/uof.rb +21 -0
- data/lib/stepmod/utils/smrl_resource_converter.rb +1 -1
- data/lib/stepmod/utils/stepmod_definition_converter.rb +14 -9
- data/lib/stepmod/utils/stepmod_file_annotator.rb +41 -17
- data/lib/stepmod/utils/version.rb +1 -1
- metadata +10 -8
- data/exe/stepmod-annotate +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0bf29e9cab4e7f1564993380efa536e105ad6f7aa54612b242d1bd993a4b06f
|
4
|
+
data.tar.gz: 68bae8817c50a70a89fb1b159e0b600ced160435ff45c75f6af063eb6a640c6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58071bec7536d36329370d7be259b7a23efd00870e8aac6d2ecb116a568ec87f08bed596ce3d85e4be3e58b9603e7d4d040f0220d3709ffa8063eb12e77ba9f1
|
7
|
+
data.tar.gz: c48c7d2b6ed22d2b6dd80a3d4ce4ba574f793bc1005ee4e8512b7c696bd06d802bce681ade9919e3ae606ef8807f8993f9ee26d77a12c4430aed23340c8546f9
|
data/.github/workflows/rake.yml
CHANGED
@@ -30,7 +30,9 @@ jobs:
|
|
30
30
|
os: 'macos-latest'
|
31
31
|
experimental: true
|
32
32
|
steps:
|
33
|
-
- uses: actions/checkout@
|
33
|
+
- uses: actions/checkout@v2
|
34
|
+
with:
|
35
|
+
submodules: true
|
34
36
|
|
35
37
|
- uses: ruby/setup-ruby@v1
|
36
38
|
with:
|
@@ -38,14 +40,3 @@ jobs:
|
|
38
40
|
bundler-cache: true
|
39
41
|
|
40
42
|
- run: bundle exec rake
|
41
|
-
|
42
|
-
tests-passed:
|
43
|
-
needs: rake
|
44
|
-
runs-on: ubuntu-latest
|
45
|
-
steps:
|
46
|
-
- uses: peter-evans/repository-dispatch@v1
|
47
|
-
with:
|
48
|
-
token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
|
49
|
-
repository: ${{ github.repository }}
|
50
|
-
event-type: notify
|
51
|
-
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
1
3
|
name: release
|
2
4
|
|
3
5
|
on:
|
@@ -8,6 +10,8 @@ on:
|
|
8
10
|
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
9
11
|
required: true
|
10
12
|
default: 'patch'
|
13
|
+
push:
|
14
|
+
tags: [ v* ]
|
11
15
|
|
12
16
|
jobs:
|
13
17
|
release:
|
@@ -19,9 +23,10 @@ jobs:
|
|
19
23
|
with:
|
20
24
|
ruby-version: '2.6'
|
21
25
|
|
22
|
-
- run: gem install gem-release
|
26
|
+
- run: gem install gem-release
|
23
27
|
|
24
|
-
-
|
28
|
+
- if: ${{ github.event_name == 'workflow_dispatch' }}
|
29
|
+
run: |
|
25
30
|
git config user.name github-actions
|
26
31
|
git config user.email github-actions@github.com
|
27
32
|
gem bump --version ${{ github.event.inputs.next_version }} --tag --push
|
data/Makefile
CHANGED
data/exe/stepmod-annotate-all
CHANGED
@@ -24,12 +24,12 @@ files.each_slice(MAX_QUEUE_SIZE) do |batch|
|
|
24
24
|
puts("Queueing next batch")
|
25
25
|
batch.each do |file|
|
26
26
|
pool.post do
|
27
|
-
puts("Queued processing #{file}")
|
27
|
+
puts("#{Thread.current.object_id}: Queued processing #{file}")
|
28
28
|
annotated = Stepmod::Utils::StepmodFileAnnotator.new(express_file: file, resource_docs_cache_file: resource_docs_cache_file, stepmod_dir: stepmod_dir).call
|
29
29
|
File.open(File.join(File.dirname(file), "#{File.basename(file, '.exp')}_annotated.exp"), 'w') do |file|
|
30
30
|
file.puts(annotated)
|
31
31
|
end
|
32
|
-
puts("Done processing #{file}")
|
32
|
+
puts("#{Thread.current.object_id}: Done processing #{file}")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
pool.shutdown
|
data/exe/stepmod-extract-terms
CHANGED
@@ -24,7 +24,12 @@ require 'ptools'
|
|
24
24
|
|
25
25
|
ReverseAdoc.config.unknown_tags = :bypass
|
26
26
|
|
27
|
-
|
27
|
+
# TODO: we may want a command line option to override this in the future
|
28
|
+
ACCEPTED_STAGES = %w(IS DIS FDIS TS)
|
29
|
+
|
30
|
+
general_concepts = []
|
31
|
+
resource_concepts = []
|
32
|
+
module_concepts = []
|
28
33
|
parsed_bibliography = []
|
29
34
|
encountered_terms = {}
|
30
35
|
|
@@ -34,6 +39,40 @@ def log message
|
|
34
39
|
puts "[stepmod-utils] #{message}"
|
35
40
|
end
|
36
41
|
|
42
|
+
def term_special_category(bibdata)
|
43
|
+
case bibdata.part.to_i
|
44
|
+
when 41,42,43,44,45,46,47,51
|
45
|
+
true
|
46
|
+
when [56..112]
|
47
|
+
true
|
48
|
+
else
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def part_to_title(bibdata)
|
54
|
+
case bibdata.part.to_i
|
55
|
+
when 41
|
56
|
+
"Part 41"
|
57
|
+
when 42
|
58
|
+
"Geometric and topological representation"
|
59
|
+
when 43
|
60
|
+
"Foundation representation"
|
61
|
+
when 44
|
62
|
+
"Product structure, concept and configuration"
|
63
|
+
when 45
|
64
|
+
"Part 45"
|
65
|
+
when 46
|
66
|
+
"Visual presentation"
|
67
|
+
when 47
|
68
|
+
"Shape tolerance"
|
69
|
+
when 51
|
70
|
+
"Mathematical representation"
|
71
|
+
else
|
72
|
+
bibdata.title_en
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
37
76
|
stepmod_path = Pathname.new(stepmod_dir).realpath
|
38
77
|
|
39
78
|
# If we are using the stepmod CVS repository, provide the revision number per file
|
@@ -57,9 +96,14 @@ files = %w(
|
|
57
96
|
business_object_model.xml
|
58
97
|
module.xml
|
59
98
|
).inject([]) do |acc, t|
|
60
|
-
|
99
|
+
|
100
|
+
candidate_paths = Dir["#{stepmod_dir}/**/#{t}"]
|
101
|
+
acc << candidate_paths
|
102
|
+
|
61
103
|
end.flatten.sort.uniq
|
62
104
|
|
105
|
+
max_encountered_refs_indexes = {}
|
106
|
+
|
63
107
|
files.each do |file_path|
|
64
108
|
file_path = Pathname.new(file_path).realpath
|
65
109
|
fpath = file_path.relative_path_from(stepmod_path)
|
@@ -75,9 +119,8 @@ files.each do |file_path|
|
|
75
119
|
next
|
76
120
|
end
|
77
121
|
|
78
|
-
|
79
|
-
|
80
|
-
log "INFO: skipped #{bibdata.docid} as it is not IS, DIS or TS"
|
122
|
+
unless ACCEPTED_STAGES.include? bibdata.doctype
|
123
|
+
log "INFO: skipped #{bibdata.docid} as it is not one of (#{ACCEPTED_STAGES.join(", ")})."
|
81
124
|
next
|
82
125
|
end
|
83
126
|
|
@@ -106,8 +149,9 @@ files.each do |file_path|
|
|
106
149
|
end
|
107
150
|
|
108
151
|
# read definitions
|
109
|
-
|
110
|
-
|
152
|
+
part_concepts = []
|
153
|
+
current_document.xpath('//definition').each do |definition|
|
154
|
+
index = max_encountered_refs_indexes[bibdata.anchor] || 1
|
111
155
|
term_id = definition['id']
|
112
156
|
unless term_id.nil?
|
113
157
|
if encountered_terms[term_id]
|
@@ -126,25 +170,130 @@ files.each do |file_path|
|
|
126
170
|
reference_clause: ref_clause,
|
127
171
|
file_path: fpath + revision_string
|
128
172
|
)
|
173
|
+
next unless concept
|
174
|
+
|
175
|
+
unless term_special_category(bibdata)
|
176
|
+
# log "INFO: this part is generic"
|
177
|
+
general_concepts << concept
|
178
|
+
else
|
179
|
+
# log "INFO: this part is special"
|
180
|
+
part_concepts << concept
|
181
|
+
end
|
129
182
|
|
130
|
-
|
183
|
+
max_encountered_refs_indexes[bibdata.anchor] = index + 1
|
131
184
|
parsed_bibliography << bibdata
|
132
185
|
end
|
133
186
|
|
187
|
+
part_modules = []
|
188
|
+
current_document.xpath('//arm/uof').each do |uof_node|
|
189
|
+
concept = Stepmod::Utils::Concept.parse(
|
190
|
+
uof_node,
|
191
|
+
reference_anchor: bibdata.anchor,
|
192
|
+
reference_clause: nil,
|
193
|
+
file_path: fpath + revision_string
|
194
|
+
)
|
195
|
+
# puts concept.inspect
|
196
|
+
|
197
|
+
next unless concept
|
198
|
+
|
199
|
+
unless term_special_category(bibdata)
|
200
|
+
# log "INFO: this part is generic"
|
201
|
+
module_concepts << concept
|
202
|
+
else
|
203
|
+
# log "INFO: this part is special"
|
204
|
+
part_modules << concept
|
205
|
+
end
|
206
|
+
|
207
|
+
parsed_bibliography << bibdata
|
208
|
+
end
|
209
|
+
|
210
|
+
part_resources = []
|
211
|
+
# Assumption: every schema is only linked by a single resource_docs document.
|
212
|
+
current_document.xpath('//schema').each do |schema_node|
|
213
|
+
schema_name = schema_node['name']
|
214
|
+
|
215
|
+
Dir["#{stepmod_path}/*/#{schema_name}/descriptions.xml"].each do |description_xml_path|
|
216
|
+
log "INFO: Processing resources schema #{description_xml_path}"
|
217
|
+
description_document = Nokogiri::XML(File.read(description_xml_path)).root
|
218
|
+
description_document.xpath('//ext_description').each do |ext_description|
|
219
|
+
|
220
|
+
concept = Stepmod::Utils::Concept.parse(
|
221
|
+
ext_description,
|
222
|
+
reference_anchor: bibdata.anchor,
|
223
|
+
reference_clause: nil,
|
224
|
+
file_path: fpath + revision_string
|
225
|
+
)
|
226
|
+
next unless concept
|
227
|
+
|
228
|
+
unless term_special_category(bibdata)
|
229
|
+
# log "INFO: this part is generic"
|
230
|
+
resource_concepts << concept
|
231
|
+
else
|
232
|
+
# log "INFO: this part is special"
|
233
|
+
part_resources << concept
|
234
|
+
end
|
235
|
+
|
236
|
+
parsed_bibliography << bibdata
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
134
241
|
log "INFO: Completed processing XML file #{fpath}"
|
135
242
|
|
243
|
+
if part_concepts.empty?
|
244
|
+
log "INFO: Skipping #{fpath} (#{bibdata.docid}) because it contains no concepts."
|
245
|
+
next
|
246
|
+
elsif part_concepts.length < 3
|
247
|
+
log "INFO: Skipping #{fpath} (#{bibdata.docid}) because it only has #{part_concepts.length} terms."
|
248
|
+
|
249
|
+
part_concepts.each do |x|
|
250
|
+
general_concepts << x
|
251
|
+
end
|
252
|
+
else
|
253
|
+
fn = "03x-stepmod-#{bibdata.part}.adoc"
|
254
|
+
File.open(fn, 'w') { |file|
|
255
|
+
file.puts("== #{part_to_title(bibdata)}\n\n")
|
256
|
+
file.puts(part_concepts.map(&:to_mn_adoc).join("\n"))
|
257
|
+
}
|
258
|
+
log "INFO: written to: #{fn}"
|
259
|
+
end
|
260
|
+
|
261
|
+
unless part_resources.empty?
|
262
|
+
fn = "04x-stepmod-entities-resources-#{bibdata.part}.adoc"
|
263
|
+
File.open(fn, 'w') { |file|
|
264
|
+
file.puts("== #{part_to_title(bibdata)}\n\n")
|
265
|
+
file.puts(part_resources.map(&:to_mn_adoc).join("\n"))
|
266
|
+
}
|
267
|
+
log "INFO: written to: #{fn}"
|
268
|
+
end
|
269
|
+
|
270
|
+
unless part_modules.empty?
|
271
|
+
fn = "04x-stepmod-entities-modules-#{bibdata.part}.adoc"
|
272
|
+
File.open(fn, 'w') { |file|
|
273
|
+
file.puts("== #{part_to_title(bibdata)}\n\n")
|
274
|
+
file.puts(part_modules.map(&:to_mn_adoc).join("\n"))
|
275
|
+
}
|
276
|
+
log "INFO: written to: #{fn}"
|
277
|
+
end
|
278
|
+
|
136
279
|
end
|
137
280
|
|
138
|
-
|
281
|
+
File.open('031-stepmod-general.adoc', 'w') { |file|
|
282
|
+
file.puts(general_concepts.map(&:to_mn_adoc).join("\n"))
|
283
|
+
}
|
284
|
+
|
285
|
+
File.open('04-stepmod-entities-resources.adoc', 'w') { |file|
|
286
|
+
file.puts(resource_concepts.map(&:to_mn_adoc).join("\n"))
|
287
|
+
}
|
139
288
|
|
140
|
-
File.open('
|
141
|
-
file.puts(
|
289
|
+
File.open('05-stepmod-entities-modules.adoc', 'w') { |file|
|
290
|
+
file.puts(module_concepts.map(&:to_mn_adoc).join("\n"))
|
142
291
|
}
|
143
292
|
|
144
|
-
log "INFO: written to: 031-
|
293
|
+
log "INFO: written to: 031-stepmod-general.adoc"
|
145
294
|
|
146
295
|
File.open('991-generated-bibliography.adoc', 'w') { |file|
|
147
|
-
file.puts(parsed_bibliography.map(&:to_mn_adoc).join("\n"))
|
296
|
+
file.puts(parsed_bibliography.map(&:to_mn_adoc).sort.uniq.join("\n"))
|
148
297
|
}
|
149
298
|
|
150
299
|
log "INFO: written to: 991-generated-bibliography.adoc"
|
@@ -21,8 +21,21 @@ module Stepmod
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.parse(definition_xml, reference_anchor:, reference_clause:, file_path:)
|
24
|
+
converted_definition = Stepmod::Utils::StepmodDefinitionConverter
|
25
|
+
.convert(definition_xml, { reference_anchor: reference_anchor })
|
26
|
+
|
27
|
+
return nil if converted_definition.nil? || converted_definition.strip.empty?
|
28
|
+
|
29
|
+
if definition_xml.name == 'uof' || definition_xml.name == 'ext_description'
|
30
|
+
converted_definition = <<~TEXT
|
31
|
+
#{converted_definition.split("\n")[0..3].join("\n")}
|
32
|
+
|
33
|
+
NOTE: This term is incompletely defined in this document.
|
34
|
+
Reference <<#{reference_anchor}>> for the complete definition.
|
35
|
+
TEXT
|
36
|
+
end
|
24
37
|
new(
|
25
|
-
converted_definition:
|
38
|
+
converted_definition: converted_definition,
|
26
39
|
reference_anchor: reference_anchor,
|
27
40
|
reference_clause: reference_clause,
|
28
41
|
file_path: file_path
|
@@ -35,7 +48,7 @@ module Stepmod
|
|
35
48
|
#{converted_definition}
|
36
49
|
|
37
50
|
[.source]
|
38
|
-
<<#{reference_anchor},clause
|
51
|
+
<<#{reference_anchor}#{reference_clause ? ",clause=" + reference_clause : ""}>>
|
39
52
|
|
40
53
|
TEXT
|
41
54
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stepmod
|
4
|
+
module Utils
|
5
|
+
module Converters
|
6
|
+
class Arm < ReverseAdoc::Converters::Base
|
7
|
+
def convert(node, state = {})
|
8
|
+
treat_children(node, state)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def treat_children(node, state)
|
14
|
+
res = node.children.map { |child| treat(child, state) }
|
15
|
+
res.map(&:strip).reject(&:empty?).join("\n\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ReverseAdoc::Converters.register :arm, Arm.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -44,7 +44,7 @@ module Stepmod
|
|
44
44
|
first_strong_node.next.content = first_strong_node.next.content.gsub(/\s?:/, '')
|
45
45
|
term = first_strong_node.text.strip
|
46
46
|
first_strong_node.remove
|
47
|
-
"#{term}:: #{treat_children(cloned_node, state)}"
|
47
|
+
"\n\n#{term}:: #{remove_trash_symbols(treat_children(cloned_node, state))}\n"
|
48
48
|
end
|
49
49
|
|
50
50
|
def stem_converted(cloned_node, state)
|
@@ -69,6 +69,7 @@ module Stepmod
|
|
69
69
|
.strip
|
70
70
|
.gsub(/\(\d\)$/, '')
|
71
71
|
.gsub(/\b(\w*?[_]+\w+)\b/, '"\1"')
|
72
|
+
.gsub(/([^\s])\s+_{/, '\1_{')
|
72
73
|
.strip
|
73
74
|
end
|
74
75
|
|
@@ -79,14 +80,14 @@ module Stepmod
|
|
79
80
|
TAGS_NOT_IN_CONTEXT.each do |tag_name|
|
80
81
|
node
|
81
82
|
.children
|
82
|
-
.
|
83
|
-
|
84
|
-
|
83
|
+
.each do |n|
|
84
|
+
remove_tags_not_in_context(n) if n.children.length > 0
|
85
|
+
next if n.name != tag_name
|
86
|
+
|
87
|
+
n.add_previous_sibling(n.children)
|
88
|
+
n.unlink
|
85
89
|
end
|
86
90
|
end
|
87
|
-
node.traverse do |descendant|
|
88
|
-
descendant.content = descendant.content.gsub('#8195;', '')
|
89
|
-
end
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
@@ -8,18 +8,21 @@ module Stepmod
|
|
8
8
|
node.children.map do |child|
|
9
9
|
next unless child.name == 'imgfile'
|
10
10
|
|
11
|
-
parse_to_svg_reference(child['file'])
|
11
|
+
parse_to_svg_reference(child['file'], state)
|
12
12
|
end.join("\n")
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def parse_to_svg_reference(file)
|
17
|
+
def parse_to_svg_reference(file, state)
|
18
18
|
return '' unless File.file?(file)
|
19
19
|
|
20
20
|
image_document = Nokogiri::XML(File.read(file))
|
21
21
|
svg_path = File.basename(image_document.xpath('//img').first['src'], '.*')
|
22
22
|
<<~SVGMAP
|
23
|
+
|
24
|
+
*)
|
25
|
+
(*"#{state.fetch(:schema_name)}.__expressg"
|
23
26
|
[.svgmap]
|
24
27
|
====
|
25
28
|
image::#{svg_path}.svg[]
|
@@ -5,7 +5,13 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class FundCons < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
|
8
|
+
<<~TEXT
|
9
|
+
|
10
|
+
*)
|
11
|
+
(*"#{state.fetch(:schema_name)}.__fund_cons"
|
12
|
+
|
13
|
+
#{treat_children(node, state).strip}
|
14
|
+
TEXT
|
9
15
|
end
|
10
16
|
end
|
11
17
|
|
@@ -9,7 +9,7 @@ module Stepmod
|
|
9
9
|
anchor = id ? "[[#{id}]]\n" : ""
|
10
10
|
ol_count = state.fetch(:ol_count, 0) + 1
|
11
11
|
attrs = ol_attrs(node)
|
12
|
-
res = "\n\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count))}\n"
|
12
|
+
res = "\n\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count, tdsinglepara: true))}\n"
|
13
13
|
# Why do we add this?
|
14
14
|
# res = "\n" + res if node.parent && node.parent.name == 'note'
|
15
15
|
res
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Stepmod
|
2
|
+
module Utils
|
3
|
+
module Converters
|
4
|
+
class StepmodExtDescription < ReverseAdoc::Converters::Base
|
5
|
+
def convert(node, state = {})
|
6
|
+
state = state.merge(schema_name: node['linkend'])
|
7
|
+
linkend = node['linkend'].split('.')
|
8
|
+
|
9
|
+
# We ignore all the WHERE and IP rules because those are not terms
|
10
|
+
return nil if linkend.last =~ /^wr/
|
11
|
+
|
12
|
+
<<~TEMPLATE
|
13
|
+
=== #{node['linkend'].split('.').last}
|
14
|
+
|
15
|
+
<STEP resource> #{treat_children(node, state).strip}
|
16
|
+
TEMPLATE
|
17
|
+
end
|
18
|
+
end
|
19
|
+
ReverseAdoc::Converters.register :ext_description, StepmodExtDescription.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -4,13 +4,33 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Strong < ReverseAdoc::Converters::Base
|
7
|
+
BLANK_CHARS = "{blank}".freeze
|
8
|
+
|
7
9
|
def convert(node, state = {})
|
8
10
|
content = treat_children(node, state.merge(already_strong: true))
|
9
11
|
if content.strip.empty? || state[:already_strong]
|
10
12
|
content
|
11
13
|
else
|
12
|
-
"#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}"
|
14
|
+
handle_express_escape_seq(node, "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def handle_express_escape_seq(node, content)
|
21
|
+
res = content
|
22
|
+
if braces_sibling?(node.previous, true)
|
23
|
+
res = "#{BLANK_CHARS}#{res}"
|
24
|
+
end
|
25
|
+
if braces_sibling?(node.next)
|
26
|
+
res = "#{res}#{BLANK_CHARS}"
|
13
27
|
end
|
28
|
+
res
|
29
|
+
end
|
30
|
+
|
31
|
+
def braces_sibling?(sibling, end_of_text = false)
|
32
|
+
match = end_of_text ? /\($/ : /^\)/
|
33
|
+
sibling && sibling.text? && sibling.text =~ match
|
14
34
|
end
|
15
35
|
end
|
16
36
|
|
@@ -6,8 +6,16 @@ module Stepmod
|
|
6
6
|
class Sub < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
8
|
content = treat_children(node, state)
|
9
|
+
return stem_notation(content) if node.parent.name == 'eqn'
|
10
|
+
|
9
11
|
"#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
|
10
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def stem_notation(content)
|
17
|
+
"_{#{content}}"
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
ReverseAdoc::Converters.register :sub, Sub.new
|
@@ -6,8 +6,14 @@ module Stepmod
|
|
6
6
|
class Sup < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
8
|
content = treat_children(node, state)
|
9
|
+
return stem_notation(content) if node.parent.name == 'eqn'
|
10
|
+
|
9
11
|
"#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
|
10
12
|
end
|
13
|
+
|
14
|
+
def stem_notation(content)
|
15
|
+
"^{#{content}}"
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
ReverseAdoc::Converters.register :sup, Sup.new
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stepmod
|
4
|
+
module Utils
|
5
|
+
module Converters
|
6
|
+
class Table < ReverseAdoc::Converters::Base
|
7
|
+
def convert(node, state = {})
|
8
|
+
id = node['id']
|
9
|
+
anchor = id ? "[[#{id}]]\n" : ""
|
10
|
+
title = node['caption'].to_s
|
11
|
+
title = ".#{title}\n" unless title.empty?
|
12
|
+
attrs = style(node)
|
13
|
+
"\n\n#{anchor}#{attrs}#{title}|===\n#{treat_children(node, state)}\n|===\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def frame(node)
|
17
|
+
case node["frame"]
|
18
|
+
when "void"
|
19
|
+
"frame=none"
|
20
|
+
when "hsides"
|
21
|
+
"frame=topbot"
|
22
|
+
when "vsides"
|
23
|
+
"frame=sides"
|
24
|
+
when "box", "border"
|
25
|
+
"frame=all"
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def rules(node)
|
32
|
+
case node["rules"]
|
33
|
+
when "all"
|
34
|
+
"rules=all"
|
35
|
+
when "rows"
|
36
|
+
"rules=rows"
|
37
|
+
when "cols"
|
38
|
+
"rules=cols"
|
39
|
+
when "none"
|
40
|
+
"rules=none"
|
41
|
+
else
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def style(node)
|
47
|
+
width = "width=#{node['width']}" if node['width']
|
48
|
+
attrs = []
|
49
|
+
frame_attr = frame(node)
|
50
|
+
rules_attr = rules(node)
|
51
|
+
attrs += width if width
|
52
|
+
attrs += frame_attr if frame_attr
|
53
|
+
attrs += rules_attr if rules_attr
|
54
|
+
return "" if attrs.empty?
|
55
|
+
"[#{attrs.join(',')}]\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
ReverseAdoc::Converters.register :table, Table.new
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stepmod/utils/converters/synonym'
|
4
|
+
|
5
|
+
module Stepmod
|
6
|
+
module Utils
|
7
|
+
module Converters
|
8
|
+
class Uof < ReverseAdoc::Converters::Base
|
9
|
+
def convert(node, state = {})
|
10
|
+
<<~TEXT
|
11
|
+
=== #{node['name'].strip}
|
12
|
+
|
13
|
+
<STEP module> #{treat_children(node, state).strip}
|
14
|
+
TEXT
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
ReverseAdoc::Converters.register :uof, Uof.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -32,13 +32,13 @@ require 'stepmod/utils/converters/schema'
|
|
32
32
|
require 'stepmod/utils/converters/strong'
|
33
33
|
require 'stepmod/utils/converters/sub'
|
34
34
|
require 'stepmod/utils/converters/sup'
|
35
|
+
require 'stepmod/utils/converters/table'
|
35
36
|
require 'stepmod/utils/converters/text'
|
36
37
|
require 'stepmod/utils/cleaner'
|
37
38
|
|
38
39
|
require 'reverse_adoc/converters/figure'
|
39
40
|
require 'reverse_adoc/converters/img'
|
40
41
|
require 'reverse_adoc/converters/li'
|
41
|
-
require 'reverse_adoc/converters/table'
|
42
42
|
require 'reverse_adoc/converters/tr'
|
43
43
|
require 'reverse_adoc/converters/td'
|
44
44
|
require 'reverse_adoc/converters/th'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'reverse_adoc'
|
4
|
+
require 'stepmod/utils/converters/arm'
|
4
5
|
require 'stepmod/utils/converters/clause_ref'
|
5
6
|
require 'stepmod/utils/converters/express_ref'
|
6
7
|
require 'stepmod/utils/converters/module_ref'
|
@@ -11,8 +12,10 @@ require 'stepmod/utils/converters/example'
|
|
11
12
|
require 'stepmod/utils/converters/note'
|
12
13
|
require 'stepmod/utils/converters/ol'
|
13
14
|
require 'stepmod/utils/converters/stem'
|
15
|
+
require 'stepmod/utils/converters/stepmod_ext_description'
|
14
16
|
require 'stepmod/utils/converters/term'
|
15
17
|
require 'stepmod/utils/converters/synonym'
|
18
|
+
require 'stepmod/utils/converters/uof'
|
16
19
|
|
17
20
|
require 'reverse_adoc/converters/a'
|
18
21
|
require 'reverse_adoc/converters/blockquote'
|
@@ -37,19 +40,21 @@ module Stepmod
|
|
37
40
|
module Utils
|
38
41
|
class StepmodDefinitionConverter
|
39
42
|
def self.convert(input, options = {})
|
40
|
-
root =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
root = case input
|
44
|
+
when String
|
45
|
+
Nokogiri::XML(input).root
|
46
|
+
when Nokogiri::XML::Document
|
47
|
+
input.root
|
48
|
+
when Nokogiri::XML::Node
|
49
|
+
input
|
50
|
+
end
|
47
51
|
|
48
|
-
|
52
|
+
return '' unless root
|
49
53
|
|
50
54
|
ReverseAdoc.config.with(options) do
|
51
55
|
result = ReverseAdoc::Converters.lookup(root.name).convert(root)
|
52
|
-
|
56
|
+
return '' unless result
|
57
|
+
ReverseAdoc.cleaner.tidy(result.dup)
|
53
58
|
end
|
54
59
|
end
|
55
60
|
end
|
@@ -24,31 +24,55 @@ module Stepmod
|
|
24
24
|
|
25
25
|
if File.exists?(descriptions_file)
|
26
26
|
descriptions = Nokogiri::XML(File.read(descriptions_file)).root
|
27
|
+
added_resource_descriptions = {}
|
27
28
|
descriptions.xpath('ext_description').each do |description|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# remark is empty, fallback to resource_docs_cache
|
35
|
-
resource_docs_dir = resource_docs_cache[description['linkend']]
|
36
|
-
if resource_docs_dir
|
37
|
-
resource_docs_file = File.join(stepmod_dir, 'data/resource_docs', resource_docs_dir, 'resource.xml')
|
38
|
-
resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
|
39
|
-
schema = resource_docs.xpath("schema[@name='#{description['linkend']}']")
|
40
|
-
|
41
|
-
Dir.chdir(File.dirname(descriptions_file)) do
|
42
|
-
wrapper = "<resource>#{schema.to_s}</resource>"
|
43
|
-
output_express << "\n" + Stepmod::Utils::SmrlResourceConverter.convert(wrapper)
|
44
|
-
end
|
29
|
+
# Add base resource from linked path if exists, eg "language_schema.language.wr:WR1" -> "language_schema"
|
30
|
+
base_linked = description['linkend'].to_s.split('.').first
|
31
|
+
if added_resource_descriptions[base_linked].nil?
|
32
|
+
base_reource_doc_dir = resource_docs_cache[description['linkend'].to_s.split('.').first]
|
33
|
+
if base_reource_doc_dir
|
34
|
+
output_express << convert_from_resource_file(base_reource_doc_dir, stepmod_dir, base_linked, descriptions_file)
|
45
35
|
end
|
36
|
+
added_resource_descriptions[base_linked] = true
|
37
|
+
end
|
38
|
+
resource_docs_dir = resource_docs_cache[description['linkend']]
|
39
|
+
# Convert content description
|
40
|
+
# when a schema description is available from resource.xml and also descriptions.xml, the description from resource.xml is only used.
|
41
|
+
# https://github.com/metanorma/annotated-express/issues/32#issuecomment-792609078
|
42
|
+
if description.text.strip.length.positive? && resource_docs_dir.nil?
|
43
|
+
output_express << convert_from_description_text(descriptions_file, description)
|
44
|
+
end
|
45
|
+
# Add converted description from exact linked path
|
46
|
+
if resource_docs_dir && added_resource_descriptions[description['linkend']].nil?
|
47
|
+
output_express << convert_from_resource_file(resource_docs_dir, stepmod_dir, description['linkend'], descriptions_file)
|
48
|
+
added_resource_descriptions[description['linkend']] = true
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
53
|
output_express
|
51
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def convert_from_description_text(descriptions_file, description)
|
59
|
+
Dir.chdir(File.dirname(descriptions_file)) do
|
60
|
+
wrapper = "<ext_descriptions>#{description.to_s}</ext_descriptions>"
|
61
|
+
"\n" + Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def convert_from_resource_file(resource_docs_dir, stepmod_dir, linked, descriptions_file)
|
66
|
+
resource_docs_file = File.join(stepmod_dir, 'data/resource_docs', resource_docs_dir, 'resource.xml')
|
67
|
+
puts(resource_docs_file)
|
68
|
+
resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
|
69
|
+
schema = resource_docs.xpath("schema[@name='#{linked}']")
|
70
|
+
|
71
|
+
Dir.chdir(File.dirname(descriptions_file)) do
|
72
|
+
wrapper = "<resource>#{schema.to_s}</resource>"
|
73
|
+
"\n" + Stepmod::Utils::SmrlResourceConverter.convert(wrapper)
|
74
|
+
end
|
75
|
+
end
|
52
76
|
end
|
53
77
|
end
|
54
78
|
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.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -82,11 +82,10 @@ dependencies:
|
|
82
82
|
version: '11.1'
|
83
83
|
description: 'Stepmod-utils is a toolkit that works on STEPmod data.
|
84
84
|
|
85
|
-
'
|
85
|
+
'
|
86
86
|
email:
|
87
87
|
- open.source@ribose.com
|
88
88
|
executables:
|
89
|
-
- stepmod-annotate
|
90
89
|
- stepmod-annotate-all
|
91
90
|
- stepmod-build-resource-docs-cache
|
92
91
|
- stepmod-convert-express-description
|
@@ -107,7 +106,6 @@ files:
|
|
107
106
|
- Rakefile
|
108
107
|
- bin/console
|
109
108
|
- bin/setup
|
110
|
-
- exe/stepmod-annotate
|
111
109
|
- exe/stepmod-annotate-all
|
112
110
|
- exe/stepmod-build-resource-docs-cache
|
113
111
|
- exe/stepmod-convert-express-description
|
@@ -119,6 +117,7 @@ files:
|
|
119
117
|
- lib/stepmod/utils/cleaner.rb
|
120
118
|
- lib/stepmod/utils/concept.rb
|
121
119
|
- lib/stepmod/utils/converters/a.rb
|
120
|
+
- lib/stepmod/utils/converters/arm.rb
|
122
121
|
- lib/stepmod/utils/converters/blockquote.rb
|
123
122
|
- lib/stepmod/utils/converters/br.rb
|
124
123
|
- lib/stepmod/utils/converters/bypass.rb
|
@@ -155,12 +154,15 @@ files:
|
|
155
154
|
- lib/stepmod/utils/converters/schema.rb
|
156
155
|
- lib/stepmod/utils/converters/schema_diag.rb
|
157
156
|
- lib/stepmod/utils/converters/stem.rb
|
157
|
+
- lib/stepmod/utils/converters/stepmod_ext_description.rb
|
158
158
|
- lib/stepmod/utils/converters/strong.rb
|
159
159
|
- lib/stepmod/utils/converters/sub.rb
|
160
160
|
- lib/stepmod/utils/converters/sup.rb
|
161
161
|
- lib/stepmod/utils/converters/synonym.rb
|
162
|
+
- lib/stepmod/utils/converters/table.rb
|
162
163
|
- lib/stepmod/utils/converters/term.rb
|
163
164
|
- lib/stepmod/utils/converters/text.rb
|
165
|
+
- lib/stepmod/utils/converters/uof.rb
|
164
166
|
- lib/stepmod/utils/html_to_asciimath.rb
|
165
167
|
- lib/stepmod/utils/smrl_description_converter.rb
|
166
168
|
- lib/stepmod/utils/smrl_resource_converter.rb
|
@@ -174,7 +176,7 @@ homepage: https://github.com/metanorma/stepmod-utils
|
|
174
176
|
licenses:
|
175
177
|
- BSD-2-Clause
|
176
178
|
metadata: {}
|
177
|
-
post_install_message:
|
179
|
+
post_install_message:
|
178
180
|
rdoc_options: []
|
179
181
|
require_paths:
|
180
182
|
- lib
|
@@ -190,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
192
|
version: '0'
|
191
193
|
requirements: []
|
192
194
|
rubygems_version: 3.0.3
|
193
|
-
signing_key:
|
195
|
+
signing_key:
|
194
196
|
specification_version: 4
|
195
197
|
summary: Stepmod-utils is a toolkit that works on STEPmod data.
|
196
198
|
test_files: []
|
data/exe/stepmod-annotate
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
require 'stepmod/utils/smrl_description_converter'
|
5
|
-
require 'stepmod/utils/smrl_resource_converter'
|
6
|
-
|
7
|
-
express_file = ARGV.shift
|
8
|
-
resource_docs_cache_file = ARGV.shift # output of ./stepmod-build-resource-docs-cache
|
9
|
-
stepmod_dir = ARGV.first || Dir.pwd
|
10
|
-
|
11
|
-
match = File.basename(express_file).match('^(arm|mim|bom)\.exp$')
|
12
|
-
descriptions_base = match ? "#{match.captures[0]}_descriptions.xml" : 'descriptions.xml'
|
13
|
-
descriptions_file = File.join(File.dirname(express_file), descriptions_base)
|
14
|
-
|
15
|
-
output_express = File.read(express_file)
|
16
|
-
|
17
|
-
resource_docs_cache = JSON.parse(File.read(resource_docs_cache_file))
|
18
|
-
|
19
|
-
if File.exists?(descriptions_file)
|
20
|
-
descriptions = Nokogiri::XML(File.read(descriptions_file)).root
|
21
|
-
descriptions.xpath('ext_description').each do |description|
|
22
|
-
unless description.text.strip.empty? then
|
23
|
-
Dir.chdir(File.dirname(descriptions_file)) do
|
24
|
-
wrapper = "<ext_descriptions>#{description.to_s}</ext_descriptions>"
|
25
|
-
output_express << "\n" + Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)
|
26
|
-
end
|
27
|
-
else
|
28
|
-
# remark is empty, fallback to resource_docs_cache
|
29
|
-
resource_docs_dir = resource_docs_cache[description['linkend']]
|
30
|
-
if resource_docs_dir
|
31
|
-
resource_docs_file = File.join(stepmod_dir, 'data/resource_docs', resource_docs_dir, 'resource.xml')
|
32
|
-
resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
|
33
|
-
schema = resource_docs.xpath("schema[@name='#{description['linkend']}']")
|
34
|
-
|
35
|
-
Dir.chdir(File.dirname(descriptions_file)) do
|
36
|
-
wrapper = "<resource>#{schema.to_s}</resource>"
|
37
|
-
output_express << "\n" + Stepmod::Utils::SmrlResourceConverter.convert(wrapper)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
puts output_express
|