-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
13,626 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
repo_token: z50UjdFEZqzhCBcjNNk676SvFZP3dbWUF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This workflow runs continuous CI across different versions of ruby on all branches and pull requests to develop. | ||
|
||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ '**' ] | ||
pull_request: | ||
branches: [ develop ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
tests: | ||
name: Ruby ${{ matrix.ruby }} | ||
if: "contains(github.event.commits[0].message, '[ci skip]') == false" | ||
runs-on: ubuntu-latest | ||
env: | ||
CI: true | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ruby: | ||
- 2.4 | ||
- 2.5 | ||
- 2.6 | ||
- 2.7 | ||
#- 3.0 # until net-http-persistent is updaated | ||
#- ruby-head # until net-http-persistent is updaated | ||
- jruby | ||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v2 | ||
- name: Clone Test Suite repository | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: w3c/data-shapes | ||
path: spec/w3c-data-shapes | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
- name: Install dependencies | ||
run: bundle install --jobs 4 --retry 3 | ||
- name: Run tests | ||
run: bundle exec rspec spec | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.DS_Store | ||
.tmp | ||
.yardoc | ||
pkg | ||
tmp | ||
/*.gem | ||
/.rbx/ | ||
/doc/ | ||
Gemfile.lock | ||
.bundle/ | ||
*.sw? | ||
benchmark/ | ||
/.byebug_history | ||
/coverage/ | ||
/doc/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: ruby | ||
script: "bundle exec rspec spec" | ||
env: | ||
- CI=true | ||
rvm: | ||
- 2.5 | ||
- 2.6 | ||
- 2.7 | ||
- ruby-head | ||
- jruby | ||
cache: bundler | ||
sudo: false | ||
matrix: | ||
allow_failures: | ||
- rvm: jruby | ||
- rvm: ruby-head | ||
dist: trusty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--title "SHACL: Shapes Constraint Language (SHACL) for Ruby" | ||
--output-dir doc/yard | ||
--protected | ||
--no-private | ||
--hide-void-return | ||
--markup markdown | ||
--readme README.md | ||
- | ||
VERSION | ||
LICENSE | ||
etc/earl.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
gem 'rdf', | ||
git: 'https://github.com/ruby-rdf/rdf.git', | ||
branch: 'develop' | ||
|
||
group :development, :test do | ||
gem 'json-ld', git: 'https://github.com/ruby-rdf/json-ld.git', branch: 'develop' | ||
gem 'rdf-isomorphic', git: 'https://github.com/ruby-rdf/rdf-isomorphic.git', branch: 'develop' | ||
gem 'rdf-ordered-repo', git: 'https://github.com/ruby-rdf/rdf-ordered-repo.git', branch: 'develop' | ||
gem 'rdf-reasoner', git: 'https://github.com/ruby-rdf/rdf-reasoner.git', branch: 'develop' | ||
gem 'rdf-spec', git: 'https://github.com/ruby-rdf/rdf-spec.git', branch: 'develop' | ||
gem 'rdf-turtle', git: 'https://github.com/ruby-rdf/rdf-turtle.git', branch: 'develop' | ||
gem 'rdf-xsd', git: 'https://github.com/ruby-rdf/rdf-xsd.git', branch: 'develop' | ||
gem 'sparql', git: 'https://github.com/ruby-rdf/sparql.git', branch: 'develop' | ||
gem 'sxp', git: 'https://github.com/dryruby/sxp.rb.git', branch: 'develop' | ||
|
||
gem 'rake' | ||
gem 'simplecov', '~> 0.16', platform: :mri | ||
gem 'coveralls', '~> 0.8', '>= 0.8.23', platform: :mri | ||
|
||
gem 'earl-report', platform: :mri | ||
end | ||
|
||
group :debug do | ||
gem 'byebug', platform: :mri | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,159 @@ | ||
# shacl | ||
Implementation of Shapes Constraint Language (SHACL) for RDF.rb | ||
# SHACL: Shapes Constraint Language (SHACL) for Ruby | ||
|
||
This is a pure-Ruby library for working with the [Shape Constraint Language][SHACL Spec] to validate the shape of [RDF][] graphs. | ||
|
||
[![Gem Version](https://badge.fury.io/rb/shacl.png)](https://badge.fury.io/rb/shacl) | ||
[![Build Status](https://github.com/ruby-rdf/shacl/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/shacl/actions?query=workflow%3ACI) | ||
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/shacl/badge.svg)](https://coveralls.io/github/ruby-rdf/shacl) | ||
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf) | ||
|
||
## Features | ||
|
||
* 100% pure Ruby with minimal dependencies and no bloat. | ||
* Fully compatible with [SHACL][SHACL Spec] specifications. | ||
* 100% free and unencumbered [public domain](https://unlicense.org/) software. | ||
|
||
[Implementation Report](https://ruby-rdf.github.io/shacl/etc/earl.html) | ||
|
||
Install with `gem install shacl` | ||
|
||
## Description | ||
|
||
The SHACL gem implements a [SHACL][SHACL Spec] Shape Expression engine. | ||
|
||
## Examples | ||
|
||
require 'linkeddata' | ||
require 'shacl' | ||
|
||
graph = RDF::Graph.load("etc/doap.ttl") | ||
shacl = SHACL.open("etc/doap.shacl") | ||
report = shacl.execute(graph) | ||
#=> ValidationReport(conform?, results*) | ||
|
||
## Command Line | ||
TODO: When the `linkeddata` gem is installed, RDF.rb includes a `rdf` executable which acts as a wrapper to perform a number of different | ||
operations on RDF files, including SHACL. The commands specific to SHACL is | ||
|
||
*`shacl`: Validate repository given shape | ||
|
||
Using this command requires `shacl`, which references a URI or file path to the SHACL shapes graph. Other options are `shape` and `focus`. | ||
|
||
Example usage: | ||
|
||
rdf shacl https://ruby-rdf.github.io/shacl/etc/doap.ttl \ | ||
--shape https://ruby-rdf.github.io/shacl/etc/doap-shape.ttl | ||
|
||
The result will add the SHACL validation report to the output graph, optionally replacing the graph with the results, expressing the results as an s-expression, or adding the results as output messages. | ||
|
||
## Documentation | ||
|
||
<https://rubydoc.info/github/ruby-rdf/shacl> | ||
|
||
## Implementation Notes | ||
|
||
Similar to the [ShEx gem][] and to the general strategy for querying graphs in the [SPARQL gem][], the strategy is to parse SHACL shapes into executable operators, which are called recursively to create result sets corresponding to matched nodes and properties. | ||
|
||
The shape graph is parsed into JSON-LD, and then converted into [S-Expressions][], which match the execution path. These [S-Expressions][] can be parsed to recreate the executable shape constraints. | ||
|
||
Evaluating the shapes against a graph results in a {SHACL::ValidationReport} indicating conformance, along with a set of individual {SHACL::ValidationResult} instances. | ||
|
||
The resulting validation report can be compared with other validation reports, used as native Ruby objects, serialized to s-expressions, or used as an RDF::Enumerable to retrieve the RDF representation of the report, as defined in [SHACL Spec][]. | ||
|
||
### Matching Entailed Triples | ||
Many tests check for entailed triples, such as entailed super-classes of explicit `rdf:type` values. If this is required for a given application, the [RDF::Reasoner][] gem can be used to create such entailed triples. | ||
|
||
require 'shacl' | ||
require 'rdf/reasoner' | ||
RDF::Reasoner.apply(:rdfs) | ||
graph = RDF::Graph.load("etc/doap.ttl") | ||
graph.entail! | ||
shacl = SHACL.open("etc/doap.shacl") | ||
results = shacl.execute(graph) | ||
#=> [ValidationResult, ...] | ||
|
||
### Future work | ||
This implementation is certainly not performant. Some things that can be be considered in future versions: | ||
|
||
* Support for SHACL-SPARQL | ||
* Index shapes on `targetNode` and `targetClass` and other targets to allow a more efficient query to find relevant resources in the data graph and not simply iterrate through each top-level shape. | ||
* Cache target nodes as JSON-LD to reduce the need to separately query for each constraint. | ||
* Reasoner should support limited RDFS/OWL entailment from the data graph, not just pre-defined vocabularies. | ||
|
||
## Dependencies | ||
|
||
* [Ruby](https://ruby-lang.org/) (>= 2.4) | ||
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.1, => 3.1.8) | ||
* [SPARQL](https://rubygems.org/gems/sparql) (~> 3.1, => 3.1.4) | ||
* [json-ld](https://rubygems.org/gems/sparql) (~> 3.1, => 3.1.7) | ||
* [sxp](https://rubygems.org/gems/sxp) (~> 1.1) | ||
|
||
## Installation | ||
|
||
The recommended installation method is via [RubyGems](https://rubygems.org/). | ||
To install the latest official release of RDF.rb, do: | ||
|
||
% [sudo] gem install shacl | ||
|
||
## Download | ||
|
||
To get a local working copy of the development repository, do: | ||
|
||
% git clone git://github.com/ruby-rdf/shacl.git | ||
|
||
Alternatively, download the latest development version as a tarball as | ||
follows: | ||
|
||
% wget https://github.com/ruby-rdf/shacl/tarball/master | ||
|
||
## Resources | ||
|
||
* <https://rubydoc.info/github/ruby-rdf/shacl> | ||
* <https://github.com/ruby-rdf/shacl> | ||
* <https://rubygems.org/gems/shacl> | ||
|
||
## Mailing List | ||
|
||
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/> | ||
|
||
## Author | ||
|
||
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/> | ||
|
||
## Contributing | ||
|
||
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration. | ||
|
||
* Do your best to adhere to the existing coding conventions and idioms. | ||
* Don't use hard tabs, and don't leave trailing whitespace on any line. | ||
Before committing, run `git diff --check` to make sure of this. | ||
* Do document every method you add using [YARD][] annotations. Read the | ||
[tutorial][YARD-GS] or just look at the existing code for examples. | ||
* Don't touch the `.gemspec` or `VERSION` files. If you need to change them, | ||
do so on your private branch only. | ||
* Do feel free to add yourself to the `CREDITS` file and the | ||
corresponding list in the the `README`. Alphabetical order applies. | ||
* Don't touch the `AUTHORS` file. If your contributions are significant | ||
enough, be assured we will eventually add you in there. | ||
* Do note that in order for us to merge any non-trivial changes (as a rule | ||
of thumb, additions larger than about 15 lines of code), we need an | ||
explicit [public domain dedication][PDD] on record from you, | ||
which you will be asked to agree to on the first commit to a repo within the organization. | ||
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization. | ||
|
||
## License | ||
|
||
This is free and unencumbered public domain software. For more information, | ||
see <https://unlicense.org/> or the accompanying {file:LICENSE} file. | ||
|
||
[RDF]: https://www.w3.org/RDF/ | ||
[YARD]: https://yardoc.org/ | ||
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md | ||
[PDD]: https://unlicense.org/#unlicensing-contributions | ||
[S-Expressions]: https://en.wikipedia.org/wiki/S-expression | ||
[RDF.rb]: https://ruby-rdf.github.com/rdf | ||
[RDF::Reasoner]: https://ruby-rdf.github.com/rdf-reasoner | ||
[SPARQL gem]: https://ruby-rdf.github.com/sparql | ||
[SXP gem]: https://ruby-rdf.github.com/sxp | ||
[SHACL Spec]: https://www.w3.org/TR/shacl/ | ||
[ShEx gem]: https://ruby-rdf.github.com/shex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env ruby | ||
require 'rdf/vocab' | ||
require 'rdf/turtle' | ||
|
||
namespace :gem do | ||
desc "Build the shacl-#{File.read('VERSION').chomp}.gem file" | ||
task :build do | ||
sh "gem build shacl.gemspec && mv shacl-#{File.read('VERSION').chomp}.gem pkg/" | ||
end | ||
|
||
desc "Release the shacl-#{File.read('VERSION').chomp}.gem file" | ||
task :release do | ||
sh "gem push pkg/shacl-#{File.read('VERSION').chomp}.gem" | ||
end | ||
end | ||
|
||
desc "Generate SHACL vocabulary class" | ||
task :vocab do | ||
puts "Generate lib/shacl/vocab.rb" | ||
cmd = "bundle exec rdf" | ||
cmd += " serialize --uri 'http://www.w3.org/ns/shacl#' --output-format vocabulary --ordered" | ||
cmd += " --module-name RDF::Vocab" | ||
cmd += " --class-name SHACL" | ||
cmd += " --strict" | ||
cmd += " -o lib/shacl/vocab.rb_t" | ||
cmd += " https://www.w3.org/ns/shacl.ttl" | ||
puts " #{cmd}" | ||
begin | ||
%x{#{cmd} && sed 's/\r//g' lib/rdf/vocab/shacl.rb_t > lib/rdf/vocab/shacl.rb} | ||
rescue | ||
puts "Failed to load shacl vocabulary: #{$!.message}" | ||
ensure | ||
%x{rm -f lib/rdf/vocab/shacl.rb_t} | ||
end | ||
end | ||
|
||
desc "Build cached context for interpreting IRIs from JSON representation" | ||
task context: "lib/shacl/context.rb" | ||
|
||
file "lib/shacl/context.rb" => "lib/shacl/shapes.rb" do | ||
File.open("lib/shacl/context.rb", "w") do |f| | ||
require 'json/ld' | ||
require 'shacl' | ||
c = JSON::LD::Context.parse(SHACL::Shapes::SHAPES_FRAME['@context']) | ||
c.context_base = "http://github.com/ruby-rdf/shacl/" | ||
f.write c.to_rb | ||
end | ||
end | ||
|
||
file 'etc/manifests.ttl' do | ||
%x{script/tc --write-manifests -o etc/manifests.ttl} | ||
end | ||
|
||
desc "Generate EARL report" | ||
task :earl => 'etc/earl.html' | ||
|
||
file 'etc/earl.ttl' => 'etc/doap.ttl' do | ||
%x{script/tc --earl -o etc/earl.ttl} | ||
end | ||
|
||
file 'etc/earl.jsonld' => %w(etc/earl.ttl etc/manifests.ttl etc/template.haml) do | ||
%x{(cd etc; earl-report --format json -o earl.jsonld earl.ttl)} | ||
end | ||
|
||
file 'etc/earl.html' => 'etc/earl.jsonld' do | ||
%x{(cd etc; earl-report --json --format html --template template.haml -o earl.html earl.jsonld)} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
:format: :json | ||
:manifest: manifests.ttl | ||
:bibRef: ! '[[shacl]]' | ||
:name: Shapes Constraint Language (SHACL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# EARL results for SHACL. | ||
|
||
../script/tc --write-manifests -o manifests.ttl | ||
../script/tc --earl -o earl.ttl | ||
earl-report --format json -o earl.jsonld earl.ttl | ||
earl-report --json --format html --template template.haml -o earl.html earl.jsonld |
Oops, something went wrong.