solis 0.116.0 → 0.117.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: affbb3891268851909a6a35684c11a36f6e67d617dea1e977015124ca0bd8118
4
- data.tar.gz: 920ad82dc52d0bdefe3bd1e08b631e6907d6f13952f5573fc3bb8f392b03521d
3
+ metadata.gz: fa9ba6d86b36ebd75e9e0280928ce458f1ae70e4c64f44832c0963870f319b2f
4
+ data.tar.gz: 23c8bd2bcbbb4fe97dc133b3310d1527bab161dbce43e2939b45a8fa1a9b7712
5
5
  SHA512:
6
- metadata.gz: 9b42751289ba605e41d7e02c85a6a7df99a41a80237ca282a4502d3c4a48198ba8057a35b884a51914b828657a88b1d6c3899d3dd703f10c30a0b9ff779dd364
7
- data.tar.gz: 8d627312e95e719ab5ddabbd8bdbd0f964aa0a98ed6372df07f18462ecf69a9bdd4ce1e53f21b29392ad450a5874ebfb6bc5b510bc2adbb5fe634a1edf325cc0
6
+ metadata.gz: f15183cf04d168b3d06425bfe987d4cc446d0fad1e1b1f94532b8dfedf39b3401d39641226d91a63400f4a4e1c7096a0c995b64e2629d6d07424bae7e4c14375
7
+ data.tar.gz: d7219d14c2290aa045ca80a32a97df1f12fcc4aa0df31fc3628fe91dbd5e2ee7e6239474aef27f4f43caf45fb9347e8cd059a0deabff12a3b2bd754ad1e98342
data/lib/solis/model.rb CHANGED
@@ -583,10 +583,11 @@ values ?s {<#{self.graph_id}>}
583
583
  attribute_data = { name: attribute,
584
584
  data_type: attribute_metadata[:datatype],
585
585
  mandatory: (attribute_metadata[:mincount].to_i > 0),
586
+ repeatable: (attribute_metadata[:maxcount].to_i > 1 || attribute_metadata[:maxcount].nil?),
586
587
  description: attribute_metadata[:comment]&.value
587
588
  }
588
589
  attribute_data[:order] = attribute_metadata[:order]&.value.to_i if attribute_metadata.key?(:order) && !attribute_metadata[:order].nil?
589
- attribute_data[:category] = attribute_metadata[:category]&.value if attribute_metadata.key?(:category) && !attribute_metadata[:category].nil?
590
+ attribute_data[:group] = attribute_metadata[:group]&.value.gsub(graph_name,'').gsub(/Group$/,'') if attribute_metadata.key?(:group) && !attribute_metadata[:group].nil?
590
591
  attribute_data[:attributes] = cm[:attributes] if cm && cm[:attributes]
591
592
 
592
593
  m[:attributes] << attribute_data
@@ -52,28 +52,20 @@ module Solis
52
52
  end
53
53
 
54
54
  def read_sheets(key, spreadsheet_id, options)
55
- data = nil
56
55
  prefixes = options[:prefixes] || nil
57
56
  metadata = options[:metadata] || nil
58
57
 
59
- cache_dir = ConfigFile.include?(:cache) ? ConfigFile[:cache] : '/tmp'
60
-
61
- if ::File.exist?("#{cache_dir}/#{spreadsheet_id}.json") && (options.include?(:from_cache) && options[:from_cache])
62
- Solis::LOGGER.info("from cache #{cache_dir}/#{spreadsheet_id}.json")
63
- data = JSON.parse(::File.read("#{cache_dir}/#{spreadsheet_id}.json"), { symbolize_names: true })
64
- return data
65
- else
66
- Solis::LOGGER.info("from source #{spreadsheet_id}")
67
- session = SimpleSheets.new(key, spreadsheet_id)
68
- session.key = key
69
- sheets = {}
70
- session.worksheets.each do |worksheet|
71
- sheet = ::Sheet.new(worksheet)
72
- sheets[sheet.title] = sheet
73
- end
74
-
75
- validate(sheets, prefixes, metadata)
58
+ Solis::LOGGER.info("from source #{spreadsheet_id}")
59
+ session = SimpleSheets.new(key, spreadsheet_id)
60
+ session.key = key
61
+ sheets = {}
62
+ session.worksheets.each do |worksheet|
63
+ sheet = ::Sheet.new(worksheet)
64
+ sheets[sheet.title] = sheet
76
65
  end
66
+
67
+ validate(sheets, prefixes, metadata)
68
+
77
69
  sheets
78
70
  end
79
71
 
@@ -118,6 +110,7 @@ module Solis
118
110
 
119
111
  entities.store(e['name'].to_sym, { description: e['description'],
120
112
  order: e['order'],
113
+ category: e['categories'],
121
114
  plural: e['nameplural'],
122
115
  label: e['name'].to_s.strip,
123
116
  sub_class_of: e['subclassof'].nil? || e['subclassof'].empty? ? [] : [e['subclassof']],
@@ -137,12 +130,6 @@ module Solis
137
130
  metadata: ontology_metadata
138
131
  }
139
132
 
140
- cache_dir = ConfigFile.include?(:cache) ? ConfigFile[:cache] : '/tmp'
141
- # ::File.open("#{::File.absolute_path(cache_dir)}/#{spreadsheet_id}.json", 'wb') do |f|
142
- ::File.open("#{::File.absolute_path(cache_dir)}/#{sheet_id}.json", 'wb') do |f|
143
- f.puts data.to_json
144
- end
145
-
146
133
  data
147
134
  rescue StandardError => e
148
135
  raise Solis::Error::GeneralError, e.message
@@ -180,6 +167,7 @@ module Solis
180
167
  cardinality: { min: min_max['min'], max: min_max['max'] },
181
168
  same_as: p['sameas'],
182
169
  order: p['order'],
170
+ category: p['categories'],
183
171
  description: p['description']
184
172
  }
185
173
 
@@ -302,6 +290,8 @@ hide empty members
302
290
  node = target_class
303
291
  end
304
292
 
293
+ groups = {}
294
+
305
295
  out += %(
306
296
  #{graph_prefix}:#{entity_name}Shape
307
297
  a #{shacl_prefix}:NodeShape ;
@@ -322,11 +312,19 @@ hide empty members
322
312
  min_count = property_metadata[:cardinality][:min].strip
323
313
  max_count = property_metadata[:cardinality][:max].strip
324
314
  order = property_metadata.key?(:order) && property_metadata[:order] ? property_metadata[:order]&.strip : nil
315
+ category = property_metadata.key?(:category) && property_metadata[:category] ? property_metadata[:category]&.strip : nil
316
+ category = category.nil? || category.empty? ? nil : category
317
+
318
+ unless category.nil?
319
+ group = "#{category.classify}Group"
320
+ groups[group] = category unless groups.key?(group)
321
+ end
325
322
 
326
323
  if datatype =~ /^#{graph_prefix}:/ || datatype =~ /^<#{graph_name}/
327
324
  out += %( #{shacl_prefix}:property [#{shacl_prefix}:path #{path} ;
328
325
  #{shacl_prefix}:name "#{attribute}" ;
329
326
  #{shacl_prefix}:description "#{description}" ;#{order.nil? ? '' : "\n #{shacl_prefix}:order #{order} ;"}
327
+ #{category.nil? ? '' : "\n #{shacl_prefix}:group #{graph_prefix}:#{group} ;"}
330
328
  #{shacl_prefix}:nodeKind #{shacl_prefix}:IRI ;
331
329
  #{shacl_prefix}:class #{datatype} ;#{min_count =~ /\d+/ ? "\n #{shacl_prefix}:minCount #{min_count} ;" : ''}#{max_count =~ /\d+/ ? "\n #{shacl_prefix}:maxCount #{max_count} ;" : ''}
332
330
  ] ;
@@ -344,6 +342,7 @@ hide empty members
344
342
  out += %( #{shacl_prefix}:property [#{shacl_prefix}:path #{path} ;
345
343
  #{shacl_prefix}:name "#{attribute}";
346
344
  #{shacl_prefix}:description "#{description}" ;#{order.nil? ? '' : "\n #{shacl_prefix}:order #{order} ;"}
345
+ #{category.nil? ? '' : "\n #{shacl_prefix}:group #{graph_prefix}:#{group} ;"}
347
346
  #{shacl_prefix}:datatype #{datatype} ;#{min_count =~ /\d+/ ? "\n #{shacl_prefix}:minCount #{min_count} ;" : ''}#{max_count =~ /\d+/ ? "\n #{shacl_prefix}:maxCount #{max_count} ;" : ''}
348
347
  ] ;
349
348
  )
@@ -359,6 +358,15 @@ hide empty members
359
358
  end
360
359
  end
361
360
  out += ".\n"
361
+
362
+ groups.each do |group, category|
363
+ out += %(
364
+ #{graph_prefix}:#{group}
365
+ a sh:PropertyGroup ;
366
+ rdfs:label "#{category}" .
367
+
368
+ )
369
+ end
362
370
  end
363
371
  end
364
372
  out
@@ -716,6 +724,14 @@ hide empty members
716
724
  end
717
725
  end
718
726
 
727
+ cache_dir = ConfigFile.include?(:cache) ? ConfigFile[:cache] : '/tmp'
728
+ cache_file = "#{::File.absolute_path(cache_dir)}/#{spreadsheet_id}.json"
729
+
730
+ if options[:from_cache] && ::File.exist?(cache_file)
731
+ Solis::LOGGER.info("Loading cached result from #{cache_file}")
732
+ return JSON.parse(::File.read(cache_file), symbolize_names: true)
733
+ end
734
+
719
735
  sheet_data = read_sheets(key, spreadsheet_id, options)
720
736
  prefixes = sheet_data['_PREFIXES']
721
737
  metadata = sheet_data['_METADATA']
@@ -736,10 +752,6 @@ hide empty members
736
752
  { sheet_url: reference['sheeturl'], description: reference['description'] }
737
753
  end
738
754
 
739
- cache_dir = ConfigFile.include?(:cache) ? ConfigFile[:cache] : '/tmp'
740
- ::File.open("#{::File.absolute_path(cache_dir)}/#{spreadsheet_id}.json", 'wb') do |f|
741
- f.puts references.to_json
742
- end
743
755
  else
744
756
  references = sheet_data
745
757
  end
@@ -778,7 +790,16 @@ hide empty members
778
790
  Solis::LOGGER.info('Generating JSON SCHEMA')
779
791
  json_schema = build_json_schema(shacl)
780
792
 
781
- { inflections: inflections, shacl: shacl, schema: schema, plantuml: plantuml, json_schema: json_schema }
793
+ result = { inflections: inflections, shacl: shacl, schema: schema, plantuml: plantuml, json_schema: json_schema }
794
+
795
+ begin
796
+ ::File.open(cache_file, 'wb') { |f| f.puts result.to_json }
797
+ Solis::LOGGER.info("Cached result to #{cache_file}")
798
+ rescue StandardError => e
799
+ Solis::LOGGER.warn("Failed to write cache: #{e.message}")
800
+ end
801
+
802
+ result
782
803
  end
783
804
  end
784
805
  end
data/lib/solis/shape.rb CHANGED
@@ -104,6 +104,7 @@ module Solis
104
104
  attribute_class = solution.attributeClass if solution.bound?(:attributeClass)
105
105
  attribute_comment = solution.attributeComment if solution.bound?(:attributeComment)
106
106
  attribute_order = solution.attributeOrder if solution.bound?(:attributeOrder)
107
+ attribute_group = solution.attributeGroup if solution.bound?(:attributeGroup)
107
108
 
108
109
  attribute_max_count = 1 if solution.bound?(:attributeUniqueLang) && solution.attributeUniqueLang.value.eql?('true')
109
110
 
@@ -125,6 +126,7 @@ module Solis
125
126
  mincount: attribute_min_count,
126
127
  maxcount: attribute_max_count,
127
128
  order: attribute_order,
129
+ group: attribute_group,
128
130
  node: attribute_node,
129
131
  node_kind: attribute_node_kind,
130
132
  class: attribute_class,
@@ -142,7 +144,7 @@ PREFIX rdfv: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
142
144
 
143
145
  SELECT ?targetClass ?targetNode ?comment ?className ?attributePath ?attributeName ?attributeDatatype
144
146
  ?attributeMinCount ?attributeMaxCount ?attributeOr ?attributeClass
145
- ?attributeNode ?attributeNodeKind ?attributeComment ?attributeOrder ?attributeUniqueLang ?o
147
+ ?attributeNode ?attributeNodeKind ?attributeComment ?attributeOrder ?attributeGroup ?attributeUniqueLang ?o
146
148
  WHERE {
147
149
 
148
150
  ?s a sh:NodeShape;
@@ -162,6 +164,7 @@ WHERE {
162
164
  OPTIONAL{ ?attributes sh:node ?attributeNode } .
163
165
  OPTIONAL{ ?attributes sh:description ?attributeComment } .
164
166
  OPTIONAL{ ?attributes sh:order ?attributeOrder } .
167
+ OPTIONAL{ ?attributes sh:group ?attributeGroup } .
165
168
  OPTIONAL{ ?attributes sh:uniqueLang ?attributeUniqueLang } .
166
169
  }.
167
170
  }
@@ -182,6 +185,7 @@ WHERE {
182
185
  "mincount": 1,
183
186
  "maxcount": 1,
184
187
  "order": nil,
188
+ "group": nil,
185
189
  "node": nil,
186
190
  "node_kind": nil,
187
191
  "class": nil,
data/lib/solis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Solis
2
- VERSION = "0.116.0"
2
+ VERSION = "0.117.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.116.0
4
+ version: 0.117.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik