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

Class Query


Result of a SPARQL query. It stores to the top of the query tree, and allows some subsequent inquiries on the expanded tree. This class should not be instantiated by the user, it is done by the queryObject method.
Method Summary
  __init__(self, sparqlnode, triples, parent1, parent2)
  __add__(self, other)
This may be useful when several queries are performed and one wants the 'union' of those.
Boolean ask(self)
Whether a specific pattern has a solution or not.
  cluster(self, selection)
Cluster: a combination of Query.clusterBackward and Query.clusterForward.
sparqlGraph clusterBackward(self, selection)
Backward clustering, using all the results of the query as seeds (when appropriate).
sparqlGraph clusterForward(self, selection)
Forward clustering, using all the results of the query as seeds (when appropriate).
sparqlGraph construct(self, pattern)
Expand the subgraph based on the pattern or, if None, the internal bindings.
  describe(self, selection, forward, backward)
The DESCRIBE Form in the SPARQL draft is still in state of flux, so this is just a temporary method, in fact.
  select(self, selection, distinct, limit, orderBy, orderAscend, offset)
Run a selection on the query.

Method Details

__init__(self, sparqlnode, triples, parent1=None, parent2=None)
(Constructor)

Parameters:
sparqlnode - top of the expansion tree
           (type=_SPARQLNode)
triples - triple store
           (type=sparqlGraph)
parent1 - possible parent Query when queries are combined by summing them up
           (type=Query)
parent2 - possible parent Query when queries are combined by summing them up
           (type=Query)

__add__(self, other)
(Addition operator)

This may be useful when several queries are performed and one wants the 'union' of those. Caveat: the triple store must be the same for each argument. This method is used internally only anyway... Efficiency trick (I hope it works): the various additions on subgraphs are not done here; the results are calculated only if really necessary, ie, in a lazy evaluation manner. This is achieved by storing self and the 'other' in the new object

ask(self)

Whether a specific pattern has a solution or not.
Returns:
Boolean

cluster(self, selection)

Cluster: a combination of Query.clusterBackward and Query.clusterForward. @param selection: a selection to define the seeds for clustering via the selection; the result of select used for the clustering seed

clusterBackward(self, selection)

Backward clustering, using all the results of the query as seeds (when appropriate). It is based on the usage of the cluster backward method for triple store.
Parameters:
selection - a selection to define the seeds for clustering via the selection; the result of select used for the clustering seed
Returns:
a new triple store
           (type=sparqlGraph)

clusterForward(self, selection)

Forward clustering, using all the results of the query as seeds (when appropriate). It is based on the usage of the cluster forward method for triple store.
Parameters:
selection - a selection to define the seeds for clustering via the selection; the result of select used for the clustering seed
Returns:
a new triple store
           (type=sparqlGraph)

construct(self, pattern=None)

Expand the subgraph based on the pattern or, if None, the internal bindings.

In the former case the binding is used to instantiate the triplets in the patterns; in the latter, the original statements are used as patterns.

The result is a separate triple store containing the subgraph.
Parameters:
pattern - a GraphPattern instance or None
Returns:
a new triple store
           (type=sparqlGraph)

describe(self, selection, forward=True, backward=True)

The DESCRIBE Form in the SPARQL draft is still in state of flux, so this is just a temporary method, in fact. It may not correspond to what the final version of describe will be (if it stays in the draft at all, that is). At present, it is simply a wrapper around cluster.
Parameters:
selection - a selection to define the seeds for clustering via the selection; the result of select used for the clustering seed
forward - cluster forward yes or no
           (type=Boolean)
backward - cluster backward yes or no
           (type=Boolean)

select(self, selection, distinct=True, limit=None, orderBy=None, orderAscend=None, offset=0)

Run a selection on the query.

@param selection: Either a single query string, or an array or tuple thereof.
@param distinct: if True, identical results are filtered out
@type distinct: Boolean
@param limit: if set to an integer value, the first 'limit' number of results are returned; all of them otherwise
@type limit: non negative integer
@param orderBy: either a function or a list of strings (corresponding to variables in the query). If None, no sorting occurs
on the results. If the parameter is a function, it must take two dictionary arguments (the binding dictionaries), return
-1, 0, and 1, corresponding to smaller, equal, and greater, respectively.
@param orderAscend: if not None, then an array of booelans of the same length as orderBy, True for ascending and False
        for descending. If None, an ascending order is used.
@offset the starting point of return values in the array of results. Obviously, this parameter makes real sense if
some sort of order is defined.
@return: selection results
@rtype: list of tuples
@raise SPARQLError: invalid selection argument

Generated by Epydoc 2.1 on Mon Oct 23 14:11:24 2006 http://epydoc.sf.net