Class: Glossarist::Validation::ShaclValidator
- Inherits:
-
Object
- Object
- Glossarist::Validation::ShaclValidator
- Defined in:
- lib/glossarist/validation/shacl_validator.rb
Overview
Validates Turtle output against SHACL shapes.
Shapes resolution order:
1. Explicit :shapes_path option
2. Vendored shapes at data/concept-model/shapes/glossarist.shacl.ttl
(shipped with the gem, relative to the gem root)
Constant Summary collapse
- VENDORED_SHAPES_PATH =
File.( "../../../data/concept-model/shapes/glossarist.shacl.ttl", __dir__ ).freeze
Instance Attribute Summary collapse
-
#shapes_path ⇒ Object
readonly
Returns the value of attribute shapes_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(shapes_path: nil) ⇒ ShaclValidator
constructor
A new instance of ShaclValidator.
- #validate_files(paths) ⇒ Object
- #validate_graphs(graphs) ⇒ Object
Constructor Details
#initialize(shapes_path: nil) ⇒ ShaclValidator
Returns a new instance of ShaclValidator.
24 25 26 |
# File 'lib/glossarist/validation/shacl_validator.rb', line 24 def initialize(shapes_path: nil) @shapes_path = shapes_path || self.class.default_shapes_path end |
Instance Attribute Details
#shapes_path ⇒ Object (readonly)
Returns the value of attribute shapes_path.
22 23 24 |
# File 'lib/glossarist/validation/shacl_validator.rb', line 22 def shapes_path @shapes_path end |
Class Method Details
.default_shapes_path ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/glossarist/validation/shacl_validator.rb', line 47 def default_shapes_path return VENDORED_SHAPES_PATH if File.exist?(VENDORED_SHAPES_PATH) raise ArgumentError, "No SHACL shapes path provided and the vendored shapes " \ "file (#{VENDORED_SHAPES_PATH}) is missing. Pass " \ "shapes_path: '/path/to/glossarist.shacl.ttl'." end |
Instance Method Details
#validate_files(paths) ⇒ Object
28 29 30 |
# File 'lib/glossarist/validation/shacl_validator.rb', line 28 def validate_files(paths) validate_graphs(Array(paths).map { |p| load_graph(p) }) end |
#validate_graphs(graphs) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/glossarist/validation/shacl_validator.rb', line 32 def validate_graphs(graphs) shapes = SHACL::Shapes.from_graph(load_graph(@shapes_path)) failures = [] graphs.each do |graph| report = shapes.execute(graph) next if report.conform? failures << Report.new(results: report.results) end AggregateReport.new(failures: failures) end |