Feature:SurfaceSyntax

From SPARQL Working Group
Jump to: navigation, search


Feature: Syntactic Forms

This feature page is a record of various syntax improvements for SPARQL that do not involve any change to SPARQL semantics. Each should be equivalent to a SPARQL expression that could be written anyway.

Note that the WG may choose to accept none, some, or all of these surface syntax additions for further specification.

Illustrations

FILTER operators

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?thing ?name
WHERE {
   ?thing ?p ?name .
   FILTER (?p IN (foaf:name foaf:nick rdfs:label))
}

This query can already be written as

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?thing ?name
WHERE{
  ?thing ?p ?name .
  FILTER (?p = foaf:name || ?p = foaf:nick || ?p = rdfs:label)
}

Similarly:

FILTER ( ?x BETWEEN (5 67) )

same as:

FILTER ( ?x >= 5 && ?x <= 67 )

Issue to be fixed: what ?x BETWEEN (5 - 67 - 81) means, is it (5 - 67; - 81) or (5; - 67 - 81) ?

Graph patterns

See Feature:PropertyPaths and Extensions_Proposed_By_OpenLink#Path_Expressions.

Simple property paths, that is, ones not involving the operators for arbitary length paths can be written in standard SPARQL such as operators for concatentation "/", reverse path "^" and alternation "|".

Commas in expression lists

SELECT ?a, ?b, ?c
...

equivalent to

SELECT ?a ?b ?c
...

The rationale for this is that it gives greater familiarity to people used to SQL, and it also makes the syntax of AS easier to read,

?a (?b) AS foo

becomes

?a, ?b AS foo.

Existing Implementation(s)

  • FILTER (?p IN (foaf:name foaf:nick rdfs:label)) is implemented in Virtuoso.

Existing Specification / Documentation

Compatibility

Extensions should be upwards compatible with the previous SPARQL spec. For surface syntax extensions, there should be an equivalent SPARQL query string.

Champions

Use Cases

the FILTER IN operator is a useful shorthand when you have a list of subjects that you want information about. Computas has also allready found it extremely useful when used with DELETE:

DELETE { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (?s IN ( <http://example.org/foo> <http://example.org/foo> )) }

It is quite often the cases that you know the subjects that you want to delete.