Class: SHACL::Format

Inherits:
RDF::Format
  • Object
show all
Defined in:
lib/shacl/format.rb

Overview

SHACL format specification. Note that this format does not define any readers or writers.

Examples:

Obtaining an ShEx format class

RDF::Format.for(:shacl)           #=> ShEx::Format

Class Method Summary collapse

Class Method Details

.cli_commandsHash{Symbol => Lambda(Array, Hash)}

Hash of CLI commands appropriate for this format

Returns:

  • (Hash{Symbol => Lambda(Array, Hash)})


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/shacl/format.rb', line 13

def self.cli_commands
  {
    shacl: {
      description: "Validate repository given shape",
      help: %(shacl [--shape URI] [--focus Resource] [--replace]

        Evaluates the repository according the the specified shapes.
        If no shape file is specified, it will look for one or more
        shapes graphs using the sh:shapesGraph property found within
        the repository.
        ).gsub(/^\s+/, ''),
      parse: true,
      lambda: -> (argv, **options) do
        shacl = case options[:shape]
        when IO, StringIO
          SHACL.get_shapes(RDF::Reader.new(options[:shape]), **options)
        when nil
          SHACL.from_queryable(RDF::CLI.repository, **options)
        else SHACL.open(options[:shape], **options)
        end

        if options[:to_sxp]
          options[:messages][:shacl] = {}
          options[:messages][:shacl].merge!({"S-Expression": [SXP::Generator.string(shacl.to_sxp_bin)]})
        else
          start = Time.now
          report = shacl.execute(RDF::CLI.repository, **options)
          secs = Time.new - start
          options[:logger].info "SHACL resulted in #{report.conform? ? 'success' : 'failure'} including #{report.count} results."
          options[:logger].info "Validated in #{secs} seconds."
          options[:messages][:shacl] = {result: report.conform? ? "Satisfied shape" : "Did not satisfy shape"}
          if report.conform?
            options[:messages][:shacl] = {result: ["Satisfied shape"]}
          else
            RDF::CLI.repository << report
            options[:messages][:shacl] = {result: ["Did not satisfy shape: #{report.count} results"]}
            options[:messages].merge!(report.linter_messages)
          end
        end
        RDF::CLI.repository
      end,
      options: [
        RDF::CLI::Option.new(
          symbol: :focus,
          datatype: String,
          control: :text,
          on: ["--focus Resource"],
          description: "Focus node within repository"
        ) {|v| RDF::URI(v)},
        RDF::CLI::Option.new(
          symbol: :replace,
          datatype: TrueClass,
          control: :checkbox,
          on: ["--replace"],
          description: "Replaces the data graph with the validation report"
        ) {|v| RDF::URI(v)},
        RDF::CLI::Option.new(
          symbol: :shape,
          datatype: String,
          control: :url2,
          on: ["--shape URI"],
          description: "SHACL shapes graph location"
        ) {|v| RDF::URI(v)},
        RDF::CLI::Option.new(
          symbol: :to_sxp,
          datatype: String,
          control: :checkbox,
          on: ["--to-sxp"],
          description: "Display parsed shapes as an S-Expression"
        ),
      ]
    }
  }
end