Skip to content

Commit bf91451

Browse files
committed
Improve documentation.
1 parent 4b5708f commit bf91451

File tree

14 files changed

+107
-70
lines changed

14 files changed

+107
-70
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Gemfile.lock
1212
benchmark/
1313
/.byebug_history
1414
/coverage/
15+
/doc/

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ShEx: Shape Expression language for Ruby
22

3-
This is a pure-Ruby library for working with the [Shape Expressions Language][ShEx] to validate the shape of [RDF][] graphs.
3+
This is a pure-Ruby library for working with the [Shape Expressions Language][ShExSpec] to validate the shape of [RDF][] graphs.
44

5-
* <http://ruby-rdf.github.com/shex>
5+
<http://ruby-rdf.github.com/shex>
66

77
[![Gem Version](https://badge.fury.io/rb/shex.png)](http://badge.fury.io/rb/shex)
88
[![Build Status](https://travis-ci.org/ruby-rdf/shex.png?branch=master)](http://travis-ci.org/ruby-rdf/shex)
@@ -12,9 +12,41 @@ This is a pure-Ruby library for working with the [Shape Expressions Language][Sh
1212
## Features
1313

1414
* 100% pure Ruby with minimal dependencies and no bloat.
15-
* Fully compatible with [RDF 1.1][] specifications.
15+
* Fully compatible with [ShEx][ShExSpec] specifications.
1616
* 100% free and unencumbered [public domain](http://unlicense.org/) software.
1717

18+
## Description
19+
20+
The ShEx gem implements a [ShEx][ShExSpec] Shape Expression engine.
21+
22+
* `ShEx::Parser` parses ShExC formatted documents generating executable operators which can be serialized as [S-Expressions](http://en.wikipedia.org/wiki/S-expression).
23+
* `ShEx::Algebra` executes operators against Any `RDF::Graph`, including compliant [RDF.rb][].
24+
25+
## Example
26+
27+
require 'rubygems'
28+
require 'rdf/turtle'
29+
require 'shex'
30+
31+
shexc: %(
32+
PREFIX doap: <http://usefulinc.com/ns/doap#>
33+
PREFIX dc: <http://purl.org/dc/terms/>
34+
<TestShape> EXTRA a {
35+
a doap:Project;
36+
(doap:name;doap:description|dc:title;dc:description)+;
37+
doap:category*;
38+
doap:developer IRI;
39+
doap:implements [<https://shexspec.github.io/spec/>]
40+
}
41+
)
42+
graph = RDF::Graph.load("etc/doap.ttl")
43+
schema = ShEx.parse(shexc)
44+
map = {
45+
"http://rubygems.org/gems/shex" => "TestShape"
46+
}
47+
schema.satisfies?("http://rubygems.org/gems/shex", graph, map)
48+
# => true
49+
1850
## Documentation
1951

2052
<http://rubydoc.info/github/ruby-rdf/shex>
@@ -30,7 +62,7 @@ This is a pure-Ruby library for working with the [Shape Expressions Language][Sh
3062
The recommended installation method is via [RubyGems](http://rubygems.org/).
3163
To install the latest official release of RDF.rb, do:
3264

33-
% [sudo] gem install shex # Ruby 2+
65+
% [sudo] gem install shex
3466

3567
## Download
3668

@@ -81,5 +113,6 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
81113
This is free and unencumbered public domain software. For more information,
82114
see <http://unlicense.org/> or the accompanying {file:LICENSE} file.
83115

84-
[ShEx]: https://shexspec.github.io/spec/
85-
[RDF]: http://www.w3.org/RDF/
116+
[ShExSpec]: https://shexspec.github.io/spec/
117+
[RDF]: http://www.w3.org/RDF/
118+
[RDF.rb]: http://rubydoc.info/github/ruby-rdf/rdf

etc/doap.shex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PREFIX doap: <http://usefulinc.com/ns/doap#>
2+
PREFIX dc: <http://purl.org/dc/terms/>
3+
<TestShape> EXTRA a {
4+
a doap:Project;
5+
(doap:name;doap:description|dc:title;dc:description)+;
6+
doap:category*;
7+
doap:developer IRI;
8+
doap:implements [<https://shexspec.github.io/spec/>]
9+
}

etc/doap.ttl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
@prefix ex: <http://example.org/> .
88
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
99

10-
<http://rubygems.org/gems/rdf-turtle> a doap:Project, earl:TestSubject, earl:Software ;
11-
doap:name "RDF::Turtle" ;
12-
doap:homepage <http://ruby-rdf.github.com/rdf-turtle> ;
10+
<http://rubygems.org/gems/shex> a doap:Project, earl:TestSubject, earl:Software ;
11+
doap:name "ShEx" ;
12+
doap:homepage <http://ruby-rdf.github.com/shex> ;
1313
doap:license <http://creativecommons.org/licenses/publicdomain/> ;
14-
doap:shortdesc "Turtle reader/writer for Ruby."@en ;
15-
doap:description "RDF::Turtle is an Turtle reader/writer for the RDF.rb library suite."@en ;
16-
doap:created "2011-08-29"^^xsd:date ;
14+
doap:shortdesc "ShEx is a Shape Expression engine for Ruby."@en ;
15+
doap:description "ShEx is an Shape Expression engine for the RDF.rb library suite."@en ;
16+
doap:created "2016-12-09"^^xsd:date ;
1717
doap:programming-language "Ruby" ;
18-
doap:implements <http://www.w3.org/TR/turtle/> ;
18+
doap:implements <https://shexspec.github.io/spec/> ;
1919
doap:category <http://dbpedia.org/resource/Resource_Description_Framework>,
2020
<http://dbpedia.org/resource/Ruby_(programming_language)> ;
21-
doap:download-page <http://rubygems.org/gems/rdf-turtle> ;
21+
doap:download-page <http://rubygems.org/gems/shex> ;
2222
doap:mailing-list <http://lists.w3.org/Archives/Public/public-rdf-ruby/> ;
23-
doap:bug-database <http://github.com/ruby-rdf/rdf-turtle/issues> ;
23+
doap:bug-database <http://github.com/ruby-rdf/shex/issues> ;
2424
doap:blog <http://greggkellogg.net/> ;
2525
doap:developer <http://greggkellogg.net/foaf#me> ;
2626
doap:maintainer <http://greggkellogg.net/foaf#me> ;
2727
doap:documenter <http://greggkellogg.net/foaf#me> ;
2828
foaf:maker <http://greggkellogg.net/foaf#me> ;
29-
dc:title "RDF::Turtle" ;
30-
dc:description "RDF::Turtle is an Turtle reader/writer for the RDF.rb library suite."@en ;
31-
dc:date "2011-08-29"^^xsd:date ;
29+
dc:title "ShEx" ;
30+
dc:description "ShEx is an Shape Expression engine for the RDF.rb library suite."@en ;
31+
dc:date "2016-12-09"^^xsd:date ;
3232
dc:creator <http://greggkellogg.net/foaf#me> ;
3333
dc:isPartOf <http://rubygems.org/gems/rdf> .

lib/shex.rb

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ module ShEx
1414
##
1515
# Parse the given ShEx `query` string.
1616
#
17-
# @example
18-
# query = ShEx.parse("...")
17+
# @example parsing a ShExC schema
18+
# schema = ShEx.parse(%(
19+
# PREFIX ex: <http://schema.example/> ex:IssueShape {ex:state IRI}
20+
# ).parse
1921
#
2022
# @param [IO, StringIO, String, #to_s] expression (ShExC or ShExJ)
2123
# @param ['shexc', 'shexj', 'sse'] format ('shexc')
2224
# @param [Hash{Symbol => Object}] options
2325
# @return [ShEx::Algebra::Schema] The executable parsed expression.
24-
# @raise [Parser::Error] on invalid input
26+
# @raise [ShEx::ParseError] when a syntax error is detected
27+
# @raise [ShEx::StructureError, ShEx::OperandError] on structural problems with schema
2528
def self.parse(expression, format: 'shexc', **options)
2629
case format
2730
when 'shexc' then Parser.new(expression, options).parse
@@ -34,32 +37,46 @@ def self.parse(expression, format: 'shexc', **options)
3437
##
3538
# Parses input from the given file name or URL.
3639
#
40+
# @example parsing a ShExC schema
41+
# schema = ShEx.parse('foo.shex').parse
42+
#
3743
# @param [String, #to_s] filename
3844
# @param ['shexc', 'shexj', 'sse'] format ('shexc')
3945
# @param [Hash{Symbol => Object}] options
4046
# any additional options (see `RDF::Reader#initialize` and `RDF::Format.for`)
4147
# @yield [ShEx::Algebra::Schema]
4248
# @yieldparam [RDF::Reader] reader
4349
# @yieldreturn [void] ignored
44-
# @raise [RDF::FormatError] if no reader found for the specified format
50+
# @return [ShEx::Algebra::Schema] The executable parsed expression.
51+
# @raise [ShEx::ParseError] when a syntax error is detected
52+
# @raise [ShEx::StructureError, ShEx::OperandError] on structural problems with schema
4553
def self.open(filename, format: 'shexc', **options, &block)
4654
RDF::Util::File.open_file(filename, options) do |file|
4755
self.parse(file, options)
4856
end
4957
end
5058

5159
##
52-
# Parse and execute the given ShEx `expression` string against `queriable`.
53-
# @param [IO, StringIO, String, #to_s] expression (ShExC or ShExJ)
54-
# @param ['shexc', 'shexj', 'sse'] format ('shexc')
55-
# @param [Hash{Symbol => Object}] options
56-
def self.execute(expression, queryable, format: 'shexc', **options, &block)
60+
# Parse and validate the given ShEx `expression` string against `queriable`.
61+
#
62+
# @example executing a ShExC schema
63+
# graph = RDF::Graph.load("etc/doap.ttl")
64+
# ShEx.execute('etc/doap.shex', graph, "http://rubygems.org/gems/shex", "")
65+
#
66+
# @param [IO, StringIO, String, #to_s] expression (ShExC or ShExJ)
67+
# @param [RDF::Resource] focus
68+
# @param [RDF::Resource] shape
69+
# @param ['shexc', 'shexj', 'sse'] format ('shexc')
70+
# @param [Hash{Symbol => Object}] options
71+
# @return [Boolean] `true` if satisfied, `false` if it does not apply
72+
# @raise [ShEx::NotSatisfied] if not satisfied
73+
# @raise [ShEx::ParseError] when a syntax error is detected
74+
# @raise [ShEx::StructureError, ShEx::OperandError] on structural problems with schema
75+
def self.execute(expression, queryable, focus, shape, format: 'shexc', **options, &block)
5776
shex = self.parse(expression, options)
5877
queryable = queryable || RDF::Graph.new
5978

60-
shex.execute(queryable, options)
61-
rescue Parser::Error => e
62-
raise MalformedQuery, e.message
79+
shex.satisfies?(focus, queryable, {focus => shape}, options)
6380
end
6481

6582
class Error < StandardError

lib/shex/algebra.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
$:.unshift(File.expand_path("../..", __FILE__))
22
require 'sparql/algebra'
33
require 'sxp'
4-
require 'shex/algebra/extensions'
54

65
module ShEx
76
# Based on the SPARQL Algebra, operators for executing a patch

lib/shex/algebra/extensions.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/shex/algebra/one_of.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class OneOf < Operator
88
# `expr` is a OneOf and there is some shape expression `se2` in shapeExprs such that a `matches(T, se2, m)`...
99
#
1010
# @param [Array<RDF::Statement>] t
11-
# @param [RDF::Queryable] g
12-
# @param [Hash{RDF::Resource => RDF::Resource}] m
1311
# @return [Array<RDF::Statement]
1412
def matches(t)
1513
results = []

lib/shex/algebra/operator.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,6 @@ class Unary < Operator
341341
##
342342
# @param [RDF::Term] arg1
343343
# the first operand
344-
# @param [RDF::Term] arg2
345-
# the second operand
346344
# @param [Hash{Symbol => Object}] options
347345
# any additional options (see {Operator#initialize})
348346
def initialize(arg1, options = {})

lib/shex/algebra/schema.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class Schema < Operator
1515
##
1616
# Match on schema. Finds appropriate shape for node, and matches that shape.
1717
#
18-
# FIXME: startActs and start
19-
#
2018
# @param [RDF::Resource] n
2119
# @param [RDF::Queryable] g
2220
# @param [Hash{RDF::Resource => RDF::Resource}] m

0 commit comments

Comments
 (0)