Skip to content

SPARQL Extension Functions

semsol edited this page Mar 14, 2011 · 2 revisions

SPARQL can be extended with custom (URI-based) functions. ARC is based on MySQL and following the pattern below, you can add a variety of MySQL-specific functions to your SPARQL queries. (Note that these extensions are most probably not going to work in other SPARQL engines.)

The MySQL function namespace is http://web-semantics.org/ns/mysql/

A specific function identifier: http://web-semantics.org/ns/mysql/**concat **

Example:

PREFIX mysql: <http://web-semantics.org/ns/mysql/> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 

SELECT ?person WHERE {
  ?person foaf:givenname ?n1 ;
          foaf:family_name ?n2 .
  FILTER (mysql:concat(?n1, " ", ?n2) = "Alec Tronnick") .
}

By default, extension functions are enabled in ARC's RDF Store class, but disabled in the Endpoint class, as they could introduce security risks. In order to activate them in your endpoint, add a store_allow_extension_functions option to your configuration array:

$config = array(
  ...
  'store_allow_extension_functions' => 1,
  ...
);

/* instantiation */
$ep = ARC2::getStoreEndpoint($config);