Class: SHACL::ValidationResult
- Includes:
- RDF::Enumerable
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb
Overview
A SHACL Validateion Result.
Also allows for a successful result, if the resultSeverity
nil
.
Instance Attribute Summary collapse
-
#component ⇒ Object
Returns the value of attribute component.
-
#details ⇒ Object
Returns the value of attribute details.
-
#focus ⇒ Object
Returns the value of attribute focus.
-
#message ⇒ Object
Returns the value of attribute message.
-
#path ⇒ Object
Returns the value of attribute path.
-
#resultSeverity ⇒ Object
Returns the value of attribute resultSeverity.
-
#shape ⇒ Object
Returns the value of attribute shape.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes included from RDF::Enumerable
Class Method Summary collapse
-
.from_json(input, **options) ⇒ ValidationResult
Transform a JSON representation of a result, into a native representation.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
To results are eql? if their overlapping properties are equal.
-
#conform? ⇒ Boolean
(also: #conforms?)
A result conforms if it is not a violation.
-
#each {|statement| ... }
Yields statements for this result.
-
#initialize(*args) ⇒ ValidationResult
constructor
Initializer calculates lexical values for URIs.
-
#inspect ⇒ Object
Inspect as SXP.
-
#linter_message ⇒ Hash{Symbol => Hash{Symbol => Array<String>}}
Create a hash of messages appropriate for linter-like output.
-
#to_s ⇒ Object
Some humanized result for the report.
-
#to_sxp(**options) ⇒ String
Transform ValidationResult to SXP.
- #to_sxp_bin ⇒ Object
Methods included from RDF::Enumerable
add_entailment, #canonicalize, #canonicalize!, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #entail, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph?, #graph_names, #invalid?, #method_missing, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #respond_to_missing?, #statement?, #statements, #subject?, #subjects, #supports?, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!
Methods included from RDF::Util::Aliasing::LateBound
Methods included from RDF::Isomorphic
#bijection_to, #isomorphic_with?
Methods included from RDF::Countable
Constructor Details
#initialize(*args) ⇒ ValidationResult
Initializer calculates lexical values for URIs
27 28 29 30 31 32 33 34 35 36 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 27 def initialize(*args) args = args.map do |v| if v.respond_to?(:qname) && !v.lexical && v.qname v = RDF::URI.new(v.to_s) if v.frozen? v.lexical = v.qname.join(':') end v end super(*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RDF::Enumerable
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def component @component end |
#details ⇒ Object
Returns the value of attribute details
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def details @details end |
#focus ⇒ Object
Returns the value of attribute focus
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def focus @focus end |
#message ⇒ Object
Returns the value of attribute message
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def @message end |
#path ⇒ Object
Returns the value of attribute path
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def path @path end |
#resultSeverity ⇒ Object
Returns the value of attribute resultSeverity
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def resultSeverity @resultSeverity end |
#shape ⇒ Object
Returns the value of attribute shape
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def shape @shape end |
#value ⇒ Object
Returns the value of attribute value
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 12 def value @value end |
Class Method Details
.from_json(input, **options) ⇒ ValidationResult
Transform a JSON representation of a result, into a native representation
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 123 def from_json(input, **) input = JSON.parse(input) if input.is_a?(String) input = JSON::LD::API.compact(input, "http://github.com/ruby-rdf/shacl/", expandContext: "http://github.com/ruby-rdf/shacl/") raise ArgumentError, "Expect report to be a hash" unless input.is_a?(Hash) result = self.new result.focus = Algebra::Operator.to_rdf(:focus, input['focusNode'], base: nil, vocab: false) if input['focusNode'] result.path = Algebra::Operator.parse_path(input['resultPath'], **) if input['resultPath'] result.resultSeverity = Algebra::Operator.iri(input['resultSeverity'], **) if input['resultSeverity'] result.component = Algebra::Operator.iri(input['sourceConstraintComponent'], **) if input['sourceConstraintComponent'] result.shape = Algebra::Operator.iri(input['sourceShape'], **) if input['sourceShape'] result.value = Algebra::Operator.to_rdf(:value, input['value'], **) if input['value'] result.details = Algebra::Operator.to_rdf(:details, input['details'], **) if input['details'] result. = Algebra::Operator.to_rdf(:message, input['message'], **) if input['message'] result end |
Instance Method Details
#==(other) ⇒ Boolean
To results are eql? if their overlapping properties are equal
146 147 148 149 150 151 152 153 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 146 def ==(other) return false unless other.is_a?(ValidationResult) %i(focus path resultSeverity component shape value).all? do |prop| ours = self.send(prop) theirs = other.send(prop) theirs.nil? || (ours && ours.node? && theirs.node?) || ours && ours.eql?(theirs) end end |
#conform? ⇒ Boolean Also known as: conforms?
A result conforms if it is not a violation
41 42 43 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 41 def conform? resultSeverity.nil? end |
#each {|statement| ... }
This method returns an undefined value.
Yields statements for this result
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 98 def each(&block) subject = RDF::Node.new block.call(RDF::Statement(subject, RDF.type, RDF::Vocab::SHACL.ValidationResult)) block.call(RDF::Statement(subject, RDF::Vocab::SHACL.focusNode, focus)) if focus case path when RDF::URI block.call(RDF::Statement(subject, RDF::Vocab::SHACL.resultPath, path)) when SPARQL::Algebra::Expression path.each_statement(&block) block.call(RDF::Statement(subject, RDF::Vocab::SHACL.resultPath, path.subject)) end block.call(RDF::Statement(subject, RDF::Vocab::SHACL.resultSeverity, resultSeverity)) if resultSeverity block.call(RDF::Statement(subject, RDF::Vocab::SHACL.sourceConstraintComponent, component)) if component block.call(RDF::Statement(subject, RDF::Vocab::SHACL.sourceShape, shape)) if shape block.call(RDF::Statement(subject, RDF::Vocab::SHACL.value, value)) if value block.call(RDF::Statement(subject, RDF::Vocab::SHACL.detail, RDF::Literal(details))) if details block.call(RDF::Statement(subject, RDF::Vocab::SHACL.resultMessage, RDF::Literal())) if end |
#inspect ⇒ Object
Inspect as SXP
156 157 158 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 156 def inspect SXP::Generator.string to_sxp_bin end |
#linter_message ⇒ Hash{Symbol => Hash{Symbol => Array<String>}}
Create a hash of messages appropriate for linter-like output.
65 66 67 68 69 70 71 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 65 def case when path then {path: {path.to_sxp => [to_s]}} when focus then {focus: {focus.to_sxp => [to_s]}} else {shape: {shape.to_sxp => [to_s]}} end end |
#to_s ⇒ Object
Some humanized result for the report
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 75 def to_s "Result for: " + %i(value focus path shape resultSeverity component details message).map do |sym| v = self.send(sym) if v.respond_to?(:humanize) v.humanize elsif v.respond_to?(:lexical) v.lexical else v.to_sxp end (sym == :value ? v.to_sxp : "#{sym}: #{v.to_sxp}") if v end.compact.join("\n ") end |
#to_sxp(**options) ⇒ String
Transform ValidationResult to SXP
57 58 59 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 57 def to_sxp(**) self.to_sxp_bin.to_sxp(**) end |
#to_sxp_bin ⇒ Object
46 47 48 49 50 51 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_result.rb', line 46 def to_sxp_bin %i(value focus path shape resultSeverity component details message).inject([:ValidationResult]) do |memo, sym| v = self.send(sym) v ? (memo + [[sym, *v]]) : memo end.to_sxp_bin end |