shex 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ ##
2
+ # Test extension.
3
+ #
4
+ # Default implementation of http://shex.io/extensions/Test/
5
+ #
6
+ # @see http://shex.io/extensions/Test/
7
+ require 'shex'
8
+
9
+ class ShEx::Test < ShEx::Extension("http://shex.io/extensions/Test/")
10
+ # (see ShEx::Extension#visit)
11
+ def visit(code: nil, matched: nil, depth: 0, **options)
12
+ str = if md = /^ *(fail|print) *\( *(?:(\"(?:[^\\"]|\\")*\")|([spo])) *\) *$/.match(code.to_s)
13
+ md[2] || case md[3]
14
+ when 's' then matched.subject
15
+ when 'p' then matched.predicate
16
+ when 'o' then matched.object
17
+ else matched.to_sxp
18
+ end.to_s
19
+ else
20
+ matched ? matched.to_sxp : 'no statement'
21
+ end
22
+
23
+ $stdout.puts str
24
+ return !md || md[1] == 'print'
25
+ end
26
+ end
@@ -79,7 +79,7 @@ module ShEx
79
79
  terminal(:PNAME_LN, PNAME_LN, unescape: true) do |prod, token, input|
80
80
  prefix, suffix = token.value.split(":", 2)
81
81
  input[:iri] = ns(prefix, suffix)
82
- error(nil, "Compact IRI missing prefix definition: #{token.value}", production: :PNAME_LN) unless input[:iri].absolute?
82
+ error(nil, "Compact IRI missing prefix definition: #{token.value}", production: :PNAME_LN) unless prefix(prefix)
83
83
  end
84
84
  terminal(:PNAME_NS, PNAME_NS) do |prod, token, input|
85
85
  prefix = token.value[0..-2]
@@ -156,19 +156,11 @@ module ShEx
156
156
  production(:shexDoc) do |input, data, callback|
157
157
  data[:start] = data[:start] if data[:start]
158
158
 
159
- expressions = []
160
- expressions << [:base, data[:baseDecl]] if data[:baseDecl]
161
- expressions << [:prefix, data[:prefixDecl]] if data[:prefixDecl]
162
- expressions += Array(data[:codeDecl])
159
+ expressions = Array(data[:codeDecl])
163
160
  expressions << Algebra::Start.new(data[:start]) if data[:start]
164
- expressions << [:shapes, data[:shapes]] if data[:shapes]
161
+ expressions << data[:shapes].unshift(:shapes) if data[:shapes]
165
162
 
166
163
  input[:schema] = Algebra::Schema.new(*expressions, options)
167
-
168
- # Set schema accessor for all included expressions
169
- input[:schema].each_descendant do |op|
170
- op.schema = input[:schema] if op.respond_to?(:schema=)
171
- end
172
164
  self
173
165
  end
174
166
 
@@ -176,14 +168,13 @@ module ShEx
176
168
 
177
169
  # [3] baseDecl ::= "BASE" IRIREF
178
170
  production(:baseDecl) do |input, data, callback|
179
- input[:baseDecl] = self.base_uri = iri(data[:iri])
171
+ self.base_uri = iri(data[:iri])
180
172
  end
181
173
 
182
174
  # [4] prefixDecl ::= "PREFIX" PNAME_NS IRIREF
183
175
  production(:prefixDecl) do |input, data, callback|
184
176
  pfx = data[:prefix]
185
177
  self.prefix(pfx, data[:iri])
186
- (input[:prefixDecl] ||= []) << [pfx.to_s, data[:iri]]
187
178
  end
188
179
 
189
180
  # [5] notStartAction ::= start | shapeExprDecl
@@ -204,8 +195,9 @@ module ShEx
204
195
  else
205
196
  data[:external] ? Algebra::External.new() : Algebra::Shape.new()
206
197
  end
198
+ expression.label = label
207
199
 
208
- (input[:shapes] ||= {})[label] = expression
200
+ (input[:shapes] ||= []) << expression
209
201
  end
210
202
 
211
203
  # [10] shapeExpression ::= shapeOr
@@ -337,7 +329,7 @@ module ShEx
337
329
  end
338
330
 
339
331
  attrs = []
340
- attrs += [:datatype, data[:datatype]] if data [:datatype]
332
+ attrs << [:datatype, data[:datatype]] if data [:datatype]
341
333
  attrs += [data[:shapeAtomLiteral], data[:nonLiteralKind]]
342
334
  attrs += Array(data[:valueSetValue])
343
335
  attrs += Array(data[:numericFacet])
@@ -394,10 +386,11 @@ module ShEx
394
386
  expression = data[:tripleExpression]
395
387
  attrs = Array(data[:extraPropertySet])
396
388
  attrs << :closed if data[:closed]
389
+ attrs << expression
397
390
  attrs += Array(data[:annotation])
398
391
  attrs += Array(data[:codeDecl])
399
392
 
400
- input[:shape] = Algebra::Shape.new(expression, *attrs) if expression
393
+ input[:shape] = Algebra::Shape.new(*attrs) if expression
401
394
  end
402
395
  private :shape_definition
403
396
 
@@ -430,7 +423,7 @@ module ShEx
430
423
  # [40] unaryTripleExpr ::= productionLabel? (tripleConstraint | bracketedTripleExpr) | include
431
424
  production(:unaryTripleExpr) do |input, data, callback|
432
425
  expression = data[:tripleExpression]
433
- expression.operands << data[:productionLabel] if expression && data[:productionLabel]
426
+ expression.label = data[:productionLabel] if expression && data[:productionLabel]
434
427
 
435
428
  (input[:tripleExpression] ||= []) << expression if expression
436
429
  end
@@ -568,10 +561,6 @@ module ShEx
568
561
  # the base URI to use when resolving relative URIs (for acessing intermediate parser productions)
569
562
  # @option options [#to_s] :anon_base ("b0")
570
563
  # Basis for generating anonymous Nodes
571
- # @option options [Boolean] :resolve_iris (false)
572
- # Resolve prefix and relative IRIs, otherwise, when serializing the parsed SXP
573
- # as S-Expressions, use the original prefixed and relative URIs along with `base` and `prefix`
574
- # definitions.
575
564
  # @option options [Boolean] :validate (false)
576
565
  # whether to validate the parsed statements and values
577
566
  # @option options [Boolean] :progress
@@ -735,7 +724,7 @@ module ShEx
735
724
  #
736
725
  # @return [HRDF::URI]
737
726
  def base_uri
738
- RDF::URI(@options[:base_uri]) if @options[:base_uri]
727
+ @options[:base_uri]
739
728
  end
740
729
 
741
730
  ##
@@ -762,9 +751,7 @@ module ShEx
762
751
 
763
752
  # Generate a BNode identifier
764
753
  def bnode(id)
765
- @bnode_cache ||= {}
766
- raise Error, "Illegal attempt to reuse a BNode" if @bnode_cache[id] && @bnode_cache[id].frozen?
767
- @bnode_cache[id] ||= RDF::Node.new(id)
754
+ RDF::Node.intern(id)
768
755
  end
769
756
 
770
757
  # Create URIs
@@ -0,0 +1,85 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+ # This file generated automatically from https://shexspec.github.io/context.jsonld
4
+ require 'json/ld'
5
+ class JSON::LD::Context
6
+ add_preloaded("https://shexspec.github.io/context.jsonld") do
7
+ new(term_definitions: {
8
+ "Annotation" => TermDefinition.new("Annotation", id: "http://shex.io/ns/shex#Annotation", simple: true),
9
+ "EachOf" => TermDefinition.new("EachOf", id: "http://shex.io/ns/shex#EachOf", simple: true),
10
+ "Inclusion" => TermDefinition.new("Inclusion", id: "http://shex.io/ns/shex#Inclusion", simple: true),
11
+ "NodeConstraint" => TermDefinition.new("NodeConstraint", id: "http://shex.io/ns/shex#NodeConstraint", simple: true),
12
+ "NodeKind" => TermDefinition.new("NodeKind", id: "http://shex.io/ns/shex#NodeKind", simple: true),
13
+ "OneOf" => TermDefinition.new("OneOf", id: "http://shex.io/ns/shex#OneOf", simple: true),
14
+ "Schema" => TermDefinition.new("Schema", id: "http://shex.io/ns/shex#Schema", simple: true),
15
+ "SemAct" => TermDefinition.new("SemAct", id: "http://shex.io/ns/shex#SemAct", simple: true),
16
+ "Shape" => TermDefinition.new("Shape", id: "http://shex.io/ns/shex#Shape", simple: true),
17
+ "ShapeAnd" => TermDefinition.new("ShapeAnd", id: "http://shex.io/ns/shex#ShapeAnd", simple: true),
18
+ "ShapeExpression" => TermDefinition.new("ShapeExpression", id: "http://shex.io/ns/shex#ShapeExpression", simple: true),
19
+ "ShapeExternal" => TermDefinition.new("ShapeExternal", id: "http://shex.io/ns/shex#ShapeExternal", simple: true),
20
+ "ShapeNot" => TermDefinition.new("ShapeNot", id: "http://shex.io/ns/shex#ShapeNot", simple: true),
21
+ "ShapeOr" => TermDefinition.new("ShapeOr", id: "http://shex.io/ns/shex#ShapeOr", simple: true),
22
+ "ShapeRef" => TermDefinition.new("ShapeRef", id: "http://shex.io/ns/shex#ShapeRef", simple: true),
23
+ "Stem" => TermDefinition.new("Stem", id: "http://shex.io/ns/shex#Stem", simple: true),
24
+ "StemRange" => TermDefinition.new("StemRange", id: "http://shex.io/ns/shex#StemRange", simple: true),
25
+ "TripleConstraint" => TermDefinition.new("TripleConstraint", id: "http://shex.io/ns/shex#TripleConstraint", simple: true),
26
+ "TripleExpression" => TermDefinition.new("TripleExpression", id: "http://shex.io/ns/shex#TripleExpression", simple: true),
27
+ "Wildcard" => TermDefinition.new("Wildcard", id: "http://shex.io/ns/shex#Wildcard", simple: true),
28
+ "annotation" => TermDefinition.new("annotation", id: "http://shex.io/ns/shex#annotation", type_mapping: "@id"),
29
+ "annotations" => TermDefinition.new("annotations", id: "http://shex.io/ns/shex#annotation", type_mapping: "@id"),
30
+ "bnode" => TermDefinition.new("bnode", id: "http://shex.io/ns/shex#bnode", simple: true),
31
+ "closed" => TermDefinition.new("closed", id: "http://shex.io/ns/shex#closed", type_mapping: "http://www.w3.org/2001/XMLSchema#boolean"),
32
+ "code" => TermDefinition.new("code", id: "http://shex.io/ns/shex#code"),
33
+ "datatype" => TermDefinition.new("datatype", id: "http://shex.io/ns/shex#datatype", type_mapping: "@id"),
34
+ "exclusion" => TermDefinition.new("exclusion", id: "http://shex.io/ns/shex#exclusion", type_mapping: "@id"),
35
+ "exclusions" => TermDefinition.new("exclusions", id: "http://shex.io/ns/shex#exclusion", type_mapping: "@id"),
36
+ "expression" => TermDefinition.new("expression", id: "http://shex.io/ns/shex#expression", type_mapping: "@id"),
37
+ "expressions" => TermDefinition.new("expressions", id: "http://shex.io/ns/shex#expressions", type_mapping: "@id", container_mapping: "@list"),
38
+ "extra" => TermDefinition.new("extra", id: "http://shex.io/ns/shex#extra", type_mapping: "@id"),
39
+ "fractiondigits" => TermDefinition.new("fractiondigits", id: "http://shex.io/ns/shex#fractiondigits", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
40
+ "id" => TermDefinition.new("id", id: "@id", simple: true),
41
+ "include" => TermDefinition.new("include", id: "http://shex.io/ns/shex#include", type_mapping: "@id"),
42
+ "inverse" => TermDefinition.new("inverse", id: "http://shex.io/ns/shex#inverse", type_mapping: "http://www.w3.org/2001/XMLSchema#boolean"),
43
+ "iri" => TermDefinition.new("iri", id: "http://shex.io/ns/shex#iri", simple: true),
44
+ "label" => TermDefinition.new("label", id: "@id", simple: true),
45
+ "language" => TermDefinition.new("language", id: "@language", simple: true),
46
+ "length" => TermDefinition.new("length", id: "http://shex.io/ns/shex#length", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
47
+ "literal" => TermDefinition.new("literal", id: "http://shex.io/ns/shex#literal", simple: true),
48
+ "max" => TermDefinition.new("max", id: "http://shex.io/ns/shex#max"),
49
+ "maxexclusive" => TermDefinition.new("maxexclusive", id: "http://shex.io/ns/shex#maxexclusive", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
50
+ "maxinclusive" => TermDefinition.new("maxinclusive", id: "http://shex.io/ns/shex#maxinclusive", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
51
+ "maxlength" => TermDefinition.new("maxlength", id: "http://shex.io/ns/shex#maxlength", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
52
+ "min" => TermDefinition.new("min", id: "http://shex.io/ns/shex#min", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
53
+ "minexclusive" => TermDefinition.new("minexclusive", id: "http://shex.io/ns/shex#minexclusive", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
54
+ "mininclusive" => TermDefinition.new("mininclusive", id: "http://shex.io/ns/shex#mininclusive", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
55
+ "minlength" => TermDefinition.new("minlength", id: "http://shex.io/ns/shex#minlength", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
56
+ "name" => TermDefinition.new("name", id: "http://shex.io/ns/shex#name", type_mapping: "@id"),
57
+ "nodeKind" => TermDefinition.new("nodeKind", id: "http://shex.io/ns/shex#nodeKind", type_mapping: "@vocab"),
58
+ "nonliteral" => TermDefinition.new("nonliteral", id: "http://shex.io/ns/shex#nonliteral", simple: true),
59
+ "numericFacet" => TermDefinition.new("numericFacet", id: "http://shex.io/ns/shex#numericFacet"),
60
+ "object" => TermDefinition.new("object", id: "http://shex.io/ns/shex#object", type_mapping: "@id"),
61
+ "pattern" => TermDefinition.new("pattern", id: "http://shex.io/ns/shex#pattern"),
62
+ "predicate" => TermDefinition.new("predicate", id: "http://shex.io/ns/shex#predicate", type_mapping: "@id"),
63
+ "rdf" => TermDefinition.new("rdf", id: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", simple: true),
64
+ "rdfs" => TermDefinition.new("rdfs", id: "http://www.w3.org/2000/01/rdf-schema#", simple: true),
65
+ "reference" => TermDefinition.new("reference", id: "http://shex.io/ns/shex#reference", type_mapping: "@id"),
66
+ "semActs" => TermDefinition.new("semActs", id: "http://shex.io/ns/shex#semActs", type_mapping: "@id", container_mapping: "@list"),
67
+ "shapeExpr" => TermDefinition.new("shapeExpr", id: "http://shex.io/ns/shex#shapeExpr", type_mapping: "@id"),
68
+ "shapeExprs" => TermDefinition.new("shapeExprs", id: "http://shex.io/ns/shex#shapeExprs", type_mapping: "@id", container_mapping: "@list"),
69
+ "shapes" => TermDefinition.new("shapes", id: "http://shex.io/ns/shex#shapes", type_mapping: "@id"),
70
+ "shex" => TermDefinition.new("shex", id: "http://shex.io/ns/shex#", simple: true),
71
+ "start" => TermDefinition.new("start", id: "http://shex.io/ns/shex#start", type_mapping: "@id"),
72
+ "startActs" => TermDefinition.new("startActs", id: "http://shex.io/ns/shex#startActs", type_mapping: "@id", container_mapping: "@list"),
73
+ "stem" => TermDefinition.new("stem", id: "http://shex.io/ns/shex#stem", type_mapping: "http://www.w3.org/2001/XMLSchema#anyUri"),
74
+ "stringFacet" => TermDefinition.new("stringFacet", id: "http://shex.io/ns/shex#stringFacet"),
75
+ "totaldigits" => TermDefinition.new("totaldigits", id: "http://shex.io/ns/shex#totaldigits", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
76
+ "type" => TermDefinition.new("type", id: "@type", simple: true),
77
+ "uri" => TermDefinition.new("uri", id: "@id", simple: true),
78
+ "value" => TermDefinition.new("value", id: "@value", simple: true),
79
+ "valueExpr" => TermDefinition.new("valueExpr", id: "http://shex.io/ns/shex#valueExpr", type_mapping: "@id"),
80
+ "values" => TermDefinition.new("values", id: "http://shex.io/ns/shex#values", type_mapping: "@id", container_mapping: "@list"),
81
+ "xsFacet" => TermDefinition.new("xsFacet", id: "http://shex.io/ns/shex#xsFacet"),
82
+ "xsd" => TermDefinition.new("xsd", id: "http://www.w3.org/2001/XMLSchema#", simple: true)
83
+ })
84
+ end
85
+ end
@@ -0,0 +1,19 @@
1
+ module ShEx
2
+ module VERSION
3
+ FILE = File.expand_path('../../../VERSION', __FILE__)
4
+ MAJOR, MINOR, TINY, EXTRA = File.read(FILE).chomp.split('.')
5
+ STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.').freeze
6
+
7
+ ##
8
+ # @return [String]
9
+ def self.to_s() STRING end
10
+
11
+ ##
12
+ # @return [String]
13
+ def self.to_str() STRING end
14
+
15
+ ##
16
+ # @return [Array(String, String, String, String)]
17
+ def self.to_a() [MAJOR, MINOR, TINY, EXTRA].compact end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-16 00:00:00.000000000 Z
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
@@ -16,10 +16,21 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
20
- - - ">="
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json-ld
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
21
32
  - !ruby/object:Gem::Version
22
- version: 2.1.1
33
+ version: '2.1'
23
34
  type: :runtime
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +38,20 @@ dependencies:
27
38
  - - "~>"
28
39
  - !ruby/object:Gem::Version
29
40
  version: '2.1'
30
- - - ">="
41
+ - !ruby/object:Gem::Dependency
42
+ name: json-ld-preloaded
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
31
53
  - !ruby/object:Gem::Version
32
- version: 2.1.1
54
+ version: '0.0'
33
55
  - !ruby/object:Gem::Dependency
34
56
  name: ebnf
35
57
  requirement: !ruby/object:Gem::Requirement
@@ -172,7 +194,6 @@ files:
172
194
  - lib/shex/algebra.rb
173
195
  - lib/shex/algebra/and.rb
174
196
  - lib/shex/algebra/annotation.rb
175
- - lib/shex/algebra/base.rb
176
197
  - lib/shex/algebra/each_of.rb
177
198
  - lib/shex/algebra/external.rb
178
199
  - lib/shex/algebra/inclusion.rb
@@ -181,7 +202,6 @@ files:
181
202
  - lib/shex/algebra/one_of.rb
182
203
  - lib/shex/algebra/operator.rb
183
204
  - lib/shex/algebra/or.rb
184
- - lib/shex/algebra/prefix.rb
185
205
  - lib/shex/algebra/satisfiable.rb
186
206
  - lib/shex/algebra/schema.rb
187
207
  - lib/shex/algebra/semact.rb
@@ -192,15 +212,19 @@ files:
192
212
  - lib/shex/algebra/stem_range.rb
193
213
  - lib/shex/algebra/triple_constraint.rb
194
214
  - lib/shex/algebra/triple_expression.rb
195
- - lib/shex/algebra/unary_shape.rb
196
215
  - lib/shex/algebra/value.rb
216
+ - lib/shex/extensions/extension.rb
217
+ - lib/shex/extensions/test.rb
197
218
  - lib/shex/meta.rb
198
219
  - lib/shex/parser.rb
220
+ - lib/shex/shex_context.rb
199
221
  - lib/shex/terminals.rb
222
+ - lib/shex/version.rb
200
223
  homepage: http://ruby-rdf.github.com/shex
201
224
  licenses:
202
225
  - Unlicense
203
- metadata: {}
226
+ metadata:
227
+ yard.run: yri
204
228
  post_install_message:
205
229
  rdoc_options: []
206
230
  require_paths:
@@ -1,6 +0,0 @@
1
- module ShEx::Algebra
2
- ##
3
- class Base < Operator::Binary
4
- NAME = :base
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module ShEx::Algebra
2
- ##
3
- class Prefix < Operator::Binary
4
- NAME = :prefix
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module ShEx::Algebra
2
- ##
3
- class UnaryShape < Operator
4
- NAME = :unaryShape
5
- end
6
- end