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

Class SPARQLGraph

SPARQL --+
         |
        SPARQLGraph


A wrapper class around the original triple store, that includes some additional utility methods
Method Summary
  __init__(self, graph)
  __add__(self, other)
Set theoretical union
  __getattr__(self, attr)
  __mul__(self, other)
Set theoretical intersection
  __sub__(self, other)
Set theoretical difference
myTripleStore cluster(self, seed)
Cluster up and down, by summing up the forward and backward clustering
myTripleStore clusterBackward(self, seed, Cluster)
Cluster the triple store: from a seed, transitively get all properties and objects 'backward', ie, following the link back in the graph.
myTripleStore clusterForward(self, seed, Cluster)
Cluster the triple store: from a seed, transitively get all properties and objects in direction of the arcs.
  extendRdfs(self)
Poor man's RDFS entailement.
Alt getAlt(self, resource)
Check if resource is an rdf:Alt.
Bag getBag(self, resource)
Check if resource is an rdf:Bag.
RDFLib Resource getPredicateSubject(self, p, v)
Get a subject value for predicate and a value.
an RDFLib Resource getPredicateValue(self, s, p)
Get a predicate value for an subject.
Seq getSeq(self, resource)
Check if resource is an rdf:Seq.
Boolean isTrue(self, s, p, o)
Checking the truthfulness of a triplet, ie, its existence.
Alt storeAlt(self, elements, name)
Store a Seq container.
Bag storeBag(self, elements, name)
Store a Seq container.
  storeCollection(self, elements, name)
Store a (Python) list as an RDF List, ie, a collection.
Seq storeSeq(self, elements, name)
Store a Seq container.
list unfoldCollection(self, resource)
Return a list of, well, list (collection) elements in RDF.
    Inherited from SPARQL
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

__add__(self, other)
(Addition operator)

Set theoretical union

__mul__(self, other)

Set theoretical intersection

__sub__(self, other)
(Subtraction operator)

Set theoretical difference

cluster(self, seed)

Cluster up and down, by summing up the forward and backward clustering
Parameters:
seed - RDFLib Resource
Returns:
The triple store containing the cluster
           (type=myTripleStore)

clusterBackward(self, seed, Cluster=None)

Cluster the triple store: from a seed, transitively get all properties and objects 'backward', ie, following the link back in the graph.
Parameters:
seed - RDFLib Resource
Cluster - another myTripleStore instance; if None, a new one will be created. The subgraph will be added to this store.
Returns:
The triple store containing the cluster
           (type=myTripleStore)

clusterForward(self, seed, Cluster=None)

Cluster the triple store: from a seed, transitively get all properties and objects in direction of the arcs.
Parameters:
seed - RDFLib Resource
Cluster - another myTripleStore instance; if None, a new one will be created. The subgraph will be added to this store.
Returns:
The triple store containing the cluster
           (type=myTripleStore)

extendRdfs(self)

Poor man's RDFS entailement. The method does not do a full RDFS entailement (this would greatly increase the size of the triple store, and RDFLib may not be efficient enough for that). Instead:
  • extend the subproperties defined in the triple store (ie, if p is subProperty of q, then for all (s p o) the (s q o) triplets are created and added to the store, and this is done recursively).
  • expand range and domain, ie if the range (domain) are defined for a property, all object (subject) resources for that property are properly typed via rdf:type
  • extend the subtypes defined in the triple store, similarly to subproperties.
Though not a full entailement, I believe that it covers a large number of useful cases for the user.
Raises:
RDFSValidityError - if the triple store contains incorrect triples

getAlt(self, resource)

Check if resource is an rdf:Alt. If yes, it returns a Alt class instance, None otherwise.
Parameters:
resource - and RDFLib Resource
Returns:
Alt

getBag(self, resource)

Check if resource is an rdf:Bag. If yes, it returns a Bag class instance, None otherwise.
Parameters:
resource - and RDFLib Resource
Returns:
Bag

getPredicateSubject(self, p, v)

Get a subject value for predicate and a value. Useful if one knows that there may only be one... Returns None if no value exists.

It is one of those situations that occur a lot, hence this 'macro' like utility.
Parameters:
p - predicate
v - value
Returns:
RDFLib Resource
Raises:
UniquenessError - the triple store contains more than one subject for the (p,v) pair

getPredicateValue(self, s, p)

Get a predicate value for an subject. Useful if one knows that there may only be one... Returns None if no value exists.

It is one of those situations that occur a lot, hence this 'macro' like utility.
Parameters:
s - subject
p - predicate
Returns:
an RDFLib Resource
Raises:
UniquenessError - the triple store contains more than one value for the (s,p) pair

getSeq(self, resource)

Check if resource is an rdf:Seq. If yes, it returns a Seq class instance, None otherwise.
Parameters:
resource - and RDFLib Resource
Returns:
Seq

isTrue(self, s, p, o)

Checking the truthfulness of a triplet, ie, its existence. Returns True/False. It is just an idiom...
Parameters:
s - subject
p - predicate
o - object
Returns:
Boolean

Depreciated: I realized later that using 'in' is by far the simplest thing that would not really need a separate method, but I left it here for backward compatibility.

storeAlt(self, elements, name=None)

Store a Seq container. Elements given as an array are added to the triple store. The BNode for the container is created on the fly.
Parameters:
elements - an array of RDF resources, ie, URIRefs, BNodes, or Literals
name - the nodeId of the BNode for the rdf:Seq (if None, the system sets the nodeId as for all other BNodes)
Returns:
the new Seq instance
           (type=Alt)

storeBag(self, elements, name=None)

Store a Seq container. Elements given as an array are added to the triple store. The BNode for the container is created on the fly.
Parameters:
elements - an array of RDF resources, ie, URIRefs, BNodes, or Literals
name - the nodeId of the BNode for the rdf:Seq (if None, the system sets the nodeId as for all other BNodes)
Returns:
the new Seq instance
           (type=Bag)

storeCollection(self, elements, name=None)

Store a (Python) list as an RDF List, ie, a collection.
Parameters:
elements - list of Literal, BNode or URIRef instances
name - the nodeId of the head of the list (if None, the system sets the nodeId as for all other BNodes)

storeSeq(self, elements, name=None)

Store a Seq container. Elements given as an array are added to the triple store. The BNode for the container is created on the fly.
Parameters:
elements - an array of RDF resources, ie, URIRefs, BNodes, or Literals
name - the nodeId of the BNode for the rdf:Seq (if None, the system sets the nodeId as for all other BNodes)
Returns:
the new Seq instance
           (type=Seq)

unfoldCollection(self, resource)

Return a list of, well, list (collection) elements in RDF.

Rdflib's store has a method called item, which is generator over list elements. In some cases this is just enough. However, the advantage of using this method is that it returns a Python list that can be, for example, sliced, massaged, etc, and that is sometimes quite useful.
Parameters:
resource - and RDFLib Resource
Returns:
list
Raises:
ListError - the resource is not a proper RDF collection

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