Skip to content

Commit 31c8b99

Browse files
committed
Finish 0.3.0
2 parents 01c6a88 + 57c3534 commit 31c8b99

File tree

396 files changed

+83018
-6025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

396 files changed

+83018
-6025
lines changed

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Skip isomorphic tests
2+
--tag ~isomorphic
3+
--tag ~shexr

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
rvm:
1414
- 2.2.6
1515
- 2.3.3
16+
- 2.4.0
1617
- jruby
1718
- rbx
1819
cache: bundler

.yardopts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ AUTHORS
1010
VERSION
1111
LICENSE
1212
etc/shex.html
13-
etc/earl.ttl
1413
etc/earl.html

Gemfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ source "https://rubygems.org"
22

33
gemspec
44

5-
gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
5+
gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
6+
gem 'json-ld', github: "ruby-rdf/json-ld", branch: "develop"
7+
gem 'json-ld-preloaded',github: "ruby-rdf/json-ld-preloaded", branch: "develop"
68

79
group :development, :test do
810
gem 'ebnf', github: "gkellogg/ebnf", branch: "develop"
911
gem 'linkeddata', github: "ruby-rdf/linkeddata", branch: "develop"
1012
gem 'sxp', github: "dryruby/sxp.rb", branch: "develop"
11-
gem 'simplecov', require: false
13+
#gem 'simplecov', require: false
14+
gem 'simplecov', github: 'colszowka/simplecov'
1215
gem 'coveralls', require: false
16+
gem 'earl-report'
1317
end
1418

1519
group :debug do

README.md

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ This is a pure-Ruby library for working with the [Shape Expressions Language][Sh
1919

2020
The ShEx gem implements a [ShEx][ShExSpec] Shape Expression engine.
2121

22-
* `ShEx::Parser` parses ShExC formatted documents generating executable operators which can be serialized as [S-Expressions](http://en.wikipedia.org/wiki/S-expression).
22+
* `ShEx::Parser` parses ShExC and ShExJ formatted documents generating executable operators which can be serialized as [S-Expressions](http://en.wikipedia.org/wiki/S-expression).
2323
* `ShEx::Algebra` executes operators against Any `RDF::Graph`, including compliant [RDF.rb][].
24+
* [Implementation Report](file.earl.html)
2425

25-
## Example
26+
## Examples
27+
### Validating a node using ShExC
2628

2729
require 'rubygems'
2830
require 'rdf/turtle'
@@ -46,6 +48,121 @@ The ShEx gem implements a [ShEx][ShExSpec] Shape Expression engine.
4648
}
4749
schema.satisfies?("http://rubygems.org/gems/shex", graph, map)
4850
# => true
51+
### Validating a node using ShExC
52+
53+
require 'rubygems'
54+
require 'rdf/turtle'
55+
require 'shex'
56+
57+
shexj: %({
58+
"type": "Schema",
59+
"prefixes": {
60+
"doap": "http://usefulinc.com/ns/doap#",
61+
"dc": "http://purl.org/dc/terms/"
62+
},
63+
"shapes": {
64+
"TestShape": {
65+
"type": "Shape",
66+
"extra": ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"],
67+
"expression": {
68+
"type": "EachOf",
69+
"expressions": [
70+
{
71+
"type": "TripleConstraint",
72+
"predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
73+
"valueExpr": {
74+
"type": "NodeConstraint",
75+
"values": ["http://usefulinc.com/ns/doap#Project"]
76+
}
77+
},
78+
{
79+
"type": "OneOf",
80+
"expressions": [
81+
{
82+
"type": "EachOf",
83+
"expressions": [
84+
{
85+
"type": "TripleConstraint",
86+
"predicate": "http://usefulinc.com/ns/doap#name",
87+
"valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
88+
},
89+
{
90+
"type": "TripleConstraint",
91+
"predicate": "http://usefulinc.com/ns/doap#description",
92+
"valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
93+
}
94+
]
95+
},
96+
{
97+
"type": "EachOf",
98+
"expressions": [
99+
{
100+
"type": "TripleConstraint",
101+
"predicate": "http://purl.org/dc/terms/title",
102+
"valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
103+
},
104+
{
105+
"type": "TripleConstraint",
106+
"predicate": "http://purl.org/dc/terms/description",
107+
"valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
108+
}
109+
]
110+
}
111+
],
112+
"min": 1, "max": "*"
113+
},
114+
{
115+
"type": "TripleConstraint",
116+
"predicate": "http://usefulinc.com/ns/doap#category",
117+
"valueExpr": {"type": "NodeConstraint", "nodeKind": "iri"},
118+
"min": 0, "max": "*"
119+
},
120+
{
121+
"type": "TripleConstraint",
122+
"predicate": "http://usefulinc.com/ns/doap#developer",
123+
"valueExpr": {"type": "NodeConstraint", "nodeKind": "iri"},
124+
"min": 1, "max": "*"
125+
},
126+
{
127+
"type": "TripleConstraint",
128+
"predicate": "http://usefulinc.com/ns/doap#implements",
129+
"valueExpr": {
130+
"type": "NodeConstraint",
131+
"values": ["https://shexspec.github.io/spec/"]
132+
}
133+
}
134+
]
135+
}
136+
}
137+
}
138+
})
139+
graph = RDF::Graph.load("etc/doap.ttl")
140+
schema = ShEx.parse(shexj, format: :shexj)
141+
map = {"http://rubygems.org/gems/shex" => "TestShape"}
142+
schema.satisfies?("http://rubygems.org/gems/shex", graph, map)
143+
# => true
144+
145+
## Extensions
146+
ShEx has an extension mechanism using [Semantic Actions](https://shexspec.github.io/spec/#semantic-actions). Extensions may be implemented in Ruby ShEx by sub-classing {ShEx::Extension} and implementing {ShEx::Extension#visit} and possibly {ShEx::Extension#initialize}, {ShEx::Extension#enter}, {ShEx::Extension#exit}, and {ShEx::Extension#close}. The `#visit` method will be called as part of the `#satisfies?` operation.
147+
148+
require 'shex'
149+
class ShEx::Test < ShEx::Extension("http://shex.io/extensions/Test/")
150+
# (see ShEx::Extension#initialize)
151+
def initialize(schema: nil, logger: nil, depth: 0, **options)
152+
...
153+
end
154+
155+
# (see ShEx::Extension#visit)
156+
def visit(code: nil, matched: nil, expression: nil, depth: 0, **options)
157+
...
158+
end
159+
end
160+
161+
The `#enter` method will be called on any {ShEx::Algebra::TripleExpression} that includes a {ShEx::Algebra::SemAct} referencing the extension, while the `#exit` method will be called on exit, even if not satisfied.
162+
163+
The `#initialize` method is called when {ShEx::Algebra::Schema#execute} starts and `#close` called on exit, even if not satisfied.
164+
165+
To make sure your extension is found, make sure to require it before the shape is executed.
49166

50167
## Documentation
51168

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,13 @@ file "etc/shex.html" => "etc/shex.ebnf" do |t|
5959
etc/shex.ebnf
6060
}
6161
end
62+
63+
desc "Build shex JSON-LD context cache"
64+
task context: "lib/shex/shex_context.rb"
65+
file "lib/shex/shex_context.rb" do
66+
require 'json/ld'
67+
File.open("lib/shex/shex_context.rb", "w") do |f|
68+
c = JSON::LD::Context.new().parse("https://shexspec.github.io/context.jsonld")
69+
f.write c.to_rb
70+
end
71+
end

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.3.0

etc/.earl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
:format: :json
3+
:manifest:
4+
- https://raw.githubusercontent.com/shexSpec/shexTest/master/schemas/manifest.ttl
5+
- https://raw.githubusercontent.com/shexSpec/shexTest/master/negativeSyntax/manifest.ttl
6+
- https://raw.githubusercontent.com/shexSpec/shexTest/master/negativeStructure/manifest.ttl
7+
- https://raw.githubusercontent.com/shexSpec/shexTest/master/validation/manifest.ttl
8+
:bibRef: ! '[[shex]]'
9+
:name: Shape Expressions Language
10+
:query: >
11+
PREFIX mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>
12+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
13+
PREFIX sx: <https://shexspec.github.io/shexTest/ns#>
14+
15+
SELECT ?uri ?testAction ?manUri
16+
WHERE {
17+
?uri mf:action | sx:shex ?testAction .
18+
OPTIONAL {
19+
?manUri a mf:Manifest; mf:entries ?lh .
20+
?lh rdf:first ?uri .
21+
}
22+
}

etc/README

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This is a collection of individual EARL reports for
2+
test subjects claiming Turtle processor conformance.
3+
4+
The consolodated report is saved to index.html generated
5+
using the earl-report Ruby gem. Run it as follows:
6+
7+
gem install earl-report
8+
9+
earl-report --format json -o earl.jsonld earl.ttl
10+
earl-report --json --format html --template template.haml -o earl.html earl.jsonld

etc/doap.json

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"@context": "https://shexspec.github.io/context.jsonld",
3+
"type": "Schema",
4+
"shapes": [
5+
{
6+
"type": "Shape",
7+
"label": "TestShape",
8+
"extra": [
9+
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
10+
],
11+
"expression": {
12+
"type": "EachOf",
13+
"expressions": [
14+
{
15+
"type": "TripleConstraint",
16+
"predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
17+
"valueExpr": {
18+
"type": "NodeConstraint",
19+
"values": [
20+
{
21+
"uri": "http://usefulinc.com/ns/doap#Project"
22+
}
23+
]
24+
}
25+
},
26+
{
27+
"type": "OneOf",
28+
"expressions": [
29+
{
30+
"type": "EachOf",
31+
"expressions": [
32+
{
33+
"type": "TripleConstraint",
34+
"predicate": "http://usefulinc.com/ns/doap#name",
35+
"valueExpr": {
36+
"type": "NodeConstraint",
37+
"nodeKind": "literal"
38+
}
39+
},
40+
{
41+
"type": "TripleConstraint",
42+
"predicate": "http://usefulinc.com/ns/doap#description",
43+
"valueExpr": {
44+
"type": "NodeConstraint",
45+
"nodeKind": "literal"
46+
}
47+
}
48+
]
49+
},
50+
{
51+
"type": "EachOf",
52+
"expressions": [
53+
{
54+
"type": "TripleConstraint",
55+
"predicate": "http://purl.org/dc/terms/title",
56+
"valueExpr": {
57+
"type": "NodeConstraint",
58+
"nodeKind": "literal"
59+
}
60+
},
61+
{
62+
"type": "TripleConstraint",
63+
"predicate": "http://purl.org/dc/terms/description",
64+
"valueExpr": {
65+
"type": "NodeConstraint",
66+
"nodeKind": "literal"
67+
}
68+
}
69+
]
70+
}
71+
],
72+
"min": 1,
73+
"max": "*"
74+
},
75+
{
76+
"type": "TripleConstraint",
77+
"predicate": "http://usefulinc.com/ns/doap#category",
78+
"valueExpr": {
79+
"type": "NodeConstraint",
80+
"nodeKind": "iri"
81+
},
82+
"min": 0,
83+
"max": "*"
84+
},
85+
{
86+
"type": "TripleConstraint",
87+
"predicate": "http://usefulinc.com/ns/doap#developer",
88+
"valueExpr": {
89+
"type": "NodeConstraint",
90+
"nodeKind": "iri"
91+
},
92+
"min": 1,
93+
"max": "*"
94+
},
95+
{
96+
"type": "TripleConstraint",
97+
"predicate": "http://usefulinc.com/ns/doap#implements",
98+
"valueExpr": {
99+
"type": "NodeConstraint",
100+
"values": [
101+
{
102+
"uri": "https://shexspec.github.io/spec/"
103+
}
104+
]
105+
}
106+
}
107+
]
108+
}
109+
}
110+
]
111+
}
112+

0 commit comments

Comments
 (0)