Skip to content

Commit

Permalink
Property path grouping and named graphs containing a property path.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jan 11, 2022
1 parent 9a507e4 commit 2b484da
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/sparql/algebra/operator/alt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def execute(queryable, **options, &block)
#
# @return [String]
def to_sparql(**options)
"#{operands.first.to_sparql(**options)}|#{operands.last.to_sparql(**options)}"
"(#{operands.first.to_sparql(**options)}|#{operands.last.to_sparql(**options)})"
end
end # Alt
end # Operator
Expand Down
22 changes: 20 additions & 2 deletions lib/sparql/algebra/operator/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Operator
# :x :p :z
# GRAPH ?g { :x :b ?a . GRAPH ?g2 { :x :p ?x } }
# }
#
# @example SSE (syntax-graph-05.rq)
# (prefix ((: <http://example.org/>))
# (join
Expand All @@ -47,6 +48,21 @@ class Operator
# (graph ?g2
# (bgp (triple :x :p ?x)))))))
#
# @example SPARQL Grammar (pp06.rq)
# prefix ex: <http://www.example.org/schema#>
# prefix in: <http://www.example.org/instance#>
#
# select ?x where {
# graph ?g {in:a ex:p1/ex:p2 ?x}
# }
#
# @example SSE (syntax-graph-05.rq)
# (prefix ((ex: <http://www.example.org/schema#>)
# (in: <http://www.example.org/instance#>))
# (project (?x)
# (graph ?g
# (path in:a (seq ex:p1 ex:p2) ?x))))
#
# @see https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
class Graph < Operator::Binary
include Query
Expand Down Expand Up @@ -117,8 +133,10 @@ def rewrite(&block)
# Treat this as a top-level, generating SELECT ... WHERE {}
# @return [String]
def to_sparql(top_level: true, **options)
str = "GRAPH #{operands.first.to_sparql(**options)} " +
operands.last.to_sparql(top_level: false, **options)
query = operands.last.to_sparql(top_level: false, **options)
# Paths don't automatically get braces.
query = "{\n#{query}\n}" unless query.start_with?('{')
str = "GRAPH #{operands.first.to_sparql(**options)} " + query
top_level ? Operator.to_sparql(str, **options) : str
end
end # Graph
Expand Down
15 changes: 12 additions & 3 deletions lib/sparql/algebra/operator/notoneof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class Operator
# @example SPARQL Grammar
# PREFIX ex: <http://www.example.org/schema#>
# PREFIX in: <http://www.example.org/instance#>
# ASK { in:b ^ex:p in:a }
# ASK { in:a !(ex:p1|ex:p2) ?x }
#
# @example SSE
# (prefix ((ex: <http://www.example.org/schema#>)
# (in: <http://www.example.org/instance#>))
# (in: <http://www.example.org/instance#>))
# (ask
# (path in:b (reverse ex:p) in:a)))
# (path in:a (notoneof ex:p1 ex:p2) ?x)))
#
# @see https://www.w3.org/TR/sparql11-query/#eval_negatedPropertySet
class NotOneOf < Operator
Expand Down Expand Up @@ -56,6 +56,15 @@ def execute(queryable, **options, &block)
block.call(solution)
end
end

##
#
# Returns a partial SPARQL grammar for this operator.
#
# @return [String]
def to_sparql(**options)
"!(" + operands.to_sparql(delimiter: ' | ', **options) + ')'
end
end # NotOneOf
end # Operator
end; end # SPARQL::Algebra
13 changes: 12 additions & 1 deletion lib/sparql/algebra/operator/reverse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class Operator
# (in: <http://www.example.org/instance#>))
# (ask (path in:b (reverse ex:p) in:a)))
#
# @example SPARQL Grammar
# prefix ex: <http://www.example.org/schema#>
# prefix in: <http://www.example.org/instance#>
#
# select * where { in:c ^(ex:p1/ex:p2) ?x }
#
# @example SSE
# (prefix ((ex: <http://www.example.org/schema#>)
# (in: <http://www.example.org/instance#>))
# (path in:c (reverse (seq ex:p1 ex:p2)) ?x))
#
# @see https://www.w3.org/TR/sparql11-query/#defn_evalPP_inverse
class Reverse < Operator::Unary
include Query
Expand Down Expand Up @@ -65,7 +76,7 @@ def execute(queryable, **options, &block)
#
# @return [String]
def to_sparql(**options)
"^" + operands.first.to_sparql(**options)
"^(" + operands.first.to_sparql(**options) + ')'
end
end # Reverse
end # Operator
Expand Down
2 changes: 1 addition & 1 deletion lib/sparql/algebra/operator/seq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def execute(queryable, **options, &block)
#
# @return [String]
def to_sparql(**options)
operands.to_sparql(delimiter: '/', **options)
'(' + operands.to_sparql(delimiter: '/', **options) + ')'
end
end # Seq
end # Operator
Expand Down
5 changes: 4 additions & 1 deletion lib/sparql/algebra/operator/sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class Operator
##
# The SPARQL UPDATE `sequence` operator.
#
# Sequences through each operand
# Sequences through each operand.
#
# [103] CollectionPath ::= '(' GraphNodePath+ ')'
#
# @see https://www.w3.org/TR/sparql11-query/#collections
class Sequence < Operator
include SPARQL::Algebra::Update

Expand Down
14 changes: 3 additions & 11 deletions spec/suite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,19 @@
skip "Decimal format changed in SPARQL 1.1"
when 'syntax-esc-04.rq', 'syntax-esc-05.rq'
skip "PNAME_LN changed in SPARQL 1.1"
when 'syn-pp-in-collection.rq'
pending "CollectionPath"
when 'bind05.rq', 'bind08.rq', 'syntax-bind-02.rq', 'strbefore02.rq'
skip "Equivalent form"
when 'exists03.rq', 'exists04.rq', 'exists05.rq'
skip('TODO Exists')
when 'agg-groupconcat-1.rq', 'agg-groupconcat-2.rq', 'agg-groupconcat-3.rq',
'agg-sample-01.rq', 'sq03.rq', 'sq08.rq', 'sq09.rq', 'sq11.rq', 'sq12.rq',
'agg-sample-01.rq', 'sq08.rq', 'sq09.rq', 'sq11.rq', 'sq12.rq',
'sq13.rq', 'sq14.rq', 'syntax-SELECTscope1.rq', 'syntax-SELECTscope3.rq'
pending("TODO SubSelect")
when 'pp06.rq', 'path-ng-01.rq', 'path-ng-02.rq'
pending "TODO graph name on property path"
when 'pp09.rq', 'pp10.rq', 'path-p2.rq', 'path-p4.rq'
pending "TODO property path grouping"
when 'syntax-bindings-02a.rq', 'syntax-bindings-03a.rq', 'syntax-bindings-05a.rq'
pending "TODO top-level values"
when 'syn-pname-05.rq', 'syn-pname-06.rq', 'syn-pname-07.rq', 'syn-codepoint-escape-01.rq',
'1val1STRING_LITERAL1_with_UTF8_boundaries.rq', '1val1STRING_LITERAL1_with_UTF8_boundaries_escaped.rq'
pending "TODO escaping"
when 'syn-pp-in-collection.rq'
pending "TODO runtime error and list representation"
when 'strafter02.rq '
pending "TODO odd project multple bindings"
end
t.logger = RDF::Spec.logger
t.logger.debug "Source:\n#{t.action.query_string}"
Expand Down

0 comments on commit 2b484da

Please sign in to comment.