- From: Geoff Chappell <gchappell@intellidimension.com>
- Date: Tue, 6 Nov 2007 07:18:11 -0500
- To: <public-sparql-dev@w3.org>
- Message-ID: <026001c8206f$19c15b20$6101a8c0@GSC810>
I've been experimenting with some syntax for expressing rules in sparql that
can also handle cascaded queries/subselects.
It looks like:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
with (
construct {?a rdf:type rdf:Property. ?x rdf:type rdfs:Resource }
where {?x ?a ?y}
construct {?y rdf:type rdfs:Resource} where {?x ?a ?y.
filter(isuri(?y))}
construct {?x rdf:type ?z} where {?a rdfs:domain ?z. ?x ?a ?y}
construct {?u rdf:type ?z} where {?a rdfs:range ?z. ?x ?a ?u
filter(isuri(?u))}
construct {?a rdfs:subPropertyOf ?c} where {?a
rdfs:subPropertyOf ?b. ?b rdfs:subPropertyOf ?c}
construct {?x ?b ?y} where {?a rdfs:subPropertyOf ?b. ?x ?a ?y}
construct {?x rdfs:subClassOf rdfs:Resource} where {?x rdf:type
rdfs:Class}
construct {?a rdfs:subClassOf ?c} where {?a rdfs:subClassOf ?b.
?b rdfs:subClassOf ?c}
construct {?a rdf:type ?y} where {?x rdfs:subClassOf ?y. ?a
rdf:type ?x}
)
select * where {?s ?p ?o}
which deals nicely with triple rules (WITH syntax is similar in concept to
CTEs in SQL Server). I'm also supporting non-triple rules with a
named-select syntax
with
(
select ?s where {?s ?p ?o} as ex:myselect
)
select * where {?s ?p ?o. ROWSET ex:myselect (?s)}
The ROWSET operator allows you to reference a named select but also allows
you to make use of built-in, non-functional relations that don't fit nicely
as functions in a filter (e.g. a builtin to expose a relational table to
sparql queries).
Anyone doing anything similar (e.g. rules in sparql?). Does this look like a
reasonable approach?
-Geoff
Received on Tuesday, 6 November 2007 12:18:30 UTC