Class: SHACL::ValidationResult
- Inherits:
-
Struct
- Object
- Struct
- SHACL::ValidationResult
- Includes:
- RDF::Enumerable
- Defined in:
- lib/shacl/validation_result.rb
Overview
A SHACL [Validateion Result](www.w3.org/TR/shacl/#results-validation-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.
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| ... } ⇒ void
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
Constructor Details
#initialize(*args) ⇒ ValidationResult
Initializer calculates lexical values for URIs
27 28 29 30 31 32 33 34 35 36 |
# File '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 |
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component
12 13 14 |
# File 'lib/shacl/validation_result.rb', line 12 def component @component end |
#details ⇒ Object
Returns the value of attribute details
12 13 14 |
# File 'lib/shacl/validation_result.rb', line 12 def details @details end |
#focus ⇒ Object
Returns the value of attribute focus
12 13 14 |
# File 'lib/shacl/validation_result.rb', line 12 def focus @focus end |
#message ⇒ Object
Returns the value of attribute message
12 13 14 |
# File 'lib/shacl/validation_result.rb', line 12 def end |
#path ⇒ Object
Returns the value of attribute path
12 13 14 |
# File 'lib/shacl/validation_result.rb', line 12 def path @path end |
#resultSeverity ⇒ Object
Returns the value of attribute resultSeverity
12 13 14 |
# File 'lib/shacl/validation_result.rb', line 12 def resultSeverity @resultSeverity end |
#shape ⇒ Object
Returns the value of attribute shape
12 13 14 |
# File 'lib/shacl/validation_result.rb', line 12 def shape @shape end |
#value ⇒ Object
Returns the value of attribute value
12 13 14 |
# File '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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/shacl/validation_result.rb', line 121 def self.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
143 144 145 146 147 148 149 150 |
# File 'lib/shacl/validation_result.rb', line 143 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 'lib/shacl/validation_result.rb', line 41 def conform? resultSeverity.nil? end |
#each {|statement| ... } ⇒ void
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 '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
153 154 155 |
# File 'lib/shacl/validation_result.rb', line 153 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 '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 'lib/shacl/validation_result.rb', line 75 def to_s "Result for: " + i(value focus path shape resultSeverity component details ).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 '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 'lib/shacl/validation_result.rb', line 46 def to_sxp_bin i(value focus path shape resultSeverity component details ).inject([:ValidationResult]) do |memo, sym| v = self.send(sym) v ? (memo + [[sym, *v]]) : memo end.to_sxp_bin end |