solis 0.127.0 → 0.128.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7cf89eceec897d7b5fe15ef1669b031480a7aab2850bd5638cfac379e4798ae
4
- data.tar.gz: 56a9ce9652925e1be2904dc150bba6d31f3f2ca13870641c883fb0dde65b341c
3
+ metadata.gz: 8200228367f2710bad52af70fd0430ca70ec589fe284e19e22bdfe4e1a659a98
4
+ data.tar.gz: 337d425fa58afb14c95cfd3703d848a9093e563a335f1d37b08d420981389761
5
5
  SHA512:
6
- metadata.gz: 499ff31724baaa76c0ae960916d5b01c0f25f535e07e89fd0cba72cbc042fe271898b5c422842201463daef4903d1207bf4fdcbd248e3bbff346153f4dba1765
7
- data.tar.gz: 264f64d77cf8b15d708da87cbf0602a6f8be5282c04a365f52966e865895032e9c08b4952e99abbcb6e5f4aa80fcbd20887e3e4d9c961398e350a4cbaff17b0b
6
+ metadata.gz: 64cae66429794837abf0e51b72e43847337c195a69b9f6ca5cbffa22bf6888dc472592d7c186d31ca9a7b4eca826d3ecdf1a4c1b0853d047d778cc7931f4ab47
7
+ data.tar.gz: 449810be62118c3def433b580a8e794f3b19ef84413d8b14ca1fbda72c95986ebe8787ddb5a019cb9d63c2dc73f756983b0fc6249977241585c490217a494a12
data/lib/solis/model.rb CHANGED
@@ -590,7 +590,10 @@ values ?s {<#{self.graph_id}>}
590
590
  description: attribute_metadata[:comment]&.value
591
591
  }
592
592
  attribute_data[:order] = attribute_metadata[:order]&.value.to_i if attribute_metadata.key?(:order) && !attribute_metadata[:order].nil?
593
- attribute_data[:group] = attribute_metadata[:group]&.value.gsub(graph_name,'').gsub(/Group$/,'') if attribute_metadata.key?(:group) && !attribute_metadata[:group].nil?
593
+ if attribute_metadata.key?(:group) && !attribute_metadata[:group].nil?
594
+ attribute_data[:group] = { name: attribute_metadata[:group][:name],
595
+ label: attribute_metadata[:group][:label] || {} }
596
+ end
594
597
  attribute_data[:attributes] = cm[:attributes] if cm && cm[:attributes]
595
598
 
596
599
  m[:attributes] << attribute_data
@@ -45,7 +45,8 @@ module Solis
45
45
 
46
46
  if sheets.key?('_CATEGORIES')
47
47
  categories = sheets['_CATEGORIES']
48
- raise "_CATEGORIES tab must have ['name'] as a header at row 1" unless (%w[name] - categories.header).length == 0
48
+ has_name = categories.header.include?('name') || categories.header.any? { |h| language_column('name').match?(h.to_s) }
49
+ raise "_CATEGORIES tab must have ['name'] or ['name_XX', ...] as a header at row 1" unless has_name
49
50
  end
50
51
 
51
52
  sheets.each do |sheet_name, sheet|
@@ -141,17 +142,20 @@ module Solis
141
142
  raise Solis::Error::GeneralError, e.message
142
143
  end
143
144
 
144
- # Matches the 'Label_XX' columns (header is downcased by ::Sheet#header) where
145
- # XX is a language tag, ex. 'Label_NL', 'Label_EN', 'Label_nl-BE'
146
- LANGUAGE_LABEL_COLUMN = /\Alabel_(?<language>[a-z]{2,3}([-_][a-z0-9]{2,8})*)\z/.freeze
145
+ # Matches the '<prefix>_XX' columns (header is downcased by ::Sheet#header) where
146
+ # XX is a language tag, ex. 'Label_NL', 'Label_EN', 'Label_nl-BE', 'Name_nl'
147
+ def language_column(prefix)
148
+ /\A#{Regexp.escape(prefix.to_s.downcase)}_(?<language>[a-z]{2,3}([-_][a-z0-9]{2,8})*)\z/
149
+ end
147
150
 
148
- # Collects all 'Label_XX' columns of a row into { nl: 'Publiceren', en: 'Publish' }
149
- def parse_labels(row)
151
+ # Collects all 'Label_XX' (or '<prefix>_XX') columns of a row into { nl: 'Publiceren', en: 'Publish' }
152
+ def parse_labels(row, prefix = 'label')
150
153
  labels = {}
151
154
  return labels unless row.respond_to?(:each_pair)
152
155
 
156
+ column_pattern = language_column(prefix)
153
157
  row.each_pair do |column, value|
154
- match = LANGUAGE_LABEL_COLUMN.match(column.to_s)
158
+ match = column_pattern.match(column.to_s)
155
159
  next if match.nil?
156
160
  next if value.nil? || value.to_s.strip.empty?
157
161
 
@@ -283,7 +287,7 @@ hide empty members
283
287
  "\n#{indent}#{rdfs_prefix}:label #{literals.join(', ')} ;"
284
288
  end
285
289
 
286
- def build_shacl(datas)
290
+ def build_shacl(datas, categories = [])
287
291
  shacl_prefix = datas.first[:ontologies][:all].select { |_, v| v[:uri] =~ /shacl/ }.keys.first
288
292
  shacl_prefix = 'sh' if shacl_prefix.nil?
289
293
 
@@ -385,10 +389,17 @@ hide empty members
385
389
  out += ".\n"
386
390
 
387
391
  groups.each do |group, category|
392
+ # use the per language names from _CATEGORIES when the category is referenced by any of them
393
+ category_labels = categories.find { |c| c[:name].eql?(category) || c[:labels].value?(category) }&.dig(:labels)
394
+ group_label = if category_labels.nil? || category_labels.empty?
395
+ %(#{rdfs_prefix}:label "#{category}")
396
+ else
397
+ build_labels(category_labels, rdfs_prefix, '').strip.chomp(' ;')
398
+ end
388
399
  out += %(
389
400
  #{graph_prefix}:#{group}
390
401
  a #{shacl_prefix}:PropertyGroup ;
391
- #{rdfs_prefix}:label "#{category}" .
402
+ #{group_label} .
392
403
 
393
404
  )
394
405
  end
@@ -526,7 +537,7 @@ hide empty members
526
537
  # categories are uninflected, singular and plural are the same word.
527
538
  # an entity by the same name keeps its own plural.
528
539
  # categories.each do |category|
529
- # name = category.to_s.strip
540
+ # name = category[:name].to_s.strip
530
541
  # next if name.empty?
531
542
  #
532
543
  # inflections[name.to_sym] = name unless inflections.key?(name.to_sym) || inclections.value?(name.to_s)
@@ -780,7 +791,19 @@ hide empty members
780
791
  options[:metadata] = metadata
781
792
 
782
793
  # like _REFERENCES, _CATEGORIES only lives in the main sheet
783
- categories = sheet_data.is_a?(Hash) && sheet_data.key?('_CATEGORIES') ? sheet_data['_CATEGORIES'].map { |c| c['name'] } : []
794
+ # a category can have a name per language ('Name_nl', 'Name_en', ...) next to, or instead of, 'Name'.
795
+ # entity sheets refer to a category by 'Name' or, when missing, by the first 'Name_XX' column.
796
+ categories = []
797
+ if sheet_data.is_a?(Hash) && sheet_data.key?('_CATEGORIES')
798
+ categories = sheet_data['_CATEGORIES'].map do |c|
799
+ labels = parse_labels(c, 'name')
800
+ name = c['name'].to_s.strip
801
+ name = labels.values.first.to_s if name.empty?
802
+ next if name.empty?
803
+
804
+ { name: name, labels: labels }
805
+ end.compact
806
+ end
784
807
  Solis::LOGGER.info("Found #{categories.length} categories") unless categories.empty?
785
808
 
786
809
  #TODO: cleanup
@@ -820,7 +843,7 @@ hide empty members
820
843
  end
821
844
 
822
845
  Solis::LOGGER.info('Generating SHACL')
823
- shacl = build_shacl(datas)
846
+ shacl = build_shacl(datas, categories)
824
847
  Solis::LOGGER.info('Generating PLANTUML')
825
848
  plantuml = build_plantuml(datas)
826
849
  Solis::LOGGER.info('Generating SCHEMA')
data/lib/solis/shape.rb CHANGED
@@ -156,12 +156,25 @@ module Solis
156
156
  next if attribute.nil?
157
157
 
158
158
  attribute[:label] = labels_of(graph, property.object)
159
+ attribute[:group] = group_of(graph, attribute[:group]) unless attribute[:group].nil?
159
160
  end
160
161
  end
161
162
 
162
163
  shapes
163
164
  end
164
165
 
166
+ # Turns a sh:PropertyGroup URI into
167
+ # { uri: RDF::URI, name: 'OpleidingEnLoopbaan', label: { nl: 'opleiding_en_loopbaan', en: 'education_and_career' } }
168
+ def group_of(graph, group)
169
+ return group if group.is_a?(Hash)
170
+
171
+ {
172
+ uri: group,
173
+ name: group.to_s.split(%r{[/#]}).last.to_s.gsub(/Group$/, ''),
174
+ label: labels_of(graph, group)
175
+ }
176
+ end
177
+
165
178
  def name_of(graph, subject)
166
179
  graph.query([subject, RDF::Vocab::SHACL.name, nil]).first&.object&.value
167
180
  end
data/lib/solis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Solis
2
- VERSION = "0.127.0"
2
+ VERSION = "0.128.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.127.0
4
+ version: 0.128.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik