@@ -25,120 +25,131 @@ The ShEx gem implements a [ShEx][ShExSpec] Shape Expression engine version 2.0.
2525## Examples
2626### Validating a node using ShExC
2727
28- require 'rubygems'
2928 require 'rdf/turtle'
3029 require 'shex'
3130
32- shexc: %(
31+ shexc = %(
3332 PREFIX doap: <http://usefulinc.com/ns/doap#>
3433 PREFIX dc: <http://purl.org/dc/terms/>
35- <TestShape> EXTRA a {
36- a doap:Project;
37- (doap:name;doap:description|dc:title;dc:description)+;
38- doap:category*;
39- doap:developer IRI;
40- doap:implements [<http://shex.io/shex-semantics/>]
34+ PREFIX ex: <http://example.com/>
35+
36+ ex:TestShape EXTRA a {
37+ a [doap:Project];
38+ ( doap:name Literal;
39+ doap:description Literal
40+ | dc:title Literal;
41+ dc:description Literal)+;
42+ doap:category IRI*;
43+ doap:developer IRI+;
44+ doap:implements [<http://shex.io/shex-semantics/>]
4145 }
4246 )
4347 graph = RDF::Graph.load("etc/doap.ttl")
4448 schema = ShEx.parse(shexc)
4549 map = {
46- "https://rubygems.org/gems/shex" => " TestShape"
50+ RDF::URI( "https://rubygems.org/gems/shex") => RDF::URI("http://example.com/ TestShape")
4751 }
48- schema.satisfies?("https://rubygems.org/gems/shex", graph, map)
52+ schema.satisfies?(graph, map)
4953 # => true
5054### Validating a node using ShExJ
5155
5256 require 'rubygems'
5357 require 'rdf/turtle'
5458 require 'shex'
5559
56- shexj: %({
60+ shexj = %({
61+ "@context": "http://www.w3.org/ns/shex.jsonld",
5762 "type": "Schema",
58- "prefixes": {
59- "doap": "http://usefulinc.com/ns/doap#",
60- "dc": "http://purl.org/dc/terms/"
61- },
62- "shapes": {
63- "TestShape": {
64- "type": "Shape",
65- "extra": ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"],
66- "expression": {
67- "type": "EachOf",
68- "expressions": [
69- {
70- "type": "TripleConstraint",
71- "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
72- "valueExpr": {
73- "type": "NodeConstraint",
74- "values": ["http://usefulinc.com/ns/doap#Project"]
75- }
76- },
77- {
78- "type": "OneOf",
79- "expressions": [
80- {
81- "type": "EachOf",
82- "expressions": [
83- {
84- "type": "TripleConstraint",
85- "predicate": "http://usefulinc.com/ns/doap#name",
86- "valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
87- },
88- {
89- "type": "TripleConstraint",
90- "predicate": "http://usefulinc.com/ns/doap#description",
91- "valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
92- }
93- ]
94- },
95- {
96- "type": "EachOf",
97- "expressions": [
98- {
99- "type": "TripleConstraint",
100- "predicate": "http://purl.org/dc/terms/title",
101- "valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
102- },
103- {
104- "type": "TripleConstraint",
105- "predicate": "http://purl.org/dc/terms/description",
106- "valueExpr": {"type": "NodeConstraint", "nodeKind": "literal"}
107- }
108- ]
63+ "shapes": [{
64+ "id": "http://example.com/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+ "type": "TripleConstraint",
71+ "predicate": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
72+ "valueExpr": {
73+ "type": "NodeConstraint",
74+ "values": ["http://usefulinc.com/ns/doap#Project"]
75+ }
76+ }, {
77+ "type": "OneOf",
78+ "expressions": [{
79+ "type": "EachOf",
80+ "expressions": [{
81+ "type": "TripleConstraint",
82+ "predicate": "http://usefulinc.com/ns/doap#name",
83+ "valueExpr": {
84+ "type": "NodeConstraint",
85+ "nodeKind": "literal"
10986 }
110- ],
111- "min": 1, "max": -1
112- },
113- {
114- "type": "TripleConstraint",
115- "predicate": "http://usefulinc.com/ns/doap#category",
116- "valueExpr": {"type": "NodeConstraint", "nodeKind": "iri"},
117- "min": 0, "max": -1
87+ }, {
88+ "type": "TripleConstraint",
89+ "predicate": "http://usefulinc.com/ns/doap#description",
90+ "valueExpr": {
91+ "type": "NodeConstraint",
92+ "nodeKind": "literal"
93+ }
94+ }]
95+ }, {
96+ "type": "EachOf",
97+ "expressions": [{
98+ "type": "TripleConstraint",
99+ "predicate": "http://purl.org/dc/terms/title",
100+ "valueExpr": {
101+ "type": "NodeConstraint",
102+ "nodeKind": "literal"
103+ }
104+ }, {
105+ "type": "TripleConstraint",
106+ "predicate": "http://purl.org/dc/terms/description",
107+ "valueExpr": {
108+ "type": "NodeConstraint",
109+ "nodeKind": "literal"
110+ }
111+ }]
112+ }],
113+ "min": 1,
114+ "max": -1
115+ }, {
116+ "type": "TripleConstraint",
117+ "predicate": "http://usefulinc.com/ns/doap#category",
118+ "valueExpr": {
119+ "type": "NodeConstraint",
120+ "nodeKind": "iri"
118121 },
119- {
120- "type": "TripleConstraint",
121- "predicate": "http://usefulinc.com/ns/doap#developer",
122- "valueExpr": {"type": "NodeConstraint", "nodeKind": "iri"},
123- "min": 1, "max": -1
122+ "min": 0,
123+ "max": -1
124+ }, {
125+ "type": "TripleConstraint",
126+ "predicate": "http://usefulinc.com/ns/doap#developer",
127+ "valueExpr": {
128+ "type": "NodeConstraint",
129+ "nodeKind": "iri"
124130 },
125- {
126- "type": "TripleConstraint",
127- "predicate": "http://usefulinc.com/ns/doap#implements",
128- "valueExpr": {
129- "type": "NodeConstraint",
130- "values": ["http://shex.io/shex-semantics/"]
131- }
131+ "min": 1,
132+ "max": -1
133+ }, {
134+ "type": "TripleConstraint",
135+ "predicate": "http://usefulinc.com/ns/doap#implements",
136+ "valueExpr": {
137+ "type": "NodeConstraint",
138+ "values": [
139+ "http://shex.io/shex-semantics/"
140+ ]
132141 }
133- ]
134- }
142+ }
143+ ]
135144 }
136145 }
137- })
146+ ] })
138147 graph = RDF::Graph.load("etc/doap.ttl")
139148 schema = ShEx.parse(shexj, format: :shexj)
140- map = {"https://rubygems.org/gems/shex" => "TestShape"}
141- schema.satisfies?("https://rubygems.org/gems/shex", graph, map)
149+ map = {
150+ RDF::URI("https://rubygems.org/gems/shex") => RDF::URI("http://example.com/TestShape")
151+ }
152+ schema.satisfies?(graph, map)
142153 # => true
143154
144155## Extensions
@@ -189,8 +200,8 @@ The parser uses the executable [S-Expressions][] generated from the EBNF ShExC g
189200
190201## Dependencies
191202
192- * [ Ruby] ( https://ruby-lang.org/ ) (>= 2.4 )
193- * [ RDF.rb] ( https://rubygems.org/gems/rdf ) (~ > 3.1 )
203+ * [ Ruby] ( https://ruby-lang.org/ ) (>= 2.6 )
204+ * [ RDF.rb] ( https://rubygems.org/gems/rdf ) (~ > 3.2 )
194205* [ SPARQL gem] ( https://rubygems.org/gems/sparql ) (~ > 3.1)
195206
196207## Installation
0 commit comments