solis 0.93.0 → 0.96.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.
@@ -6,7 +6,8 @@ module Solis
6
6
  def initialize(model)
7
7
  @model = model
8
8
  @sparql_endpoint = @model.class.sparql_endpoint
9
- @sparql_client = SPARQL::Client.new(@sparql_endpoint, graph: @model.class.graph_name, read_timeout: 120)
9
+ #@sparql_client = SPARQL::Client.new(@sparql_endpoint, graph: @model.class.graph_name, read_timeout: 120)
10
+ @sparql_client = Solis::Store::Sparql::Client.new(@sparql_endpoint, graph: @model.class.graph_name, read_timeout: 120)
10
11
  @construct_cache = File.absolute_path(Solis::Options.instance.get[:cache])
11
12
  @moneta = Moneta.new(:File, dir: "#{@construct_cache}/construct", expires: Solis::Options.instance.get[:cache_expire])
12
13
  end
@@ -38,7 +39,7 @@ module Solis
38
39
  if @moneta.key?(file_path_hash) && from_cache.eql?('1')
39
40
  sparql_repository = @moneta[file_path_hash]
40
41
  else
41
- @sparql_client = SPARQL::Client.new(@sparql_endpoint, read_timeout: 120)
42
+ #@sparql_client = SPARQL::Client.new(@sparql_endpoint, read_timeout: 120)
42
43
  result = @sparql_client.query(construct_query)
43
44
  repository=RDF::Repository.new
44
45
  result.each {|s| repository << [s[:s], s[:p], s[:o]]}
@@ -114,13 +114,11 @@ module Solis
114
114
  v=normalize_string(v)
115
115
  filter = "?concept <#{metadata[:path]}> ?__search#{i} FILTER(?__search#{i} #{not_operator}#{value[:operator]} \"#{v}\"#{datatype}) .\n"
116
116
  end
117
-
118
-
119
117
  end
120
118
  else # if "~" contains
121
119
  if metadata[:datatype_rdf].eql?( 'http://www.w3.org/2001/XMLSchema#anyURI') || !metadata[:node].nil?
122
120
  model_graph_name = Solis::Options.instance.get.key?(:graphs) ? Solis::Options.instance.get[:graphs].select{|s| s['type'].eql?(:data)}&.first['name'] : @model.class.graph_name
123
- filter = "?CONCEPT <#{metadata[:path]}> ?__search#{i} . ?__search#{i} <#{model_graph_name}id> ?__search#{i}_#{i} FILTER(?__search#{i}_#{i} = \"#{value[:value].first}\")."
121
+ filter = "?concept <#{metadata[:path]}> ?__search#{i} . ?__search#{i} <#{model_graph_name}id> ?__search#{i}_#{i} filter(?__search#{i}_#{i} = \"#{value[:value].first}\")."
124
122
  else
125
123
  filter = "?concept <#{metadata[:path]}> ?__search#{i} FILTER(#{contains.empty? ? '""' : contains}) .\n"
126
124
  end
@@ -15,7 +15,7 @@ class Solis::Query::Runner
15
15
  }
16
16
  )
17
17
 
18
- c = Solis::Store::Sparql::Client.new(Solis::Options.instance.get[:sparql_endpoint], graph_name)
18
+ c = Solis::Store::Sparql::Client.new(Solis::Options.instance.get[:sparql_endpoint], graph_name: graph_name)
19
19
  r = c.query(query, options)
20
20
  if r.is_a?(SPARQL::Client)
21
21
  g = RDF::Graph.new
@@ -109,6 +109,7 @@ class Solis::Query::Runner
109
109
  end
110
110
 
111
111
  def self.graph_name
112
+ raise Solis::Error::NotFoundError, 'No graph name found' if Solis::Options.instance.get.key?(:graphs).nil?
112
113
  Solis::Options.instance.get.key?(:graphs) ? Solis::Options.instance.get[:graphs].select{|s| s['type'].eql?(:main)}&.first['name'] : ''
113
114
  end
114
115
  end
data/lib/solis/query.rb CHANGED
@@ -11,8 +11,8 @@ module Solis
11
11
  include Enumerable
12
12
  include Solis::QueryFilter
13
13
 
14
- def self.run(entity, query)
15
- Solis::Query::Runner.run(entity, query)
14
+ def self.run(entity, query, options = {})
15
+ Solis::Query::Runner.run(entity, query, options)
16
16
  end
17
17
 
18
18
  def self.run_construct_with_file(filename, id_name, entity, ids, from_cache = '1')
@@ -65,11 +65,10 @@ module Solis
65
65
  @metadata = @model.class.metadata
66
66
  @sparql_endpoint = @model.class.sparql_endpoint
67
67
  if Solis::Options.instance.get.key?(:graphs) && Solis::Options.instance.get[:graphs].size > 0
68
- @sparql_client = SPARQL::Client.new(@sparql_endpoint)
68
+ @sparql_client = Solis::Store::Sparql::Client.new(@sparql_endpoint)
69
69
  else
70
- @sparql_client = SPARQL::Client.new(@sparql_endpoint, graph: @model.class.graph_name)
70
+ @sparql_client = Solis::Store::Sparql::Client.new(@sparql_endpoint, graph: @model.class.graph_name)
71
71
  end
72
-
73
72
  @filter = {values: ["VALUES ?type {#{target_class}}"], concepts: ['?concept a ?type .'] }
74
73
  @sort = 'ORDER BY ?s'
75
74
  @sort_select = ''
@@ -166,7 +165,6 @@ module Solis
166
165
  offset = @offset || 0
167
166
 
168
167
  sparql_client = model_construct? ? Solis::Query::Construct.new(@model).run : @sparql_client
169
- #sparql_client = model_construct? ? SPARQL::Client.new(run_construct) : @sparql_client
170
168
 
171
169
  relationship = ''
172
170
  if options.key?(:relationship)
@@ -196,7 +194,7 @@ order by ?s
196
194
 
197
195
  Solis::LOGGER.info(query) if ConfigFile[:debug]
198
196
 
199
- query_key = "#{@model.name}-#{Digest::MD5.hexdigest(query)}"
197
+ query_key = "#{@model.model_class_name}-#{Digest::MD5.hexdigest(query)}"
200
198
 
201
199
  result = nil
202
200
 
@@ -277,7 +275,7 @@ PREFIX #{@model.class.graph_prefix}: <#{@model.class.graph_name}>"
277
275
  attribute = statement.p.value.split('/').last.underscore
278
276
 
279
277
  unless solution_model.metadata[:attributes].key?(attribute)
280
- Solis::LOGGER.error "Attribute found in data that is not part of the model model #{solution_model.name}(#{record_uri.split('/').last}).#{attribute}"
278
+ Solis::LOGGER.error "Attribute found in data that is not part of the model model #{solution_model.model_class_name}(#{record_uri.split('/').last}).#{attribute}"
281
279
  next
282
280
  end
283
281
 
@@ -117,6 +117,7 @@ module Solis
117
117
  end
118
118
 
119
119
  entities.store(e['name'].to_sym, { description: e['description'],
120
+ order: e['order'],
120
121
  plural: e['nameplural'],
121
122
  label: e['name'].to_s.strip,
122
123
  sub_class_of: e['subclassof'].nil? || e['subclassof'].empty? ? [] : [e['subclassof']],
@@ -178,6 +179,7 @@ module Solis
178
179
  path: "#{graph_prefix}:#{property_name.to_s.classify}",
179
180
  cardinality: { min: min_max['min'], max: min_max['max'] },
180
181
  same_as: p['sameas'],
182
+ order: p['order'],
181
183
  description: p['description']
182
184
  }
183
185
 
@@ -308,7 +310,7 @@ hide empty members
308
310
  unless node.nil? || node.empty?
309
311
  "\n #{shacl_prefix}:node #{node} ;"
310
312
  end}
311
- #{shacl_prefix}:name "#{label}" ;
313
+ #{shacl_prefix}:name "#{label}" ;
312
314
  )
313
315
  metadata[:properties].each do |property, property_metadata|
314
316
  attribute = property.to_s.strip
@@ -319,28 +321,36 @@ hide empty members
319
321
  datatype = property_metadata[:datatype].strip
320
322
  min_count = property_metadata[:cardinality][:min].strip
321
323
  max_count = property_metadata[:cardinality][:max].strip
324
+ order = property_metadata.key?(:order) && property_metadata[:order] ? property_metadata[:order]&.strip : nil
322
325
 
323
326
  if datatype =~ /^#{graph_prefix}:/ || datatype =~ /^<#{graph_name}/
324
327
  out += %( #{shacl_prefix}:property [#{shacl_prefix}:path #{path} ;
325
328
  #{shacl_prefix}:name "#{attribute}" ;
326
- #{shacl_prefix}:description "#{description}" ;
329
+ #{shacl_prefix}:description "#{description}" ;#{order.nil? ? '' : "\n #{shacl_prefix}:order #{order} ;"}
327
330
  #{shacl_prefix}:nodeKind #{shacl_prefix}:IRI ;
328
331
  #{shacl_prefix}:class #{datatype} ;#{min_count =~ /\d+/ ? "\n #{shacl_prefix}:minCount #{min_count} ;" : ''}#{max_count =~ /\d+/ ? "\n #{shacl_prefix}:maxCount #{max_count} ;" : ''}
329
332
  ] ;
330
333
  )
331
334
  else
332
- if datatype.eql?('rdf:langString')
335
+ if datatype.eql?('rdf:langString') && max_count.eql?('1')
333
336
  out += %( #{shacl_prefix}:property [#{shacl_prefix}:path #{path} ;
334
337
  #{shacl_prefix}:name "#{attribute}";
335
- #{shacl_prefix}:description "#{description}" ;
338
+ #{shacl_prefix}:description "#{description}" ;#{order.nil? ? '' : "\n #{shacl_prefix}:order #{order} ;"}
336
339
  #{shacl_prefix}:uniqueLang true ;
337
340
  #{shacl_prefix}:datatype #{datatype} ;#{min_count =~ /\d+/ ? "\n #{shacl_prefix}:minCount #{min_count} ;" : ''}
338
341
  ] ;
342
+ )
343
+ elsif datatype.eql?('rdf:langString')
344
+ out += %( #{shacl_prefix}:property [#{shacl_prefix}:path #{path} ;
345
+ #{shacl_prefix}:name "#{attribute}";
346
+ #{shacl_prefix}:description "#{description}" ;#{order.nil? ? '' : "\n #{shacl_prefix}:order #{order} ;"}
347
+ #{shacl_prefix}:datatype #{datatype} ;#{min_count =~ /\d+/ ? "\n #{shacl_prefix}:minCount #{min_count} ;" : ''}#{max_count =~ /\d+/ ? "\n #{shacl_prefix}:maxCount #{max_count} ;" : ''}
348
+ ] ;
339
349
  )
340
350
  else
341
351
  out += %( #{shacl_prefix}:property [#{shacl_prefix}:path #{path} ;
342
352
  #{shacl_prefix}:name "#{attribute}";
343
- #{shacl_prefix}:description "#{description}" ;
353
+ #{shacl_prefix}:description "#{description}" ;#{order.nil? ? '' : "\n #{shacl_prefix}:order #{order} ;"}
344
354
  #{shacl_prefix}:datatype #{datatype} ;#{min_count =~ /\d+/ ? "\n #{shacl_prefix}:minCount #{min_count} ;" : ''}#{max_count =~ /\d+/ ? "\n #{shacl_prefix}:maxCount #{max_count} ;" : ''}
345
355
  ] ;
346
356
  )
data/lib/solis/shape.rb CHANGED
@@ -100,6 +100,10 @@ module Solis
100
100
  attribute_node = solution.attributeNode if solution.bound?(:attributeNode)
101
101
  attribute_class = solution.attributeClass if solution.bound?(:attributeClass)
102
102
  attribute_comment = solution.attributeComment if solution.bound?(:attributeComment)
103
+ attribute_order = solution.attributeOrder if solution.bound?(:attributeOrder)
104
+
105
+ attribute_max_count = 1 if solution.bound?(:attributeUniqueLang) && solution.attributeUniqueLang.value.eql?('true')
106
+
103
107
  # if solution.bound?(:attributeOr)
104
108
  # pp solution
105
109
  # end
@@ -117,6 +121,7 @@ module Solis
117
121
  datatype: lookup_datatype(attribute_datatype_rdf, attribute_node),
118
122
  mincount: attribute_min_count,
119
123
  maxcount: attribute_max_count,
124
+ order: attribute_order,
120
125
  node: attribute_node,
121
126
  node_kind: attribute_node_kind,
122
127
  class: attribute_class,
@@ -134,7 +139,7 @@ PREFIX rdfv: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
134
139
 
135
140
  SELECT ?targetClass ?targetNode ?comment ?className ?attributePath ?attributeName ?attributeDatatype
136
141
  ?attributeMinCount ?attributeMaxCount ?attributeOr ?attributeClass
137
- ?attributeNode ?attributeNodeKind ?attributeComment ?o
142
+ ?attributeNode ?attributeNodeKind ?attributeComment ?attributeOrder ?attributeUniqueLang ?o
138
143
  WHERE {
139
144
 
140
145
  ?s a sh:NodeShape;
@@ -153,6 +158,8 @@ WHERE {
153
158
  OPTIONAL{ ?attributes sh:nodeKind ?attributeNodeKind } .
154
159
  OPTIONAL{ ?attributes sh:node ?attributeNode } .
155
160
  OPTIONAL{ ?attributes sh:description ?attributeComment } .
161
+ OPTIONAL{ ?attributes sh:order ?attributeOrder } .
162
+ OPTIONAL{ ?attributes sh:uniqueLang ?attributeUniqueLang } .
156
163
  }.
157
164
  }
158
165
  )
@@ -171,6 +178,7 @@ WHERE {
171
178
  "datatype": "string",
172
179
  "mincount": 1,
173
180
  "maxcount": 1,
181
+ "order": nil,
174
182
  "node": nil,
175
183
  "node_kind": nil,
176
184
  "class": nil,
@@ -7,13 +7,22 @@ module Solis
7
7
  module Store
8
8
  module Sparql
9
9
  class Client
10
- def initialize(endpoint, graph_name)
10
+ def initialize(endpoint, options = {})
11
11
  @endpoint = endpoint
12
- @graph_name = graph_name
12
+ @graph_name = options[:graph_name] || ''
13
+ @read_timeout = options[:read_timeout] || 120
14
+ @logger = options[:logger] || Solis::LOGGER
13
15
 
14
16
  @pool = ConnectionPool.new(size:5, timeout: 160) do
15
- SPARQL::Client.new(@endpoint, graph: @graph_name)
16
- #SPARQL::Client.new(@endpoint)
17
+ Solis::LOGGER.level = Logger::DEBUG if ConfigFile[:debug]
18
+
19
+ if @graph_name
20
+ client = SPARQL::Client.new(@endpoint, graph: @graph_name, read_timeout: @read_timeout, logger: @logger)
21
+ else
22
+ client = SPARQL::Client.new(@endpoint, read_timeout: @read_timeout, logger: @logger)
23
+ end
24
+
25
+ client
17
26
  end
18
27
  end
19
28
 
data/lib/solis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Solis
2
- VERSION = "0.93.0"
2
+ VERSION = "0.96.0"
3
3
  end
data/solis.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_runtime_dependency 'activesupport', '~> 8.0'
31
31
  spec.add_runtime_dependency 'http', '~> 5.2'
32
- spec.add_runtime_dependency 'graphiti', '~> 1.7'
32
+ spec.add_runtime_dependency 'graphiti', '~> 1.8'
33
33
  spec.add_runtime_dependency 'moneta', '~> 1.6'
34
34
  spec.add_runtime_dependency 'linkeddata', '~> 3.3'
35
35
  spec.add_runtime_dependency 'google_drive', '~> 3.0'
@@ -40,9 +40,9 @@ Gem::Specification.new do |spec|
40
40
  spec.add_runtime_dependency 'uuidtools', '~> 2.2.0'
41
41
  spec.add_runtime_dependency 'dry-struct', '~> 1.6'
42
42
  spec.add_runtime_dependency 'psych', '~> 5.1'
43
- spec.add_runtime_dependency 'csv'
44
- spec.add_runtime_dependency 'mutex_m'
45
- spec.add_runtime_dependency 'ostruct'
43
+ spec.add_runtime_dependency 'csv', '~> 3.2'
44
+ spec.add_runtime_dependency 'mutex_m', '~> 0.1'
45
+ spec.add_runtime_dependency 'ostruct', '~> 0.5'
46
46
  # spec.add_runtime_dependency 'rdf-edtf', '~> 1.1.2'
47
47
 
48
48
  spec.add_development_dependency 'rake', '~> 13.0'
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.93.0
4
+ version: 0.96.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.7'
46
+ version: '1.8'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '1.7'
53
+ version: '1.8'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: moneta
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -195,44 +195,44 @@ dependencies:
195
195
  name: csv
196
196
  requirement: !ruby/object:Gem::Requirement
197
197
  requirements:
198
- - - ">="
198
+ - - "~>"
199
199
  - !ruby/object:Gem::Version
200
- version: '0'
200
+ version: '3.2'
201
201
  type: :runtime
202
202
  prerelease: false
203
203
  version_requirements: !ruby/object:Gem::Requirement
204
204
  requirements:
205
- - - ">="
205
+ - - "~>"
206
206
  - !ruby/object:Gem::Version
207
- version: '0'
207
+ version: '3.2'
208
208
  - !ruby/object:Gem::Dependency
209
209
  name: mutex_m
210
210
  requirement: !ruby/object:Gem::Requirement
211
211
  requirements:
212
- - - ">="
212
+ - - "~>"
213
213
  - !ruby/object:Gem::Version
214
- version: '0'
214
+ version: '0.1'
215
215
  type: :runtime
216
216
  prerelease: false
217
217
  version_requirements: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - ">="
219
+ - - "~>"
220
220
  - !ruby/object:Gem::Version
221
- version: '0'
221
+ version: '0.1'
222
222
  - !ruby/object:Gem::Dependency
223
223
  name: ostruct
224
224
  requirement: !ruby/object:Gem::Requirement
225
225
  requirements:
226
- - - ">="
226
+ - - "~>"
227
227
  - !ruby/object:Gem::Version
228
- version: '0'
228
+ version: '0.5'
229
229
  type: :runtime
230
230
  prerelease: false
231
231
  version_requirements: !ruby/object:Gem::Requirement
232
232
  requirements:
233
- - - ">="
233
+ - - "~>"
234
234
  - !ruby/object:Gem::Version
235
- version: '0'
235
+ version: '0.5'
236
236
  - !ruby/object:Gem::Dependency
237
237
  name: rake
238
238
  requirement: !ruby/object:Gem::Requirement
@@ -294,6 +294,7 @@ files:
294
294
  - lib/solis/error/query_error.rb
295
295
  - lib/solis/graph.rb
296
296
  - lib/solis/model.rb
297
+ - lib/solis/model.rb.ok
297
298
  - lib/solis/options.rb
298
299
  - lib/solis/query.rb
299
300
  - lib/solis/query/construct.rb
@@ -335,7 +336,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
335
336
  - !ruby/object:Gem::Version
336
337
  version: '0'
337
338
  requirements: []
338
- rubygems_version: 3.7.1
339
+ rubygems_version: 3.7.2
339
340
  specification_version: 4
340
341
  summary: Turn any SHACL file into an API, ORM, documentation, ...
341
342
  test_files: []