@@ -25,120 +25,131 @@ The ShEx gem implements a [ShEx][ShExSpec] Shape Expression engine version 2.0.
25
25
## Examples
26
26
### Validating a node using ShExC
27
27
28
- require 'rubygems'
29
28
require 'rdf/turtle'
30
29
require 'shex'
31
30
32
- shexc: %(
31
+ shexc = %(
33
32
PREFIX doap: <http://usefulinc.com/ns/doap#>
34
33
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/>]
41
45
}
42
46
)
43
47
graph = RDF::Graph.load("etc/doap.ttl")
44
48
schema = ShEx.parse(shexc)
45
49
map = {
46
- "https://rubygems.org/gems/shex" => " TestShape"
50
+ RDF::URI( "https://rubygems.org/gems/shex") => RDF::URI("http://example.com/ TestShape")
47
51
}
48
- schema.satisfies?("https://rubygems.org/gems/shex", graph, map)
52
+ schema.satisfies?(graph, map)
49
53
# => true
50
54
### Validating a node using ShExJ
51
55
52
56
require 'rubygems'
53
57
require 'rdf/turtle'
54
58
require 'shex'
55
59
56
- shexj: %({
60
+ shexj = %({
61
+ "@context": "http://www.w3.org/ns/shex.jsonld",
57
62
"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"
109
86
}
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"
118
121
},
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"
124
130
},
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
+ ]
132
141
}
133
- ]
134
- }
142
+ }
143
+ ]
135
144
}
136
145
}
137
- })
146
+ ] })
138
147
graph = RDF::Graph.load("etc/doap.ttl")
139
148
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)
142
153
# => true
143
154
144
155
## Extensions
0 commit comments