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.
myTripleStore clusterBackward(self, selection)
Backward clustering, using all the results of the query as seeds (when appropriate).
myTripleStore clusterForward(self, selection)
Forward clustering, using all the results of the query as seeds (when appropriate).
myTripleStore 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.
list of tuples select(self, selection, distinct, limit)
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=myTripleStore)
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.
Parameters:
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=myTripleStore)

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=myTripleStore)

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=myTripleStore)

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)

Run a selection on the query.
Parameters:
selection - Either a single query string, or an array or tuple thereof.
distinct - if True, identical results are filtered out
           (type=Boolean)
limit - if set to an integer value, the first 'limit' number of results are returned; all of them otherwise
           (type=non negative integer)
Returns:
selection results
           (type=list of tuples)
Raises:
SPARQLError - invalid selection argument

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