stepmod-utils 0.2.3 → 0.3.0
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 +140 -13
- data/lib/stepmod/utils/bibdata.rb +2 -0
- data/lib/stepmod/utils/concept.rb +12 -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 +17 -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 +3 -0
- data/lib/stepmod/utils/stepmod_file_annotator.rb +41 -17
- data/lib/stepmod/utils/version.rb +1 -1
- data/stepmod-utils.gemspec +1 -0
- metadata +24 -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: 1006db3b3828bc38932f36a4f410cf6f8a0d5669bf0c3357c7a204c84e587a44
|
|
4
|
+
data.tar.gz: 7fa819c6ee34eef23ad8ab20fd3a833296a36bf99ca48cb624a81a04049871ff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40f09784e7aeac5e8e35c24079e84c5119dc9cd00f9555a4c24c1ce389e4b28bb32e0f6ec8c4408b3a1fea0445cfa16ca3700a263517b28c935c9ddca7de8cbb
|
|
7
|
+
data.tar.gz: dd35cce57f836527e31a6bd36576f6966494f558d1a0cc87486632c3149b1eecf66f37493f188f0a1ff685b804ddedb33bc13c1c6d45e5142335710ea7dea88c
|
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]
|
|
@@ -127,24 +171,107 @@ files.each do |file_path|
|
|
|
127
171
|
file_path: fpath + revision_string
|
|
128
172
|
)
|
|
129
173
|
|
|
130
|
-
|
|
174
|
+
unless term_special_category(bibdata)
|
|
175
|
+
# log "INFO: this part is generic"
|
|
176
|
+
general_concepts << concept
|
|
177
|
+
else
|
|
178
|
+
# log "INFO: this part is special"
|
|
179
|
+
part_concepts << concept
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
max_encountered_refs_indexes[bibdata.anchor] = index + 1
|
|
131
183
|
parsed_bibliography << bibdata
|
|
132
184
|
end
|
|
133
185
|
|
|
186
|
+
current_document.xpath('//arm').each do |arm_node|
|
|
187
|
+
index = max_encountered_refs_indexes[bibdata.anchor] || 1
|
|
188
|
+
|
|
189
|
+
concept = Stepmod::Utils::Concept.parse(
|
|
190
|
+
arm_node,
|
|
191
|
+
reference_anchor: bibdata.anchor,
|
|
192
|
+
reference_clause: nil,
|
|
193
|
+
file_path: fpath + revision_string
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
module_concepts << concept
|
|
197
|
+
# unless term_special_category(bibdata)
|
|
198
|
+
# # log "INFO: this part is generic"
|
|
199
|
+
# general_concepts << concept
|
|
200
|
+
# else
|
|
201
|
+
# # log "INFO: this part is special"
|
|
202
|
+
# part_concepts << concept
|
|
203
|
+
# end
|
|
204
|
+
|
|
205
|
+
max_encountered_refs_indexes[bibdata.anchor] = index + 1
|
|
206
|
+
parsed_bibliography << bibdata
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
current_document.xpath('//schema').each do |schema_node|
|
|
210
|
+
Dir["#{stepmod_dir}/**/#{schema_node['name']}/descriptions.xml"].each do |description|
|
|
211
|
+
description_document = Nokogiri::XML(File.read(description)).root
|
|
212
|
+
description_document.xpath('//ext_description').each do |ext_description|
|
|
213
|
+
index = max_encountered_refs_indexes[bibdata.anchor] || 1
|
|
214
|
+
|
|
215
|
+
concept = Stepmod::Utils::Concept.parse(
|
|
216
|
+
ext_description,
|
|
217
|
+
reference_anchor: bibdata.anchor,
|
|
218
|
+
reference_clause: nil,
|
|
219
|
+
file_path: fpath + revision_string
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
resource_concepts << concept
|
|
223
|
+
# unless term_special_category(bibdata)
|
|
224
|
+
# # log "INFO: this part is generic"
|
|
225
|
+
# general_concepts << concept
|
|
226
|
+
# else
|
|
227
|
+
# # log "INFO: this part is special"
|
|
228
|
+
# part_concepts << concept
|
|
229
|
+
# end
|
|
230
|
+
|
|
231
|
+
max_encountered_refs_indexes[bibdata.anchor] = index + 1
|
|
232
|
+
parsed_bibliography << bibdata
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
134
237
|
log "INFO: Completed processing XML file #{fpath}"
|
|
135
238
|
|
|
239
|
+
if part_concepts.length == 0
|
|
240
|
+
log "INFO: Skipping #{fpath} (#{bibdata.docid}) because it contains no concepts."
|
|
241
|
+
next
|
|
242
|
+
elsif part_concepts.length < 3
|
|
243
|
+
log "INFO: Skipping #{fpath} (#{bibdata.docid}) because it only has #{part_concepts.length} terms."
|
|
244
|
+
|
|
245
|
+
part_concepts.each do |x|
|
|
246
|
+
general_concepts << x
|
|
247
|
+
end
|
|
248
|
+
else
|
|
249
|
+
fn = "03x-stepmod-#{bibdata.part}.adoc"
|
|
250
|
+
File.open(fn, 'w') { |file|
|
|
251
|
+
file.puts("== #{part_to_title(bibdata)}\n\n")
|
|
252
|
+
file.puts(part_concepts.map(&:to_mn_adoc).join("\n"))
|
|
253
|
+
}
|
|
254
|
+
log "INFO: written to: #{fn}"
|
|
255
|
+
end
|
|
256
|
+
|
|
136
257
|
end
|
|
137
258
|
|
|
138
|
-
|
|
259
|
+
File.open('031-stepmod-general.adoc', 'w') { |file|
|
|
260
|
+
file.puts(general_concepts.map(&:to_mn_adoc).join("\n"))
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
File.open('04-stepmod-entities-resources.adoc', 'w') { |file|
|
|
264
|
+
file.puts(resource_concepts.map(&:to_mn_adoc).join("\n"))
|
|
265
|
+
}
|
|
139
266
|
|
|
140
|
-
File.open('
|
|
141
|
-
file.puts(
|
|
267
|
+
File.open('05-stepmod-entities-modules.adoc', 'w') { |file|
|
|
268
|
+
file.puts(module_concepts.map(&:to_mn_adoc).join("\n"))
|
|
142
269
|
}
|
|
143
270
|
|
|
144
|
-
log "INFO: written to: 031-
|
|
271
|
+
log "INFO: written to: 031-stepmod-general.adoc"
|
|
145
272
|
|
|
146
273
|
File.open('991-generated-bibliography.adoc', 'w') { |file|
|
|
147
|
-
file.puts(parsed_bibliography.map(&:to_mn_adoc).join("\n"))
|
|
274
|
+
file.puts(parsed_bibliography.map(&:to_mn_adoc).sort.uniq.join("\n"))
|
|
148
275
|
}
|
|
149
276
|
|
|
150
277
|
log "INFO: written to: 991-generated-bibliography.adoc"
|
|
@@ -21,8 +21,18 @@ 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
|
+
if definition_xml.name == 'arm' || definition_xml.name == 'ext_description'
|
|
27
|
+
converted_definition = <<~TEXT
|
|
28
|
+
#{converted_definition.split("\n")[0..3].join("\n")}
|
|
29
|
+
|
|
30
|
+
NOTE: This term is incompletely defined in this document.
|
|
31
|
+
Reference <<#{reference_anchor}>> for the complete definition.
|
|
32
|
+
TEXT
|
|
33
|
+
end
|
|
24
34
|
new(
|
|
25
|
-
converted_definition:
|
|
35
|
+
converted_definition: converted_definition,
|
|
26
36
|
reference_anchor: reference_anchor,
|
|
27
37
|
reference_clause: reference_clause,
|
|
28
38
|
file_path: file_path
|
|
@@ -35,7 +45,7 @@ module Stepmod
|
|
|
35
45
|
#{converted_definition}
|
|
36
46
|
|
|
37
47
|
[.source]
|
|
38
|
-
<<#{reference_anchor},clause
|
|
48
|
+
<<#{reference_anchor}#{reference_clause ? ",clause=" + reference_clause : ""}>>
|
|
39
49
|
|
|
40
50
|
TEXT
|
|
41
51
|
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,17 @@
|
|
|
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
|
+
<<~TEMPLATE
|
|
8
|
+
=== #{node['linkend'].split('.').last}
|
|
9
|
+
|
|
10
|
+
<STEP resource> #{treat_children(node, state).strip}
|
|
11
|
+
TEMPLATE
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
ReverseAdoc::Converters.register :ext_description, StepmodExtDescription.new
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
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'
|
|
@@ -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
|
data/stepmod-utils.gemspec
CHANGED
|
@@ -32,5 +32,6 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
spec.add_runtime_dependency "thor", ">= 0.20.3"
|
|
33
33
|
spec.add_runtime_dependency "reverse_adoc", ">= 0.2.9"
|
|
34
34
|
spec.add_runtime_dependency "ptools", '~> 1.3'
|
|
35
|
+
spec.add_runtime_dependency "concurrent-ruby"
|
|
35
36
|
spec.add_development_dependency "byebug", "~> 11.1"
|
|
36
37
|
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.0
|
|
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
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '1.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: concurrent-ruby
|
|
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'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: byebug
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -68,11 +82,10 @@ dependencies:
|
|
|
68
82
|
version: '11.1'
|
|
69
83
|
description: 'Stepmod-utils is a toolkit that works on STEPmod data.
|
|
70
84
|
|
|
71
|
-
'
|
|
85
|
+
'
|
|
72
86
|
email:
|
|
73
87
|
- open.source@ribose.com
|
|
74
88
|
executables:
|
|
75
|
-
- stepmod-annotate
|
|
76
89
|
- stepmod-annotate-all
|
|
77
90
|
- stepmod-build-resource-docs-cache
|
|
78
91
|
- stepmod-convert-express-description
|
|
@@ -93,7 +106,6 @@ files:
|
|
|
93
106
|
- Rakefile
|
|
94
107
|
- bin/console
|
|
95
108
|
- bin/setup
|
|
96
|
-
- exe/stepmod-annotate
|
|
97
109
|
- exe/stepmod-annotate-all
|
|
98
110
|
- exe/stepmod-build-resource-docs-cache
|
|
99
111
|
- exe/stepmod-convert-express-description
|
|
@@ -105,6 +117,7 @@ files:
|
|
|
105
117
|
- lib/stepmod/utils/cleaner.rb
|
|
106
118
|
- lib/stepmod/utils/concept.rb
|
|
107
119
|
- lib/stepmod/utils/converters/a.rb
|
|
120
|
+
- lib/stepmod/utils/converters/arm.rb
|
|
108
121
|
- lib/stepmod/utils/converters/blockquote.rb
|
|
109
122
|
- lib/stepmod/utils/converters/br.rb
|
|
110
123
|
- lib/stepmod/utils/converters/bypass.rb
|
|
@@ -141,12 +154,15 @@ files:
|
|
|
141
154
|
- lib/stepmod/utils/converters/schema.rb
|
|
142
155
|
- lib/stepmod/utils/converters/schema_diag.rb
|
|
143
156
|
- lib/stepmod/utils/converters/stem.rb
|
|
157
|
+
- lib/stepmod/utils/converters/stepmod_ext_description.rb
|
|
144
158
|
- lib/stepmod/utils/converters/strong.rb
|
|
145
159
|
- lib/stepmod/utils/converters/sub.rb
|
|
146
160
|
- lib/stepmod/utils/converters/sup.rb
|
|
147
161
|
- lib/stepmod/utils/converters/synonym.rb
|
|
162
|
+
- lib/stepmod/utils/converters/table.rb
|
|
148
163
|
- lib/stepmod/utils/converters/term.rb
|
|
149
164
|
- lib/stepmod/utils/converters/text.rb
|
|
165
|
+
- lib/stepmod/utils/converters/uof.rb
|
|
150
166
|
- lib/stepmod/utils/html_to_asciimath.rb
|
|
151
167
|
- lib/stepmod/utils/smrl_description_converter.rb
|
|
152
168
|
- lib/stepmod/utils/smrl_resource_converter.rb
|
|
@@ -160,7 +176,7 @@ homepage: https://github.com/metanorma/stepmod-utils
|
|
|
160
176
|
licenses:
|
|
161
177
|
- BSD-2-Clause
|
|
162
178
|
metadata: {}
|
|
163
|
-
post_install_message:
|
|
179
|
+
post_install_message:
|
|
164
180
|
rdoc_options: []
|
|
165
181
|
require_paths:
|
|
166
182
|
- lib
|
|
@@ -176,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
176
192
|
version: '0'
|
|
177
193
|
requirements: []
|
|
178
194
|
rubygems_version: 3.0.3
|
|
179
|
-
signing_key:
|
|
195
|
+
signing_key:
|
|
180
196
|
specification_version: 4
|
|
181
197
|
summary: Stepmod-utils is a toolkit that works on STEPmod data.
|
|
182
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
|