-
Notifications
You must be signed in to change notification settings - Fork 4
Built in Functions
Zachary Whitley edited this page Apr 2, 2019
·
1 revision
Motivating example from S.Bichof's MS thesis, p50 (72 of 207); also see presentation:
- Fixes unintended behavior of nested queries.
- Extends the scope of a dataset over subqueries and allows blank node joins See corrected p54 (76 of 207)
xQuery callable Functions:
-
xsparql:createScopedDataset($query,$id)
: evaluate a SPARQL query, storing the bindings to be reused later. -
xsparql:sparqlScopedDataset($query,$id,$joinVars,$pos)
: evaluate a SPARQL query, using previously stored dataset$id
.$joinVars
: comma-separated joining variables that will be put in the initial binding of$query
$pos
is the current iteration -
_xsparql:deleteScopedDataset($id)
: delete a scoped dataset -
xsparql:scopedDatasetPopResults($id)
: delete the last results from the stack
The classes bind Java functions to xQuery ones
_xsparql Namespace ("http://xsparql.deri.org/demo/xquery/xsparql.xquery")
- createScopedDatasetExtFunction - binding for the createScopedDataset as above
- deleteScopedDatasetExtFunction - binding for the deleteScopedDataset
- scopedDatasetPopResultsExtFunction - delete the last results from the stack
- sparqlQueryExtFunction - binding for the sparqlQuery function
- sparqlScopedDatasetExtFunction - binding for the sparqlScopedDataset function
- sqlQueryExtFunction - binding for the _sqlQuery function
- turtleGraphToURIExtFunction - Saves temp graph to file
- scopedDatasetPopResultsExtFunction - binding for the scopedDatasetPopResults function
- doPostQueryExtFunction - Can execute SQL queries as sqlQuery(), not sure what is the difference.
- createNamedGraphExtFunction - binding for the createNamedGraph function
- deleteNamedGraphExtFunction - binding for the deleteNamedGraph function
- sparqlQueryTDBExtFunction - binding for the _sparqlQueryTDB function
xsparql Namespace ("http://xsparql.deri.org/demo/xquery/sparql-functions.xquery")
- getRDBTableAttributesExtFunction - receives the information about attributes from a specific table
let $table := xsparql:getRDBTableAttributes("EMP")
return $table
result:
<metadata>
<foreignKeys/>
<columns>
<column name=""EMPNO"" type="INT"/>
<column name=""ENAME"" type="VARCHAR"/>
<column name=""JOB"" type="VARCHAR"/>
<column name=""DEPTNO"" type="INT"/>
</columns>
</metadata>
- getRDBTablesExtFunction - receives the names of all tables in the current db
let $tables := xsparql:getRDBTables()
return $tables
result:
<relations>
<relation>EMP</relation>
<relation>test1</relation>
</relations>
- jsonDocExtFunction - convert JSON to XML
- sqlQuery
let $res := "
Select EMPNO
, ENAME
, JOB
, DEPTNO
from EMP
"
for row $row from sqlQuery($res)
return $row
result:
<result>
<SQLbinding type="INT" name=""EMPNO"">7369</SQLbinding>
<SQLbinding type="VARCHAR" name=""ENAME"">SMITH</SQLbinding>
<SQLbinding type="VARCHAR" name=""JOB"">CLERK</SQLbinding>
<SQLbinding type="INT" name=""DEPTNO"">10</SQLbinding>
</result>
- xqueryEvaluatorSaxon - registers the Saxon extention functions
These replace blank nodes to a URL using a specific prefix, to guarantee sameness between datasets. See Skolemisation in Wikipedia. They leave other terms unmolested.
-
xsparql:skolem($term,$prefix)
: skolemize a term using the provided prefix -
xsparql:skolem($term)
: skolemise a term using default prefix http://xsparql.deri.org/skolem# -
xsparql:skolemise($terms)
: skolemise sequence of terms -
xsparql:skolemiseGraph($graph,$prefix)
: skolemise all blank nodes in a graph using the provided prefix -
xsparql:skolemiseGraph($graph)
: skolemise all blank nodes in a graph using default prefix http://xsparql.deri.org/skolem#
xsparql:isBlank($term)
xsparql:isIRI($term)
xsparql:isLiteral($term)
xsparql:bound($term)
xsparql:datatype($term)
xsparql:lang($term)
Examples:
{fn:concat($o," : ",xsparql:datatype($o)," : ",xsparql:lang($o)) }
-
xsparql:createURI($uri)
: creates URI from string -
xsparql:createBNode($name)
: creates blank node using provided string name -
xsparql:createLiteral($str)
: creates plain-text literal. Is it equivalent to one with datatypexsd:string
as per RDF 1.1? -
xsparql:createLiteral($str,$lang,$datatype)
: creates literal with given value, lang and datatype. Allows both lang and datatype but shouldn't. -
xsparql:createTerm($item)
: creates RDF term, guessing the type from the form of input: literal if it has XML typexs:integer
(but that's not carried over to the datatype), blank node if it matches_:\w+
, URI if it has XML typexs:anyURI
, URI if it starts with one of 4-5 fixed schemes (see bug https://github.com/semantalytics/xsparql/issues/4), literal otherwise -
xsparql:createTerm($item,$lang,$datatype)
: creates RDF term, guessing the type from the form of input. If blank node or URI is guessed, the lang and datatype are ignored.
From test_datatype_lang.xsparql:
declare option xsparql:keepRDFTerms "true";
This was added on 2014-09-08 but is now removed. I tested the query and it returns fine, so I guess this is now always enabled