shex 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,11 +37,10 @@ class JSON::LD::Context
37
37
  "expressions" => TermDefinition.new("expressions", id: "http://shex.io/ns/shex#expressions", type_mapping: "@id", container_mapping: "@list"),
38
38
  "extra" => TermDefinition.new("extra", id: "http://shex.io/ns/shex#extra", type_mapping: "@id"),
39
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
40
  "include" => TermDefinition.new("include", id: "http://shex.io/ns/shex#include", type_mapping: "@id"),
42
41
  "inverse" => TermDefinition.new("inverse", id: "http://shex.io/ns/shex#inverse", type_mapping: "http://www.w3.org/2001/XMLSchema#boolean"),
43
42
  "iri" => TermDefinition.new("iri", id: "http://shex.io/ns/shex#iri", simple: true),
44
- "label" => TermDefinition.new("label", id: "@id", simple: true),
43
+ "id" => TermDefinition.new("id", id: "@id", simple: true),
45
44
  "language" => TermDefinition.new("language", id: "@language", simple: true),
46
45
  "length" => TermDefinition.new("length", id: "http://shex.io/ns/shex#length", type_mapping: "http://www.w3.org/2001/XMLSchema#integer"),
47
46
  "literal" => TermDefinition.new("literal", id: "http://shex.io/ns/shex#literal", simple: true),
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.3.0
4
+ version: 0.4.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: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.0'
47
+ version: '1.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.0'
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ebnf
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -196,17 +196,15 @@ files:
196
196
  - lib/shex/algebra/annotation.rb
197
197
  - lib/shex/algebra/each_of.rb
198
198
  - lib/shex/algebra/external.rb
199
- - lib/shex/algebra/inclusion.rb
200
199
  - lib/shex/algebra/node_constraint.rb
201
200
  - lib/shex/algebra/not.rb
202
201
  - lib/shex/algebra/one_of.rb
203
202
  - lib/shex/algebra/operator.rb
204
203
  - lib/shex/algebra/or.rb
205
- - lib/shex/algebra/satisfiable.rb
206
204
  - lib/shex/algebra/schema.rb
207
205
  - lib/shex/algebra/semact.rb
208
206
  - lib/shex/algebra/shape.rb
209
- - lib/shex/algebra/shape_ref.rb
207
+ - lib/shex/algebra/shape_expression.rb
210
208
  - lib/shex/algebra/start.rb
211
209
  - lib/shex/algebra/stem.rb
212
210
  - lib/shex/algebra/stem_range.rb
@@ -1,67 +0,0 @@
1
- module ShEx::Algebra
2
- ##
3
- class Inclusion < Operator
4
- include TripleExpression
5
- NAME = :inclusion
6
-
7
- ##
8
- # Creates an operator instance from a parsed ShExJ representation
9
- # @param (see Operator#from_shexj)
10
- # @return [Operator]
11
- def self.from_shexj(operator, options = {})
12
- raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == "Inclusion"
13
- raise ArgumentError, "missing include in #{operator.inspect}" unless operator.has_key?('include')
14
- super
15
- end
16
-
17
- def initialize(arg, **options)
18
- raise ArgumentError, "Shape inclusion must be an IRI or BNode: #{arg}" unless arg.is_a?(RDF::Resource)
19
- super
20
- end
21
-
22
- ##
23
- # In this case, we accept an array of statements, and match based on cardinality.
24
- #
25
- # @param (see TripleExpression#matches)
26
- # @return (see TripleExpression#matches)
27
- # @raise (see TripleExpression#matches)
28
- def matches(arcs_in, arcs_out, depth: 0)
29
- status "referenced_shape: #{operands.first}"
30
- expression = referenced_shape.expression
31
- max = maximum
32
- matched_expression = expression.matches(arcs_in, arcs_out, depth: depth + 1)
33
- satisfy matched: matched_expression.matched, depth: depth
34
- rescue ShEx::NotMatched => e
35
- not_matched e.message, unsatisfied: e.expression, depth: depth
36
- end
37
-
38
- ##
39
- # Returns the referenced shape
40
- #
41
- # @return [Operand]
42
- def referenced_shape
43
- @referenced_shape ||= schema.shapes.detect {|s| s.label == operands.first}
44
- end
45
-
46
- ##
47
- # A Inclusion is valid if it's ancestor schema has any shape with a lable
48
- # the same as it's reference.
49
- #
50
- # An Inclusion object's include property must appear in the schema's shapes map and the corresponding triple expression must be a Shape with a tripleExpr. The function dereference(include) returns the shape's tripleExpr.
51
- def validate!
52
- structure_error("Missing included shape: #{operands.first}") if referenced_shape.nil?
53
- structure_error("Self included shape: #{operands.first}") if referenced_shape == first_ancestor(Shape)
54
- structure_error("Referenced shape must be a Shape: #{operands.first}") unless referenced_shape.is_a?(Shape)
55
- super
56
- end
57
-
58
- ##
59
- # Returns the binary S-Expression (SXP) representation of this operator.
60
- #
61
- # @return [Array]
62
- # @see https://en.wikipedia.org/wiki/S-expression
63
- def to_sxp_bin
64
- ([:inclusion, ([:label, @label] if @label)].compact + operands).to_sxp_bin
65
- end
66
- end
67
- end
@@ -1,71 +0,0 @@
1
- module ShEx::Algebra
2
- ##
3
- class ShapeRef < Operator::Unary
4
- include Satisfiable
5
- NAME = :shapeRef
6
-
7
- def initialize(arg, **options)
8
- structure_error("Shape reference must be an IRI or BNode: #{arg}", exception: ArgumentError) unless arg.is_a?(RDF::Resource)
9
- super
10
- end
11
-
12
- ##
13
- # Creates an operator instance from a parsed ShExJ representation
14
- # @param (see Operator#from_shexj)
15
- # @return [Operator]
16
- def self.from_shexj(operator, options = {})
17
- raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == "ShapeRef"
18
- raise ArgumentError, "missing reference in #{operator.inspect}" unless operator.has_key?('reference')
19
- super
20
- end
21
-
22
- ##
23
- # Satisfies referenced shape.
24
- # @param (see Satisfiable#satisfies?)
25
- # @return (see Satisfiable#satisfies?)
26
- # @raise (see Satisfiable#satisfies?)
27
- # @see [https://shexspec.github.io/spec/#shape-expression-semantics]
28
- def satisfies?(focus, depth: 0)
29
- status "ref #{operands.first.to_s}", depth: depth
30
- schema.enter_shape(operands.first, focus) do |shape|
31
- if shape
32
- matched_shape = shape.satisfies?(focus, depth: depth + 1)
33
- satisfy focus: focus, satisfied: matched_shape, depth: depth
34
- else
35
- status "Satisfy as #{operands.first} was re-entered for #{focus}", depth: depth
36
- satisfy focus: focus, satisfied: referenced_shape, depth: depth
37
- end
38
- end
39
- rescue ShEx::NotSatisfied => e
40
- not_satisfied e.message, focus: focus, unsatisfied: e.expression, depth: depth
41
- end
42
-
43
- ##
44
- # Returns the referenced shape
45
- #
46
- # @return [Shape]
47
- def referenced_shape
48
- @referenced_shape ||= schema.shapes.detect {|s| s.label == operands.first}
49
- end
50
-
51
- ##
52
- # A ShapeRef is valid if it's ancestor schema has any shape with a label
53
- # the same as it's reference.
54
- # A ref cannot reference itself (via whatever path) without going through a TripleConstraint.
55
- # Even when going through TripleConstraints, there can't be a negative reference.
56
- def validate!
57
- structure_error("Missing referenced shape: #{operands.first}") if referenced_shape.nil?
58
- raise ShEx::StructureError, "Self referencing shape: #{operands.first}" if referenced_shape == first_ancestor(Satisfiable)
59
- super
60
- end
61
-
62
- ##
63
- # Returns the binary S-Expression (SXP) representation of this operator.
64
- #
65
- # @return [Array]
66
- # @see https://en.wikipedia.org/wiki/S-expression
67
- def to_sxp_bin
68
- ([:shapeRef, ([:label, @label] if @label)].compact + operands).to_sxp_bin
69
- end
70
- end
71
- end