stepmod-utils 0.2.5 → 0.3.2
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/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/express_g.rb +1 -1
- data/lib/stepmod/utils/converters/fund_cons.rb +1 -1
- data/lib/stepmod/utils/converters/stepmod_ext_description.rb +22 -0
- data/lib/stepmod/utils/converters/uof.rb +21 -0
- data/lib/stepmod/utils/stepmod_definition_converter.rb +14 -9
- data/lib/stepmod/utils/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcb84433f081424b5227cdb8c9c6b7d7342d31089e176f8f333817c4533c721d
|
4
|
+
data.tar.gz: 82fee2a54cc8d818587c2c9b08e955d1328497f05362307f528b968f1a576f61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4840fc050b58a4eda03c0c7106d7af524c7d3f863d5a40907facf6e6393ddf26d60a00852478df1ccadc2568b20616139251bb5fd4f4fcdb37296a8bfc5a94cb
|
7
|
+
data.tar.gz: f3a7b2d85581e1f5db195bef23b28422a82dd8588b66c66df2147700ccebc6b15c96b3b2b696cfb0435e2a6cdedf02579b542bd1af77efd6c1afd608a61593ca
|
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('041-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('051-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
|
@@ -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
|
@@ -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
|
@@ -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
|
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.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/stepmod/utils/cleaner.rb
|
118
118
|
- lib/stepmod/utils/concept.rb
|
119
119
|
- lib/stepmod/utils/converters/a.rb
|
120
|
+
- lib/stepmod/utils/converters/arm.rb
|
120
121
|
- lib/stepmod/utils/converters/blockquote.rb
|
121
122
|
- lib/stepmod/utils/converters/br.rb
|
122
123
|
- lib/stepmod/utils/converters/bypass.rb
|
@@ -153,6 +154,7 @@ files:
|
|
153
154
|
- lib/stepmod/utils/converters/schema.rb
|
154
155
|
- lib/stepmod/utils/converters/schema_diag.rb
|
155
156
|
- lib/stepmod/utils/converters/stem.rb
|
157
|
+
- lib/stepmod/utils/converters/stepmod_ext_description.rb
|
156
158
|
- lib/stepmod/utils/converters/strong.rb
|
157
159
|
- lib/stepmod/utils/converters/sub.rb
|
158
160
|
- lib/stepmod/utils/converters/sup.rb
|
@@ -160,6 +162,7 @@ files:
|
|
160
162
|
- lib/stepmod/utils/converters/table.rb
|
161
163
|
- lib/stepmod/utils/converters/term.rb
|
162
164
|
- lib/stepmod/utils/converters/text.rb
|
165
|
+
- lib/stepmod/utils/converters/uof.rb
|
163
166
|
- lib/stepmod/utils/html_to_asciimath.rb
|
164
167
|
- lib/stepmod/utils/smrl_description_converter.rb
|
165
168
|
- lib/stepmod/utils/smrl_resource_converter.rb
|
@@ -188,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
191
|
- !ruby/object:Gem::Version
|
189
192
|
version: '0'
|
190
193
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
194
|
+
rubygems_version: 3.0.3
|
192
195
|
signing_key:
|
193
196
|
specification_version: 4
|
194
197
|
summary: Stepmod-utils is a toolkit that works on STEPmod data.
|