Class: SHACL::ValidationReport

Inherits:
Object
  • Object
show all
Includes:
RDF::Enumerable
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb

Overview

A SHACL Validateion Report.

Collects the individual ValidationResult instances and provides a conforms boolean accessor.

Allows the report to be serialized as a set of RDF Statements

Instance Attribute Summary collapse

Attributes included from RDF::Enumerable

#existentials, #universals

Instance Method Summary collapse

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

#alias_method

Methods included from RDF::Isomorphic

#bijection_to, #isomorphic_with?

Methods included from RDF::Countable

#empty?

Constructor Details

#initialize(results) ⇒ ValidationReport

Creates a report from the set of results

Parameters:



27
28
29
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 27

def initialize(results)
  @all_results = Array(results)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Enumerable

Instance Attribute Details

#all_resultsObject (readonly)

All results, both conforming and non-conforming



20
21
22
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 20

def all_results
  @all_results
end

Instance Method Details

#==(other) ⇒ Boolean

Two reports are eq if they have the same number of results and each result equals a result in the other report.

Parameters:

Returns:

  • (Boolean)


78
79
80
81
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 78

def ==(other)
  return false unless other.is_a?(ValidationReport)
  count == other.count && other.results.all? {|r| results.include?(r)}
end

#conform?Boolean

Do the individual results indicate conformance?

Returns:

  • (Boolean)


51
52
53
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 51

def conform?
  results.empty?
end

#countInteger

The number of non-conforming results

Returns:



43
44
45
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 43

def count
  results.length
end

#each {|statement| ... }

This method returns an undefined value.

Yields statements for this report

Yields:

  • (statement)

    each statement

Yield Parameters:

Yield Returns:

  • (void)

    ignored



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 99

def each(&block)
  subject = RDF::Node.new
  block.call(RDF::Statement(subject, RDF.type, RDF::Vocab::SHACL.ValidationReport))
  block.call(RDF::Statement(subject, RDF::Vocab::SHACL.conforms, RDF::Literal(conform?)))
  results.each do |result|
    result_subject = nil
    result.each do |statement|
      result_subject ||= statement.subject
      yield(statement)
    end
    yield(RDF::Statement(subject, RDF::Vocab::SHACL.result, result_subject))
  end
end

#linter_messagesHash{Symbol => Hash{Symbol => Array<String>}}

Create a hash of messages appropriate for linter-like output.

Returns:



87
88
89
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 87

def linter_messages
  results.inject({}) {|memo, result| memo.deep_merge(result.linter_message)}
end

#resultsArray<ValidationResult>

The non-conforming results

Returns:



35
36
37
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 35

def results
  @all_results.reject(&:conform?)
end

#to_sObject



70
71
72
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 70

def to_s
  results.map(&:to_s).join("\n")
end

#to_sxp(**options) ⇒ String

Transform Report to SXP

Returns:



66
67
68
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 66

def to_sxp(**options)
  self.to_sxp_bin.to_sxp(**options)
end

#to_sxp_binObject

The number of results



58
59
60
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/validation_report.rb', line 58

def to_sxp_bin
  [:ValidationReport, conform?, results].to_sxp_bin
end