SPARQLExtensionDescriptions

From VoCamp Wiki
Jump to: navigation, search

Some work done by LeighDodds at VoCampDCOctober2009.

Problem Statement[edit]

There are many SPARQL extensions available from a variety of different SPARQL implementations. SPARQL 1.0 requires extension functions to have a URI, however none of those URIs typically resolve. It would be useful to publish metadata at those URIs to support interoperability, validation, etc.

SPARQL 1.1 includes a Service Description specification which also encourages assignment of URIs to language extensions and entailment regimes, but does not say how to describe those features.

By describing functions and extensions, we can support the following use cases:

  • Improve documentation and understanding of SPARQL extensions
  • Promote interoperability between endpoints by encouraging them to support the same extensions and/or identifying how to map between equivalent extensions
  • Validate SPARQL queries to determine whether it is using extensions, and whether those extensions are supported by an endpoints

For more background on SPARQL extensions see Surveying and Classifying SPARQL Extensions.

Sample SPARQL Query With Extensions[edit]

The following SPARQL query includes three extensions:

One thing to note is that without prior knowledge there's no way to determine that the prop:member extension is a SPARQL extension rather than an actual predicate that exists in the data. This problem doesn't exist for extensions functions as they are used in a specific context. Language extensions are also easily identified.

PREFIX list: <http://jena.hpl.hp.com/ARQ/list#>
PREFIX func: <http://jena.hpl.hp.com/ARQ/function#>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX ex: <http://example.org/vocab/>

SELECT ?doc ?contributor WHERE {
   ?s dc:modified ?created.
   ?s ex:authors ?authorList.
   ?authorList list:member ?author.
   LET ( ?contributor := ?author )
   FILTER ( ?created < func:now() )
}

Goals:

  • The URIs for the filter and property functions should be dereferencable and should return some useful metadata
  • The language extension (LET) does not have a URI in the query, but should be described in a SPARQL Service Description document. That URI should return useful data when de-referenced

Draft Extension Description Schema[edit]

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix vann: <http://purl.org/vocab/vann/> .
@prefix version: <http://www.w3.org/2003/06/sw-vocab-status/ns#> .
@prefix ssd: <http://www.w3.org/ns/sparql-service-description#> .
@prefix sed: <http://purl.org/net/schemas/sparql-extension-description/> .

############################################################################
# General description of the schema
############################################################################

<http://purl.org/net/schemas/sparql-extension-description>
  rdfs:comment "A vocabulary for describing SPARQL extensions and function libraries. The vocabulary is intended to support the publishing of descriptive terms at the URIs associated with SPARQL extensions to promote interoperability, validation of SPARQL queries, and general ease of use of"@en ;
  dc:title "SPARQL Extensions Schema"@en ;

  foaf:maker <http://www.ldodds.com#me> ;
  dc:created "2009-10-30"^^xsd:date .

<http://www.ldodds.com#me> a foaf:Person ;
  foaf:name "Leigh Dodds" .

############################################################################
# Classes and Terms from SPARQL Service Description
############################################################################

ssd:Language a rdfs:Class.
ssd:Function a rdfs:Class.

ssd:ScalarFunction a rdfs:Class;
 rdfs:subClassOf ssd:Function;
 rdfs:label "An instance of sd:ScalarFunction represents an extension function that may be used in a SPARQL FILTER/HAVING clause or a project expression"@en.

ssd:AggregateFunction a rdfs:Class;
 rdfs:subClassOf ssd:Function;
 rdfs:label "An instance of sd:AggregateFunction represents an extension function that may be used in a SPARQL aggregate query HAVING clause or project expression"@en.

ssd:EntailmentRegime a rdfs:Class;
 rdfs:label "An instance of sd:EntailmentRegime represents an entailment regime used in basic graph pattern matching"@en.

############################################################################
# Classes
############################################################################

sed:FunctionLibrary a rdfs:Class;
 rdfs:label "Function Library";
 rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
 rdfs:comment "A library of SPARQL extension functions".

#The following should really be in the SPARQL SSD namespace!
sed:FunctionalPredicate a rdfs:Class;
 rdfs:label "functional predicate";
 rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
 rdfs:comment "A SPARQL functional predicate. aka property function or magic property".

sed:SPARQLProcessor a rdfs:Class;
 rdfs:label "";
 rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
 rdfs:comment "An implementation of the SPARQL specification. A SPARQL Processor underpins a service or endpoint".

############################################################################
# Properties
############################################################################

sed:includedIn a rdf:Property;
  rdfs:label "included in";
  rdfs:comment "Indicates that a SPARQL Function is included in a Function Library";
  rdfs:range sed:FunctionLibrary;
  rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
  rdfs:domain ssd:Function.

sed:includes a rdf:Property;
  rdfs:label "includes";
  rdfs:comment "Indicates that a Function Library contains a specific SPARQL Function";
  rdfs:range ssd:Function;
  rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
  rdfs:domain sed:FunctionLibrary.

sed:functionLibrary a rdf:Property;
  rdfs:label "function library";
  rdfs:comment "A Function Library supported by a SPARQL endpoint. Implies that the endpoint supports all of the functions included in the library";
  rdfs:range ssd:FunctionLibrary;
  rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
  rdfs:domain ssd:Service.

sed:implementsLibrary a rdf:Property;
  rdfs:label "implements library";
  rdfs:comment "Used to relate a SPARQL Processor to a function library that it completely implements";
  rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
  rdfs:range sed:FunctionLibrary;
  rdfs:domain sed:SparqlProcessor.

sed:implements a rdf:Property;
  rdfs:label "implements";
  rdfs:comment "Used to relate a SPARQL Processor to a SPARQL function that it implements";
  rdfs:isDefinedBy <http://purl.org/net/schemas/sparql-extension-description/>;
  rdfs:range ssd:Function;
  rdfs:domain sed:SparqlProcessor.

Examples[edit]

<http://jena.hpl.hp.com/ARQ/function> a sed:FunctionLibrary;
  dc:title "ARQ Function Library";
  dc:description "A collection of SPARQL extension functions implemented by the ARQ engine";
  foaf:homepage <http://jena.sourceforge.net/ARQ/library-function.html>;
  sed:includes <http://jena.hpl.hp.com/ARQ/function#sha1sum>.
  
<http://jena.hpl.hp.com/ARQ/function#sha1sum> a ssd:ScalarFunction;
  rdfs:label "sha1sum";
  dc:description "Calculate the SHA1 checksum of a literal or URI.";
  sed:includedIn <http://jena.hpl.hp.com/ARQ/function#>.

<http://jena.hpl.hp.com/ARQ/list> a sed:FunctionLibrary;
  dc:title "ARQ Property Function Library";
  dc:description "A collection of SPARQL property functions for manipulating RDF collections, implemented by the ARQ engine";
  foaf:homepage <http://jena.sourceforge.net/ARQ/library-propfunc.html>;
  sed:includes <http://jena.hpl.hp.com/ARQ/list#member>.
  
<http://jena.hpl.hp.com/ARQ/list#member> a sed:FunctionalPredicate;
  rdfs:label "member";
  dc:description "Membership of an RDF List (RDF Collection). If list is not bound or a constant, find and iterate all lists in the graph (can be slow) else evaluate for one particular list. If member a variable, generate solutions with member bound to each element in the list. If member is bound or a constant expression, test to see if a member of the list.";
  sed:includedIn <http://jena.hpl.hp.com/ARQ/list#>.

<http://jena.hpl.hp.com/ARQ#self> a sed:SparqlProcessor.
  foaf:homepage <http://jena.hpl.hp.com/ARQ>;
  rdfs:label "ARQ";
  sed:implementsLibrary <http://jena.hpl.hp.com/ARQ/function>;
  sed:implementsLibrary <http://jena.hpl.hp.com/ARQ/list>.

Adding More Detail[edit]

We might want to model functions in more detail, e.g. to indicate their parameters etc. Its not clear whether this level of detail is really useful except for perhaps code assistance or validation. The basic properties described above are probably useful in the majority of cases.

If we did add more detail, what would be required?

  • For extension functions: list of parameters and their types; return type
  • For functional predicates:
    • whether the subject must be bound to a a value, or whether it can be a variable
    • whether the object must be bound to a a value, or whether it can be a variable
    • whether the subject can be a list (of variables and/or values)
    • whether the object can be a list (of variables and/or values)
    • the RDF type of the subject or object (if they can be bound to a resource rather than a variable)
    • where a list is being used to pass parameters (in either the subject or object position): the meaning of each item in the list, and their expected types