Skip to content
Zachary Whitley edited this page Apr 2, 2019 · 1 revision

Working with Scoped Datasets

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

SAXON Extension Functions Classes

The classes bind Java functions to xQuery ones

let $table := xsparql:getRDBTableAttributes("EMP")
return $table

result:

<metadata>
   <foreignKeys/>
   <columns>
      <column name="&#34;EMPNO&#34;" type="INT"/>
      <column name="&#34;ENAME&#34;" type="VARCHAR"/>
      <column name="&#34;JOB&#34;" type="VARCHAR"/>
      <column name="&#34;DEPTNO&#34;" type="INT"/>
   </columns>
</metadata>
let $tables := xsparql:getRDBTables()
return $tables

result:

<relations>
   <relation>EMP</relation>
   <relation>test1</relation>
</relations>
let $res := "
       Select EMPNO
            , ENAME
            , JOB
            , DEPTNO
         from EMP
       "

for row $row from sqlQuery($res)
return $row

result:

<result>
   <SQLbinding type="INT" name="&#34;EMPNO&#34;">7369</SQLbinding>
   <SQLbinding type="VARCHAR" name="&#34;ENAME&#34;">SMITH</SQLbinding>
   <SQLbinding type="VARCHAR" name="&#34;JOB&#34;">CLERK</SQLbinding>
   <SQLbinding type="INT" name="&#34;DEPTNO&#34;">10</SQLbinding>
</result>

No namespace

Skolemisation 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#

Functions Implemented in XQuery

https://github.com/semantalytics/xsparql/tree/master/xsparql-rewriter/src/main/resources/xquery/sparql-functions.xquery

Term Accessors

  • 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)) }

Create RDF Terms

  • 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 datatype xsd: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 type xs:integer (but that's not carried over to the datatype), blank node if it matches _:\w+, URI if it has XML type xs: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.

keepRDFTerms

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

Clone this wiki locally