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

Class SPARQL

Known Subclasses:
SPARQLGraph

A wrapper class around the RDFLib triple store implementing the Sparql utilities. This class is a superclass of the myTripleStore class; in other words, the methods are usualy 'seen' through an instance of that class rather than directly.
Method Summary
  __init__(self)
list of tuples query(self, selection, patterns, optionalPatterns)
A shorthand for the creation of a Query instance, returning the result of a Query.select right away.
Query queryObject(self, patterns, optionalPatterns)
Creation of a Query instance.
  sparqlQuery(self, selectU, where, constraints, optional)
A shorthand for the creation of a Query instance and returning the result of a selection right away.

Method Details

query(self, selection, patterns, optionalPatterns=[])

A shorthand for the creation of a Query instance, returning the result of a Query.select right away. Good for most of the usage, when no more action (clustering, etc) is required.
Parameters:
selection - a list or tuple with the selection criteria, or a single string. Each entry is a string that begins with a "?".
patterns - either a GraphPattern instance or a list of instances thereof. Each pattern in the list represent an 'OR' (or 'UNION') branch in SPARQL.
optionalPatterns - either a GraphPattern instance or a list of instances thereof. For each elements in the 'patterns' parameter is combined with each of the optional patterns and the results are concatenated. The list may be empty.
Returns:
list of query results
           (type=list of tuples)

queryObject(self, patterns, optionalPatterns=[])

Creation of a Query instance.
Parameters:
patterns - either a GraphPattern instance or a list of instances thereof. Each pattern in the list represent an 'OR' (or 'UNION') branch in SPARQL.
optionalPatterns - either a GraphPattern instance or a list of instances thereof. For each elements in the 'patterns' parameter is combined with each of the optional patterns and the results are concatenated. The list may be empty.
Returns:
Query object
           (type=Query)

sparqlQuery(self, selectU, where, constraints=[], optional=[])

A shorthand for the creation of a Query instance and returning the result of a selection right away. Good for most of the usage, when no more action (clustering, etc) is necessary.

This method is deprecated and may disappear from future releases. Use the query method.
Parameters:
selectU - a tuple with the selection criteria. Each entry is a string that begins with a "?". If not, it is ignored. If the selection is only one single string, then the parameter can also be a single string instead of a tuple.
where - an array of statement tuples. The tuples are either three or four elements long. Each of the first three entries in the tuples is either a string or an RDFLib Identifier (ie, a Literal or a URIRef). If a string and if the string begins by "?", it is an unbound variable, otherwise a Literal is created on the fly. The optional fourth entry in the tuple is a function reference, ie, a per-pattern condition. The method is invoked with the bound versions of the tuple variables; if it returns False, the query is stopped for those bindings. An additional tweak: an element in 'where' may be a list of tuples, instead of a tuple. This is interpreted as an 'or', ie, several queries will be issued by replacing the list with its elements respectively, and the resulting bindings will be concatenated.
constraints - a list of functions. All functions will be invoked with a full binding if found. The input is a dictionary for the binding, the return value should be true or false. The conditions are 'and'-d, ie, if one returns false, that particular binding is rejected.
optional - like the 'where' array. The subgraph is optional: ie, if no triple are found for these subgraph, the search goes on (and the corresponding select entry is set to None)
Returns:
list of query results

Depreciated: this was an earlier implementation version and is kept for backward compatibility only


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