Formalizing SPARQL rules

Noodling on using MathML for the definitions in the SPARQL spec, and deriving N3 from it.

RDF Term
The set of RDF Terms, RDF-T, is RDF-U union RDF-L union RDF-B
RDF_T RDF_U RDF_L RDF_B
Query Variable
Let V be the set of all query variables. V and RDF-T are disjoint.

hmm... mathml can say "the intersection of V and RDF_T is empty" but not "V and RDF_T are disjoint." Maybe it's extensible... ah yes... csymbol. Hmm... encodings aren't grounded in URI space.

disjointFrom V RDF_T
Triple Pattern
The set of triple patterns is (RDF-U union RDF-B union V) x (RDF-U union V) x (RDF-T union V)

sent comment: let's use the same terms everywhere@@. Term Pattern is RDF-T union V.

@@hmm... Triple Pattern isn't needed is, it? We can skip right to Graph Pattern, no?

TermPattern RDF_T V TriplePattern TermPattern TermPattern TermPattern
Binding
skipping. obsoleted by substitution
Substitution
A substitution S is a partial functional relation from variables to RDF terms or variables. We write S[v] for the RDF term that S pairs with the variable v and define S[v] to be v where there is no such pairing.

@@more on: extending substitution of terms to triples and graphs. Oops! so codomain isn't right; we want onProperty/allValuesFrom

@@move this up: For substution S and Triple Pattern T, S(T) is the triple pattern forms by replacing any variable v in T with S[v].

Triple Pattern Matching
Triple Pattern T matches RDF graph G with substitution S, if S(T) is a triple of G.
T G S TriplePatternT RDF_GraphG SubstitutionS S T G matches S T G
Graph Pattern (Partial Definition) -- Conjunction
A set of triple patterns is a graph pattern GP.
GP GPTriplePattern GraphPatternGP
Graph Pattern Matching
Graph Pattern GP matches RDF graph G with substitution S if S(GP) is a subgraph of G.
GP G S GraphPatternGP RDF_GraphG SubstitutionS entailsSimply G S GP matches S GP G
Pattern Solution
A Pattern Solution of Graph Pattern GP on graph G is any substitution S such that GP matches G with S.

For a graph pattern GP formed as a set of triple patterns, S(G), has no variables and is a subgraph of G.

GP G S GraphPatternGP RDF_GraphG SubstitutionS matchesS GP G patternSolutionG GP S
Query Results
The Query Results, for a given graph pattern GP on G, is written R(GP,G), and is the set of all query solutions such that GP matches G.

R(GP, G) may be the empty set.

@@hmm... I don't think we can write "the set of all S such that..." in N3 yet.

FunctionalProperty R GP GraphPatternGP FunctionalProperty RGP GP G S GraphPatternGP RDF_GraphG SubstitutionS S RGP G matchesS GP G
Optional Matching

Given graph pattern GP1, and graph pattern GP2, let GP= (GP1 union GP2).

The optional match of GP2 of graph G, given GP1, defines a pattern solution PS such that:

If GP matches G, then the solutions of GP is the patterns solutions of GP else the solutions are the pattern solutions of GP1 matching G.

GP1 GP2 GP G PS GraphPatternGP1 GraphPatternGP2 RDF_GraphG SubstitutionS @@

Appendix: MathML as a semantic web rules language

Let's take the classic syllogism, represent it in MathML, and then convert it to N3 via XSLT (mathmlRules.xsl), and then back using the n3.n3@@link parser

All men are mortal:

x Manx Mortalx

Socrates is a man:

Mans

another take at socrates, generated from N3:

who holds type socrates Man holds type who Man holds type who Mortal
s holds talksTo Steve Joe holds talksTo s s holds admits s I talk to myself
DanC@@
$Id: mathml-rules.xml,v 1.25 2006/09/29 04:42:20 connolly Exp $