solis 0.83.0 → 0.84.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 +4 -4
- data/lib/solis/config_file.rb +1 -1
- data/lib/solis/model.rb +25 -2
- data/lib/solis/query.rb +9 -0
- data/lib/solis/shape/reader/sheet.rb +35 -1
- data/lib/solis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2980fd83ee3bd59017c9831136d40f24402c80c3591578b27d3cc03ad132b90
|
4
|
+
data.tar.gz: 248019990f65b20f0bfb2b605f868c2658b002e02db3c5a61a7657d83e071bd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 720dd30ae84033d977cf04f6d6736745f24d8b32b06b3dedd01e09c05d5f72726a6ee2f2c74249ea8e87bc1bde8daf9bd2fe810bf139dc8d48e8ff70c7dd611d
|
7
|
+
data.tar.gz: 82855397f33cf99f61f6a7d53b3939035305f0570b2ee7965ca353402891d6b752351d19c414c2a3ee74bda22e7774a3f70f7d223b2f974c0c227610307e41a1
|
data/lib/solis/config_file.rb
CHANGED
data/lib/solis/model.rb
CHANGED
@@ -485,8 +485,31 @@ values ?s {<#{self.graph_id}>}
|
|
485
485
|
def make_graph(graph, hierarchy, id, klass, klass_metadata, resolve_all)
|
486
486
|
klass_metadata[:attributes].each do |attribute, metadata|
|
487
487
|
data = klass.instance_variable_get("@#{attribute}")
|
488
|
-
|
489
|
-
|
488
|
+
|
489
|
+
if data.nil? && metadata.key?(:mincount) && ( metadata[:mincount].nil? || metadata[:mincount] > 0) && graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
|
490
|
+
if data.nil?
|
491
|
+
uuid = id.value.split('/').last
|
492
|
+
original_klass = klass.query.filter({ filters: { id: [ uuid ] } }).find_all { |f| f.id == uuid }.first || nil
|
493
|
+
unless original_klass.nil?
|
494
|
+
klass = original_klass
|
495
|
+
data = klass.instance_variable_get("@#{attribute}")
|
496
|
+
end
|
497
|
+
end
|
498
|
+
#if data is still nil
|
499
|
+
raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}~#{klass.name}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}" if data.nil?
|
500
|
+
end
|
501
|
+
|
502
|
+
if data.nil? && metadata.key?(:maxcount) && ( metadata[:maxcount].nil? || metadata[:maxcount] > 0) && graph.query(RDF::Query.new({ attribute.to_sym => { RDF.type => metadata[:node] } })).size == 0
|
503
|
+
if data.nil?
|
504
|
+
uuid = id.value.split('/').last
|
505
|
+
original_klass = klass.query.filter({ filters: { id: [ uuid ] } }).find_all { |f| f.id == uuid }.first || nil
|
506
|
+
unless original_klass.nil?
|
507
|
+
klass = original_klass
|
508
|
+
data = klass.instance_variable_get("@#{attribute}")
|
509
|
+
end
|
510
|
+
end
|
511
|
+
#if data is still nil
|
512
|
+
raise Solis::Error::InvalidAttributeError, "#{hierarchy.join('.')}~#{klass.name}.#{attribute} min=#{metadata[:mincount]} and max=#{metadata[:maxcount]}" if data.nil?
|
490
513
|
end
|
491
514
|
|
492
515
|
# skip if nil or an object that is empty
|
data/lib/solis/query.rb
CHANGED
@@ -267,6 +267,11 @@ PREFIX #{@model.class.graph_prefix}: <#{@model.class.graph_name}>"
|
|
267
267
|
record_uri = statement.s.value
|
268
268
|
attribute = statement.p.value.split('/').last.underscore
|
269
269
|
|
270
|
+
unless solution_model.metadata[:attributes].key?(attribute)
|
271
|
+
Solis::LOGGER.error "Attribute found in data that is not part of the model model #{solution_model.name}(#{record_uri.split('/').last}).#{attribute}"
|
272
|
+
next
|
273
|
+
end
|
274
|
+
|
270
275
|
if statement.o.valid?
|
271
276
|
if statement.o.is_a?(RDF::URI)
|
272
277
|
object = statement.o.canonicalize.value
|
@@ -335,6 +340,10 @@ PREFIX #{@model.class.graph_prefix}: <#{@model.class.graph_name}>"
|
|
335
340
|
end
|
336
341
|
end
|
337
342
|
rescue StandardError => e
|
343
|
+
unless solution_model.metadata[:attributes].key?(attribute)
|
344
|
+
Solis::LOGGER.error("#{record_uri} - graph_to_object - #{attribute} - #{e.message}")
|
345
|
+
raise "'#{attribute}' not in model"
|
346
|
+
end
|
338
347
|
puts e.backtrace.first
|
339
348
|
Solis::LOGGER.error("#{record_uri} - graph_to_object - #{attribute} - #{e.message}")
|
340
349
|
g = RDF::Graph.new
|
@@ -472,6 +472,38 @@ hide empty members
|
|
472
472
|
puts e.message
|
473
473
|
end
|
474
474
|
|
475
|
+
def build_json_schema(shacl_file)
|
476
|
+
graph = RDF::Graph.load(StringIO.new(shacl_file), format: :ttl)
|
477
|
+
json_schema = {
|
478
|
+
"$schema" => "http://json-schema.org/draft-07/schema#",
|
479
|
+
"type" => "object",
|
480
|
+
"properties" => {},
|
481
|
+
"required" => []
|
482
|
+
}
|
483
|
+
|
484
|
+
graph.query([nil, RDF.type, SHACL.NodeShape]) do |shape|
|
485
|
+
shape_subject = shape.subject
|
486
|
+
|
487
|
+
graph.query([shape_subject, SHACL.property, nil]) do |prop_stmt|
|
488
|
+
prop_subject = prop_stmt.object
|
489
|
+
prop_name = graph.query([prop_subject, SHACL.path, nil]).first&.object.to_s
|
490
|
+
datatype = graph.query([prop_subject, SHACL.datatype, nil]).first&.object
|
491
|
+
min_count = graph.query([prop_subject, SHACL.minCount, nil]).first&.object&.to_i
|
492
|
+
max_count = graph.query([prop_subject, SHACL.maxCount, nil]).first&.object&.to_i
|
493
|
+
pattern = graph.query([prop_subject, SHACL.pattern, nil]).first&.object&.to_s
|
494
|
+
|
495
|
+
json_schema["properties"][prop_name] = {}
|
496
|
+
json_schema["properties"][prop_name]["type"] = datatype.to_s.split("#").last.downcase if datatype
|
497
|
+
json_schema["properties"][prop_name]["pattern"] = pattern if pattern
|
498
|
+
|
499
|
+
json_schema["required"] << prop_name if min_count && min_count > 0
|
500
|
+
json_schema["properties"][prop_name]["maxItems"] = max_count if max_count
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
JSON.pretty_generate(json_schema)
|
505
|
+
end
|
506
|
+
|
475
507
|
def every_entity(data)
|
476
508
|
all_references = []
|
477
509
|
graph_prefix = data[:ontologies][:base][:prefix]
|
@@ -658,8 +690,10 @@ hide empty members
|
|
658
690
|
schema = build_schema(datas)
|
659
691
|
Solis::LOGGER.info('Generating INFLECTIONS')
|
660
692
|
inflections = build_inflections(datas)
|
693
|
+
Solis::LOGGER.info('Generating JSON SCHEMA')
|
694
|
+
json_schema = build_json_schema(shacl)
|
661
695
|
|
662
|
-
{ inflections: inflections, shacl: shacl, schema: schema, plantuml: plantuml }
|
696
|
+
{ inflections: inflections, shacl: shacl, schema: schema, plantuml: plantuml, json_schema: json_schema }
|
663
697
|
end
|
664
698
|
end
|
665
699
|
end
|
data/lib/solis/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.84.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Celik
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-24 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|