Package rdflib :: Package sparql :: Module sparql
[show private | hide private]
[frames | no frames]

Module rdflib.sparql.sparql

SPARQL implementation on top of RDFLib Implementation of the <a href="http://www.w3.org/TR/rdf-sparql-query/">W3C SPARQL</a> language (version April 2005). The basic class here is supposed to be a superclass of rdflibUtils.myTripleStore; it has been separated only for a better maintainability.

There is a separate description for the functionalities.
Classes
Query Result of a SPARQL query.
SPARQL A wrapper class around the RDFLib triple store implementing the Sparql utilities.
_SPARQLNode The SPARQL implementation is based on the creation of a tree, each level for each statement in the 'where' clause of SPARQL.

Exceptions
SPARQLError Am SPARQL error has been detected

Function Summary
  _checkOptionals(pattern, optionals)
The following remark in the SPARQL document is important:
  _createInitialBindings(pattern)
Creates an initial binding directory for the Graph Pattern by putting a None as a value for each query variable.
  _createResource(v)
Create an RDFLib Literal instance with the corresponding XML Schema datatype set.
Boolean _isResQuest(r)
Is 'r' a request string (ie, of the form "?XXX")?
  _processResults(select, arr)
The result in an expansion node is in the form of an array of binding dictionaries.
string _schemaType(v)
Return an XML Schema type starting from a Python variable.
  _unfoldNestedLists(args)
To unfold nested lists of the sort = [t,[t1,t2],tt,ttt] into [t,t1,tt,ttt] and [t,t2,tt,ttt].

Variable Summary
bool Debug = False
URIRef JunkResource = u'http://www.ivan-herman.net/SPARQLJunk'
str type_date = 'http://www.w3.org/2001/XMLSchema#date'
str type_dateTime = 'http://www.w3.org/2001/XMLSchema#dateTi...
str type_decimal = 'http://www.w3.org/2001/XMLSchema#decimal...
str type_double = 'http://www.w3.org/2001/XMLSchema#double'
str type_float = 'http://www.w3.org/2001/XMLSchema#float'
str type_integer = 'http://www.w3.org/2001/XMLSchema#integer...
str type_long = 'http://www.w3.org/2001/XMLSchema#long'
str type_string = 'http://www.w3.org/2001/XMLSchema#string'
str type_time = 'http://www.w3.org/2001/XMLSchema#time'
dict _basicTypes = {<type 'int'>: 'http://www.w3.org/2001/XML...
dict _extraTypes = {<type 'datetime.datetime'>: 'http://www.w...
str _graphKey = '$$GRAPH$$'
str _questChar = '?'

Function Details

_checkOptionals(pattern, optionals)

The following remark in the SPARQL document is important:

"If a new variable is mentioned in an optional block (as mbox and hpage are mentioned in the previous example), that variable can be mentioned in that block and can not be mentioned in a subsequent block."

What this means is that the various optional blocks do not interefere at this level and there is no need for a check whether a binding in a subsequent block clashes with an earlier optional block.

This method checks whether this requirement is fulfilled. Raises a SPARQLError exception if it is not (the rest of the algorithm relies on this, so checking it is a good idea...)
Parameters:
pattern - graph pattern
           (type=GraphPattern)
optionals - graph pattern
           (type=GraphPattern)
Raises:
SPARQLError - if the requirement is not fulfilled

_createInitialBindings(pattern)

Creates an initial binding directory for the Graph Pattern by putting a None as a value for each query variable.
Parameters:
pattern - graph pattern
           (type=GraphPattern)

_createResource(v)

Create an RDFLib Literal instance with the corresponding XML Schema datatype set. If the variable is already an RDFLib resource, it simply returns the resource; otherwise the corresponding Literal. A SPARQLError Exception is raised if the type is not implemented.

The Literal contains the string representation of the variable (as Python does it by default) with the corresponding XML Schema URI set.
Parameters:
v - Python variable
Returns:
either an RDFLib Literal (if 'v' is not an RDFLib Resource), or the same variable if it is already an RDFLib resource (ie, Literal, BNode, or URIRef)
Raises:
SPARQLError - if the type of 'v' is not implemented

_isResQuest(r)

Is 'r' a request string (ie, of the form "?XXX")?
Returns:
Boolean

_processResults(select, arr)

The result in an expansion node is in the form of an array of binding dictionaries. The caller should receive an array of tuples, each tuple representing the final binding (or None) in the order of the original select. This method is the last step of processing by processing these values to produce the right result.
Parameters:
select - the original selection list. If None, then the binding should be taken as a whole (this corresponds to the SELECT * feature of SPARQL)
arr - the array of bindings
           (type=an array of dictionaries)
Returns:
a list of tuples with the selection results

_schemaType(v)

Return an XML Schema type starting from a Python variable. An exception is raised if the variable does not corresponds to any of the schema types that are allowed by this implementation. A SPARQLError Exception is raised if the type represents a non-implemented type.
Parameters:
v - Python variable
Returns:
URI for the XML Datatype
           (type=string)
Raises:
SPARQLError - if the type of 'v' is not implemented

_unfoldNestedLists(args)

To unfold nested lists of the sort = [t,[t1,t2],tt,ttt] into [t,t1,tt,ttt] and [t,t2,tt,ttt]. Returns the list of lists.

This utility is necessary to maintain the deprecated interfaces. When those disappear, this utility can be deleted, too
Parameters:
args - list
Returns:
unfolded list of lists

Variable Details

Debug

Type:
bool
Value:
False                                                                  

JunkResource

Type:
URIRef
Value:
u'http://www.ivan-herman.net/SPARQLJunk'                               

type_date

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#date'                                

type_dateTime

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#dateTime'                            

type_decimal

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#decimal'                             

type_double

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#double'                              

type_float

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#float'                               

type_integer

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#integer'                             

type_long

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#long'                                

type_string

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#string'                              

type_time

Type:
str
Value:
'http://www.w3.org/2001/XMLSchema#time'                                

_basicTypes

Type:
dict
Value:
{<type 'float'>: 'http://www.w3.org/2001/XMLSchema#float',
 <type 'int'>: 'http://www.w3.org/2001/XMLSchema#integer',
 <type 'long'>: 'http://www.w3.org/2001/XMLSchema#long',
 <type 'str'>: '',
 <type 'unicode'>: ''}                                                 

_extraTypes

Type:
dict
Value:
{<type 'datetime.time'>: 'http://www.w3.org/2001/XMLSchema#time',
 <type 'datetime.datetime'>: 'http://www.w3.org/2001/XMLSchema#dateTim\
e',
 <type 'datetime.date'>: 'http://www.w3.org/2001/XMLSchema#date'}      

_graphKey

Type:
str
Value:
'$$GRAPH$$'                                                            

_questChar

Type:
str
Value:
'?'                                                                    

Generated by Epydoc 2.1 on Wed Jun 29 09:50:16 2005 http://epydoc.sf.net