stepmod-utils 0.3.0 → 0.3.1

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: 1006db3b3828bc38932f36a4f410cf6f8a0d5669bf0c3357c7a204c84e587a44
4
- data.tar.gz: 7fa819c6ee34eef23ad8ab20fd3a833296a36bf99ca48cb624a81a04049871ff
3
+ metadata.gz: a0bf29e9cab4e7f1564993380efa536e105ad6f7aa54612b242d1bd993a4b06f
4
+ data.tar.gz: 68bae8817c50a70a89fb1b159e0b600ced160435ff45c75f6af063eb6a640c6f
5
5
  SHA512:
6
- metadata.gz: 40f09784e7aeac5e8e35c24079e84c5119dc9cd00f9555a4c24c1ce389e4b28bb32e0f6ec8c4408b3a1fea0445cfa16ca3700a263517b28c935c9ddca7de8cbb
7
- data.tar.gz: dd35cce57f836527e31a6bd36576f6966494f558d1a0cc87486632c3149b1eecf66f37493f188f0a1ff685b804ddedb33bc13c1c6d45e5142335710ea7dea88c
6
+ metadata.gz: 58071bec7536d36329370d7be259b7a23efd00870e8aac6d2ecb116a568ec87f08bed596ce3d85e4be3e58b9603e7d4d040f0220d3709ffa8063eb12e77ba9f1
7
+ data.tar.gz: c48c7d2b6ed22d2b6dd80a3d4ce4ba574f793bc1005ee4e8512b7c696bd06d802bce681ade9919e3ae606ef8807f8993f9ee26d77a12c4430aed23340c8546f9
@@ -170,6 +170,7 @@ files.each do |file_path|
170
170
  reference_clause: ref_clause,
171
171
  file_path: fpath + revision_string
172
172
  )
173
+ next unless concept
173
174
 
174
175
  unless term_special_category(bibdata)
175
176
  # log "INFO: this part is generic"
@@ -183,34 +184,38 @@ files.each do |file_path|
183
184
  parsed_bibliography << bibdata
184
185
  end
185
186
 
186
- current_document.xpath('//arm').each do |arm_node|
187
- index = max_encountered_refs_indexes[bibdata.anchor] || 1
188
-
187
+ part_modules = []
188
+ current_document.xpath('//arm/uof').each do |uof_node|
189
189
  concept = Stepmod::Utils::Concept.parse(
190
- arm_node,
190
+ uof_node,
191
191
  reference_anchor: bibdata.anchor,
192
192
  reference_clause: nil,
193
193
  file_path: fpath + revision_string
194
194
  )
195
+ # puts concept.inspect
195
196
 
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
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
204
206
 
205
- max_encountered_refs_indexes[bibdata.anchor] = index + 1
206
207
  parsed_bibliography << bibdata
207
208
  end
208
209
 
210
+ part_resources = []
211
+ # Assumption: every schema is only linked by a single resource_docs document.
209
212
  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
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
212
218
  description_document.xpath('//ext_description').each do |ext_description|
213
- index = max_encountered_refs_indexes[bibdata.anchor] || 1
214
219
 
215
220
  concept = Stepmod::Utils::Concept.parse(
216
221
  ext_description,
@@ -218,17 +223,16 @@ files.each do |file_path|
218
223
  reference_clause: nil,
219
224
  file_path: fpath + revision_string
220
225
  )
226
+ next unless concept
221
227
 
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
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
230
235
 
231
- max_encountered_refs_indexes[bibdata.anchor] = index + 1
232
236
  parsed_bibliography << bibdata
233
237
  end
234
238
  end
@@ -236,7 +240,7 @@ files.each do |file_path|
236
240
 
237
241
  log "INFO: Completed processing XML file #{fpath}"
238
242
 
239
- if part_concepts.length == 0
243
+ if part_concepts.empty?
240
244
  log "INFO: Skipping #{fpath} (#{bibdata.docid}) because it contains no concepts."
241
245
  next
242
246
  elsif part_concepts.length < 3
@@ -254,6 +258,24 @@ files.each do |file_path|
254
258
  log "INFO: written to: #{fn}"
255
259
  end
256
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
+
257
279
  end
258
280
 
259
281
  File.open('031-stepmod-general.adoc', 'w') { |file|
@@ -23,7 +23,10 @@ module Stepmod
23
23
  def self.parse(definition_xml, reference_anchor:, reference_clause:, file_path:)
24
24
  converted_definition = Stepmod::Utils::StepmodDefinitionConverter
25
25
  .convert(definition_xml, { reference_anchor: reference_anchor })
26
- if definition_xml.name == 'arm' || definition_xml.name == 'ext_description'
26
+
27
+ return nil if converted_definition.nil? || converted_definition.strip.empty?
28
+
29
+ if definition_xml.name == 'uof' || definition_xml.name == 'ext_description'
27
30
  converted_definition = <<~TEXT
28
31
  #{converted_definition.split("\n")[0..3].join("\n")}
29
32
 
@@ -4,6 +4,11 @@ module Stepmod
4
4
  class StepmodExtDescription < ReverseAdoc::Converters::Base
5
5
  def convert(node, state = {})
6
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
+
7
12
  <<~TEMPLATE
8
13
  === #{node['linkend'].split('.').last}
9
14
 
@@ -40,19 +40,21 @@ module Stepmod
40
40
  module Utils
41
41
  class StepmodDefinitionConverter
42
42
  def self.convert(input, options = {})
43
- root = if input.is_a?(String)
44
- then Nokogiri::XML(input).root
45
- elsif input.is_a?(Nokogiri::XML::Document)
46
- then input.root
47
- elsif input.is_a?(Nokogiri::XML::Node)
48
- then input
49
- 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
50
51
 
51
- root || (return '')
52
+ return '' unless root
52
53
 
53
54
  ReverseAdoc.config.with(options) do
54
55
  result = ReverseAdoc::Converters.lookup(root.name).convert(root)
55
- ReverseAdoc.cleaner.tidy(result)
56
+ return '' unless result
57
+ ReverseAdoc.cleaner.tidy(result.dup)
56
58
  end
57
59
  end
58
60
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.