solis 0.64.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +6 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +287 -0
  8. data/Rakefile +10 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/examples/after_hooks.rb +24 -0
  12. data/examples/config.yml.template +15 -0
  13. data/examples/read_from_shacl.rb +22 -0
  14. data/examples/read_from_shacl_abv.rb +84 -0
  15. data/examples/read_from_sheet.rb +22 -0
  16. data/lib/solis/config_file.rb +91 -0
  17. data/lib/solis/error/cursor_error.rb +6 -0
  18. data/lib/solis/error/general_error.rb +6 -0
  19. data/lib/solis/error/invalid_attribute_error.rb +6 -0
  20. data/lib/solis/error/invalid_datatype_error.rb +6 -0
  21. data/lib/solis/error/not_found_error.rb +6 -0
  22. data/lib/solis/error/query_error.rb +6 -0
  23. data/lib/solis/error.rb +3 -0
  24. data/lib/solis/graph.rb +360 -0
  25. data/lib/solis/model.rb +565 -0
  26. data/lib/solis/options.rb +19 -0
  27. data/lib/solis/query/construct.rb +93 -0
  28. data/lib/solis/query/filter.rb +133 -0
  29. data/lib/solis/query/run.rb +97 -0
  30. data/lib/solis/query.rb +347 -0
  31. data/lib/solis/resource.rb +37 -0
  32. data/lib/solis/shape/data_types.rb +280 -0
  33. data/lib/solis/shape/reader/csv.rb +12 -0
  34. data/lib/solis/shape/reader/file.rb +16 -0
  35. data/lib/solis/shape/reader/sheet.rb +777 -0
  36. data/lib/solis/shape/reader/simple_sheets/sheet.rb +59 -0
  37. data/lib/solis/shape/reader/simple_sheets/worksheet.rb +173 -0
  38. data/lib/solis/shape/reader/simple_sheets.rb +40 -0
  39. data/lib/solis/shape.rb +189 -0
  40. data/lib/solis/sparql_adaptor.rb +318 -0
  41. data/lib/solis/store/sparql/client/query.rb +35 -0
  42. data/lib/solis/store/sparql/client.rb +41 -0
  43. data/lib/solis/version.rb +3 -0
  44. data/lib/solis.rb +13 -0
  45. data/solis.gemspec +50 -0
  46. metadata +304 -0
@@ -0,0 +1,280 @@
1
+ require 'iso8601'
2
+ require 'dry-struct'
3
+
4
+ # Graphiti::Types[:year] = {
5
+ # canonical_name: :year,
6
+ # params: Graphiti::Types.create(::Integer) { |input|
7
+ # Dry::Types["coercible.integer"][input]
8
+ # },
9
+ # read: Graphiti::Types.create(::Integer) { |input|
10
+ # Dry::Types["coercible.integer"][input] if input
11
+ # },
12
+ # write: Graphiti::Types.create(::Integer) { |input|
13
+ # Dry::Types["coercible.integer"][input] if input
14
+ # },
15
+ # kind: "scalar",
16
+ # description: "contains only the year of a date"
17
+ # }
18
+
19
+ Graphiti::Types[:array_of_years] = {
20
+ canonical_name: :year,
21
+ params: Dry::Types["strict.array"].of(Graphiti::Types.create(::Integer) { |input|
22
+ Dry::Types["coercible.integer"][input || 0]
23
+ }),
24
+ read: Dry::Types["strict.array"].of(Graphiti::Types.create(::Integer) { |input|
25
+ Dry::Types["coercible.integer"][input || 0] if input
26
+ }),
27
+ write: Dry::Types["strict.array"].of(Graphiti::Types.create(::Integer) { |input|
28
+ Dry::Types["coercible.integer"][input || 0] if input
29
+ }),
30
+ kind: "array",
31
+ description: "contains a list of the year of a date"
32
+ }
33
+
34
+ Graphiti::Types[:double] = {
35
+ canonical_name: :double,
36
+ params: Graphiti::Types.create(::Float) { |input|
37
+ Dry::Types["coercible.float"][input]
38
+ },
39
+ read: Graphiti::Types.create(::Float) { |input|
40
+ Dry::Types["coercible.float"][input] if input
41
+ },
42
+ write: Graphiti::Types.create(::Float) { |input|
43
+ Dry::Types["coercible.float"][input] if input
44
+ },
45
+ kind: "scalar",
46
+ description: "double type"
47
+ }
48
+
49
+ Graphiti::Types[:time] = {
50
+ canonical_name: :time,
51
+ params: Graphiti::Types::PresentParamsDateTime,
52
+ read: Graphiti::Types::ReadDateTime,
53
+ write: Graphiti::Types::WriteDateTime,
54
+ kind: "scalar",
55
+ description: "time type"
56
+ }
57
+
58
+ Graphiti::Types[:datetime] = {
59
+ canonical_name: :datetime,
60
+ params: Graphiti::Types::PresentParamsDateTime,
61
+ read: Graphiti::Types::ReadDateTime,
62
+ write: Graphiti::Types::WriteDateTime,
63
+ kind: "scalar",
64
+ description: "datetime type"
65
+ }
66
+
67
+ Graphiti::Types[:json] = {
68
+ canonical_name: :json,
69
+ params: Dry::Types["coercible.string"],
70
+ read: Graphiti::Types.create(::JSON){|i|
71
+ i = JSON.parse(i) if i.is_a?(String)
72
+
73
+ # case i
74
+ # when i.is_a?(Array)
75
+ # Dry::Types["strict.array"][i]
76
+ # when i.is_a?(Hash)
77
+ # Dry::Types["strict.hash"][i]
78
+ # end
79
+
80
+ i
81
+ },
82
+ write: Dry::Types["coercible.string"],
83
+ kind: "scalar",
84
+ description: "contains a json object"
85
+ }
86
+
87
+ duration_definition = Dry::Types['strict.string']
88
+ read_duration_type = duration_definition.constructor do |i|
89
+ if i.is_a?(Array)
90
+ (i[0].send(:months) + i[1].send(:seconds)).iso8601
91
+ elsif i.is_a?(Float) || i.is_a?(Integer)
92
+ ActiveSupport::Duration.build(i).iso8601
93
+ end
94
+ #ActiveSupport::Duration.parse(i[0]) if i.is_a?(String)
95
+ end
96
+
97
+ write_duration_type = duration_definition.constructor do |i|
98
+ if i.is_a?(String)
99
+ ActiveSupport::Duration.parse(i).iso8601
100
+ else
101
+ ActiveSupport::Duration.build(i&.to_i || 0).iso8601
102
+ end
103
+ end
104
+
105
+ Graphiti::Types[:duration] = {
106
+ canonical_name: :duration,
107
+ params: read_duration_type,
108
+ read: read_duration_type,
109
+ write: write_duration_type,
110
+ kind: "scalar",
111
+ description: "contains ISO8601 Duration"
112
+ }
113
+
114
+ Graphiti::Types[:array_of_durations] = {
115
+ canonical_name: :duration,
116
+ params: Dry::Types["strict.array"].of(Graphiti::Types[:duration]),
117
+ read: Dry::Types["strict.array"].of(Graphiti::Types[:duration]),
118
+ write: Dry::Types["strict.array"].of(Graphiti::Types[:duration]),
119
+ kind: "array",
120
+ description: "contains a list of durations"
121
+ }
122
+
123
+
124
+ write_year = Graphiti::Types.create(:Year) do |i|
125
+ input = RDF::Literal::Year.new(i)
126
+ raise Graphiti::Errors::InvalidType unless input.valid?
127
+ Dry::Types["strict.date"][input.object] if input
128
+ end
129
+
130
+ read_year = Graphiti::Types.create(:Year) do |i|
131
+ if i.is_a?(RDF::Literal::Year)
132
+ input = i
133
+ else
134
+ input = RDF::Literal::Year.new(i)
135
+ end
136
+
137
+ raise Graphiti::Errors::InvalidType unless input.valid?
138
+ Dry::Types["strict.date"][input.object] if input
139
+ end
140
+
141
+ present_year = Graphiti::Types.create(:Year) do |i|
142
+ input = i.object
143
+ Dry::Types["strict.date"][input]
144
+ end
145
+
146
+ Graphiti::Types[:year] = {
147
+ canonical_name: :year,
148
+ params: present_year,
149
+ read: read_year,
150
+ write: write_year,
151
+ kind: "scalar",
152
+ description: "contains only the year of a date"
153
+ }
154
+
155
+ datetime_interval_definition = Dry::Types['strict.string']
156
+ read_datetime_interval_type = datetime_interval_definition.constructor do |i|
157
+ if i.is_a?(Array)
158
+ i.map{|m| ISO8601::TimeInterval.parse(m).to_s }
159
+ elsif i.is_a?(String)
160
+ ISO8601::TimeInterval.parse(i).to_s
161
+ end
162
+ rescue StandardError => e
163
+ Solis::LOGGER.error(e.message)
164
+ raise Solis::Error::InvalidDatatypeError, e.message
165
+ end
166
+
167
+ write__datetime_interval_type = datetime_interval_definition.constructor do |i|
168
+ ISO8601::TimeInterval.parse(i).to_s
169
+ rescue StandardError => e
170
+ Solis::LOGGER.error(e.message)
171
+ raise Solis::Error::InvalidDatatypeError, e.message
172
+ end
173
+
174
+
175
+ Graphiti::Types[:datetime_interval] = {
176
+ canonical_name: :datetime_interval,
177
+ params: read_datetime_interval_type,
178
+ read: read_datetime_interval_type,
179
+ write: write__datetime_interval_type,
180
+ kind: "scalar",
181
+ description: "contains a time interval"
182
+ }
183
+
184
+ Graphiti::Types[:array_of_datetime_intervals] = {
185
+ canonical_name: :datetime_interval,
186
+ params: Dry::Types["strict.array"].of(Graphiti::Types[:datetime_interval][:params]),
187
+ read: Dry::Types["strict.array"].of(Graphiti::Types[:datetime_interval][:read]),
188
+ write: Dry::Types["strict.array"].of(Graphiti::Types[:datetime_interval][:write]),
189
+ kind: "array",
190
+ description: "contains a list of datetime intervals"
191
+ }
192
+
193
+ #lang_string_definition = Dry::Types['hash'].schema(:"@value" => Dry::Types['coercible.string'], :"@language" => Dry::Types['strict.string'])
194
+ lang_string_definition = Dry::Types['coercible.string']
195
+ read_lang_string_type = lang_string_definition.constructor do |i|
196
+
197
+ # i = i.symbolize_keys if i.is_a?(Hash)
198
+ # i = i.is_a?(String) ? {:"@value" => i, :"@language" => Graphiti.context[:object]&.language || 'en'} : i
199
+ #
200
+ # if i[:"@value"].is_a?(Array)
201
+ # i[:"@value"] = i[:"@value"].first
202
+ # end
203
+
204
+ i
205
+ rescue StandardError => e
206
+ i
207
+ end
208
+
209
+ write_lang_string_type = lang_string_definition.constructor do |i|
210
+ i
211
+ end
212
+
213
+ #lang_string_array_definition = Dry::Types['hash'].schema(:"@value" => Dry::Types['strict.array'], :"@language" => Dry::Types['strict.string'])
214
+ lang_string_array_definition = Dry::Types['array'].of(Dry::Types['strict.string'])
215
+ #.of(Graphiti::Types[:lang_string])
216
+ read_lang_string_array_type = lang_string_array_definition.constructor do |i|
217
+ language = Graphiti.context[:object]&.language || Solis::Options.instance.get[:language] || 'en'
218
+ # i = i.symbolize_keys if i.is_a?(Hash)
219
+ # i = i.is_a?(String) ? {:"@value" => i, :"@language" => language} : i
220
+ # i[:"@value"]=[i[:"@value"]] unless i[:"@value"].is_a?(Array)
221
+
222
+ i
223
+ rescue StandardError => e
224
+ i
225
+ end
226
+
227
+
228
+ Graphiti::Types[:lang_string] = {
229
+ canonical_name: :lang_string,
230
+ params: read_lang_string_type,
231
+ read: read_lang_string_type,
232
+ write: write_lang_string_type,
233
+ kind: "scalar",
234
+ description: "contains an object that defines a value and language"
235
+ }
236
+
237
+ Graphiti::Types[:array_of_lang_strings] = {
238
+ canonical_name: :lang_string,
239
+ params: read_lang_string_array_type, #Dry::Types["strict.array"].of(Graphiti::Types[:lang_string]),
240
+ read: read_lang_string_array_type,# Dry::Types["strict.array"].of(Graphiti::Types[:lang_string]),
241
+ write: read_lang_string_array_type, #Dry::Types["strict.array"].of(Graphiti::Types[:lang_string]),
242
+ kind: "array",
243
+ description: "contains a list of objects that defines a value and language"
244
+ }
245
+
246
+
247
+ temporal_coverage_definition = Dry::Types['strict.string']
248
+ read_temporal_coverage_type = temporal_coverage_definition.constructor do |i|
249
+ if i.is_a?(Array)
250
+ i.map{|m| ISO8601::TimeInterval.parse(m).to_s }
251
+ elsif i.is_a?(String)
252
+ ISO8601::TimeInterval.parse(i).to_s
253
+ end
254
+ rescue StandardError => e
255
+ Solis::LOGGER.error(e.message)
256
+ raise Solis::Error::InvalidDatatypeError, e.message
257
+ end
258
+
259
+ write__temporal_coverage_type = temporal_coverage_definition.constructor do |i|
260
+ i
261
+ end
262
+
263
+
264
+ Graphiti::Types[:temporal_coverage] = {
265
+ canonical_name: :temporal_coverage,
266
+ params: read_temporal_coverage_type,
267
+ read: read_temporal_coverage_type,
268
+ write: write__temporal_coverage_type,
269
+ kind: "scalar",
270
+ description: "contains a time interval"
271
+ }
272
+
273
+ Graphiti::Types[:array_of_temporal_coverages] = {
274
+ canonical_name: :temporal_coverage,
275
+ params: Dry::Types["strict.array"].of(Graphiti::Types[:temporal_coverage][:params]),
276
+ read: Dry::Types["strict.array"].of(Graphiti::Types[:temporal_coverage][:read]),
277
+ write: Dry::Types["strict.array"].of(Graphiti::Types[:temporal_coverage][:write]),
278
+ kind: "array",
279
+ description: "contains a list of temporal coverage"
280
+ }
@@ -0,0 +1,12 @@
1
+ module Solis
2
+ module Shape
3
+ module Reader
4
+ class CSV
5
+ def initialize
6
+ super
7
+ raise "TODO"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'linkeddata'
2
+
3
+ module Solis
4
+ module Shape
5
+ module Reader
6
+ class File
7
+ def self.read(filename, options = {})
8
+ @filename = filename
9
+ raise "File not found #{@filename}" unless ::File.exist?(@filename)
10
+
11
+ RDF::Graph.load(@filename, **options)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end