stepmod-utils 0.2.5 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d3544c6e6b2eca6cab5ab08050b9985b80f62d597604d6961cbb388a712160a
4
- data.tar.gz: 6afde6fbd52b996a37a6d8bc88607adf97b760c0835d7eae5cee849a8911d8cb
3
+ metadata.gz: fcb84433f081424b5227cdb8c9c6b7d7342d31089e176f8f333817c4533c721d
4
+ data.tar.gz: 82fee2a54cc8d818587c2c9b08e955d1328497f05362307f528b968f1a576f61
5
5
  SHA512:
6
- metadata.gz: c5631d5e7587e4d26d62425f623433147ad372f4f53ebc5d9f2e0c1414d0b84599b6655d242028fbc4df872637b2db2a23df31b905ddd48136a9add7de4d0a9b
7
- data.tar.gz: d48868104b0fd44e74ec8459f9d45e1ed51b835b749bc3986c185c376d798ecb28da0d2a1813ebeb9faacc9e1432a0117adaa5101ade901e965424a101903bcc
6
+ metadata.gz: 4840fc050b58a4eda03c0c7106d7af524c7d3f863d5a40907facf6e6393ddf26d60a00852478df1ccadc2568b20616139251bb5fd4f4fcdb37296a8bfc5a94cb
7
+ data.tar.gz: f3a7b2d85581e1f5db195bef23b28422a82dd8588b66c66df2147700ccebc6b15c96b3b2b696cfb0435e2a6cdedf02579b542bd1af77efd6c1afd608a61593ca
@@ -24,7 +24,12 @@ require 'ptools'
24
24
 
25
25
  ReverseAdoc.config.unknown_tags = :bypass
26
26
 
27
- parsed_terms = []
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
- acc << Dir["#{stepmod_dir}/**/#{t}"]
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
- # TODO: we may want a command line option to override this in the future
79
- unless %w(IS DIS TS).include? bibdata.doctype
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
- current_document.xpath('//definition').each.with_index(1) do |definition, index|
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
- parsed_terms << concept
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
- parsed_bibliography.uniq!
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('031-generated-terms.adoc', 'w') { |file|
141
- file.puts(parsed_terms.map(&:to_mn_adoc).join("\n"))
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-generated-terms.adoc"
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"
@@ -67,6 +67,8 @@ module Stepmod
67
67
  "ISO/CD #{DOCNUMBER}-#{part}"
68
68
  when "DIS"
69
69
  "ISO/DIS #{DOCNUMBER}-#{part}"
70
+ when "FDIS"
71
+ "ISO/FDIS #{DOCNUMBER}-#{part}"
70
72
  when "TS"
71
73
  "ISO/TS #{DOCNUMBER}-#{part}"
72
74
  when "CD-TS"
@@ -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: Stepmod::Utils::StepmodDefinitionConverter.convert(definition_xml),
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=#{reference_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
@@ -71,6 +71,7 @@ module Stepmod
71
71
  end
72
72
 
73
73
  ReverseAdoc::Converters.register :def, Def.new
74
+ ReverseAdoc::Converters.register :description, Def.new
74
75
  end
75
76
  end
76
77
  end
@@ -20,8 +20,8 @@ module Stepmod
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
23
 
24
+ *)
25
25
  (*"#{state.fetch(:schema_name)}.__expressg"
26
26
  [.svgmap]
27
27
  ====
@@ -6,8 +6,8 @@ module Stepmod
6
6
  class FundCons < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
8
  <<~TEXT
9
- *)
10
9
 
10
+ *)
11
11
  (*"#{state.fetch(:schema_name)}.__fund_cons"
12
12
 
13
13
  #{treat_children(node, state).strip}
@@ -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 = if input.is_a?(String)
41
- then Nokogiri::XML(input).root
42
- elsif input.is_a?(Nokogiri::XML::Document)
43
- then input.root
44
- elsif input.is_a?(Nokogiri::XML::Node)
45
- then input
46
- end
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
- root || (return '')
52
+ return '' unless root
49
53
 
50
54
  ReverseAdoc.config.with(options) do
51
55
  result = ReverseAdoc::Converters.lookup(root.name).convert(root)
52
- ReverseAdoc.cleaner.tidy(result)
56
+ return '' unless result
57
+ ReverseAdoc.cleaner.tidy(result.dup)
53
58
  end
54
59
  end
55
60
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.2.5"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  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.5
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-03 00:00:00.000000000 Z
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.1.6
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.