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

Type Graph

object --+
         |
        Graph

Known Subclasses:
Context, InformationStore, TripleStore

An RDF Graph. The constructor accepts one argument, the 'backend' that will be used to store the graph data (see the 'backends' package for backends currently shipped with rdflib).

Backends can be context-aware or unaware. Unaware backends take up (some) less space in the backend but cannot support features that require context, such as true merging/demerging of sub-graphs and provenance.
Method Summary
  __init__(self, backend)
  __contains__(self, triple)
Support for 'triple in graph' syntax.
  __eq__(self, other)
Test if Graph is exactly equal to Graph other.
  __iadd__(self, other)
Add all triples in Graph other to Graph.
  __isub__(self, other)
Subtract all triples in Graph other from Graph.
  __iter__(self)
Iterates over all triples in the store.
  __len__(self, context)
Returns the number of triples in the graph.
  absolutize(self, uri, defrag)
Will turn uri into an absolute URI if it's not one already.
  add(self, (s, p, o), context)
Add a triple, optionally provide a context.
  bind(self, prefix, namespace, override)
Bind prefix to namespace.
  close(self)
Close the graph backend.
  comment(self, subject, default)
Queries for the RDFS.comment of the subject, returns default if no comment exists.
  contexts(self, triple)
Generator over all contexts in the graph.
  get_context(self, identifier)
Returns a Context graph for the given identifier, which must be a URIRef or BNode.
  items(self, list)
Generator over all items in the resource specified by list (an RDF collection)
  label(self, subject, default)
Queries for the RDFS.label of the subject, returns default if no label exists.
  load(self, location, publicID, format)
for b/w compat.
  namespaces(self)
Generator over all the prefix, namespace tuples.
  objects(self, subject, predicate)
A generator of objects with the given subject and predicate.
  open(self, path)
Open the graph backend.
  parse(self, source, publicID, format)
Parse source into Graph.
  predicate_objects(self, subject)
A generator of (predicate, object) tuples for the given subject
  predicates(self, subject, object)
A generator of predicates with the given subject and object.
  remove(self, (s, p, o), context)
Remove a triple from the graph.
  remove_context(self, identifier)
Removes the given context from the graph.
  save(self, location, format, base)
Save Graph to location using format.
  seq(self, subject)
Check if subject is an rdf:Seq.
  serialize(self, destination, format, base)
Serialize the Graph to destination.
  subject_objects(self, predicate)
A generator of (subject, object) tuples for the given predicate
  subject_predicates(self, object)
A generator of (subject, predicate) tuples for the given object
  subjects(self, predicate, object)
A generator of subjects with the given predicate and object.
  transitive_objects(self, subject, property, remember)
  transitive_subjects(self, predicate, object, remember)
  triples(self, (s, p, o), context)
Generator over the triple store.
  value(self, subject, predicate, object, default, any)
Get a value for a subject/predicate, predicate/object, or subject/object pair -- exactly one of subject, predicate, object must be None.
  __get_backend(self)
  _get_context_aware(self)
  _get_namespace_manager(self)
  _set_namespace_manager(self, nm)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Property Summary
  backend
  context_aware
  namespace_manager

Method Details

__contains__(self, triple)
(In operator)

Support for 'triple in graph' syntax.

__eq__(self, other)
(Equality operator)

Test if Graph is exactly equal to Graph other.

__iadd__(self, other)

Add all triples in Graph other to Graph.

__isub__(self, other)

Subtract all triples in Graph other from Graph.

__iter__(self)

Iterates over all triples in the store.

__len__(self, context=None)
(Length operator)

Returns the number of triples in the graph. If context is specified then the number of triples in the context is returned instead.

absolutize(self, uri, defrag=1)

Will turn uri into an absolute URI if it's not one already.

add(self, (s, p, o), context=None)

Add a triple, optionally provide a context. A 3-tuple or rdflib.Triple can be provided. Context must be a URIRef. If no context is provides, triple is added to the default context.

bind(self, prefix, namespace, override=True)

Bind prefix to namespace. If override is True will bind namespace to given prefix if namespace was already bound to a different prefix.

close(self)

Close the graph backend. Might be necessary for backends that require closing a connection to a database or releasing some resource.

comment(self, subject, default='')

Queries for the RDFS.comment of the subject, returns default if no comment exists.

contexts(self, triple=None)

Generator over all contexts in the graph. If triple is specified, a generator over all contexts the triple is in.

get_context(self, identifier)

Returns a Context graph for the given identifier, which must be a URIRef or BNode.

items(self, list)

Generator over all items in the resource specified by list (an RDF collection)

label(self, subject, default='')

Queries for the RDFS.label of the subject, returns default if no label exists.

load(self, location, publicID=None, format='xml')

for b/w compat.

namespaces(self)

Generator over all the prefix, namespace tuples.

objects(self, subject=None, predicate=None)

A generator of objects with the given subject and predicate.

open(self, path)

Open the graph backend. Might be necessary for backends that require opening a connection to a database or acquiring some resource.

parse(self, source, publicID=None, format='xml')

Parse source into Graph. If Graph is context-aware it'll get loaded into it's own context (sub graph). Format defaults to xml (AKA rdf/xml). The publicID argument is for specifying the logical URI for the case that it's different from the physical source URI.

predicate_objects(self, subject=None)

A generator of (predicate, object) tuples for the given subject

predicates(self, subject=None, object=None)

A generator of predicates with the given subject and object.

remove(self, (s, p, o), context=None)

Remove a triple from the graph. If the triple does not provide a context attribute, removes the triple from all contexts.

remove_context(self, identifier)

Removes the given context from the graph.

save(self, location, format='xml', base=None)

Save Graph to location using format. Format defaults to xml (AKA rdf/xml).

seq(self, subject)

Check if subject is an rdf:Seq. If yes, it returns a Seq class instance, None otherwise.

serialize(self, destination=None, format='xml', base=None)

Serialize the Graph to destination. If destination is None serialize method returns the serialization as a string. Format defaults to xml (AKA rdf/xml).

subject_objects(self, predicate=None)

A generator of (subject, object) tuples for the given predicate

subject_predicates(self, object=None)

A generator of (subject, predicate) tuples for the given object

subjects(self, predicate=None, object=None)

A generator of subjects with the given predicate and object.

triples(self, (s, p, o), context=None)

Generator over the triple store. Returns triples that match the given triple pattern. If triple pattern does not provide a context, all contexts will be searched.

value(self, subject, predicate, object=None, default=None, any=False)

Get a value for a subject/predicate, predicate/object, or
subject/object pair -- exactly one of subject, predicate,
object must be None. Useful if one knows that there may only
be one value.

It is one of those situations that occur a lot, hence this
'macro' like utility

Parameters:
-----------
subject, predicate, object  -- exactly one must be None
default -- value to be returned if no values found
any -- if True:
         return any value in the case there is more than one
       else:
         raise UniquenessError

Property Details

backend

Get Method:
__get_backend(self)

context_aware

Get Method:
_get_context_aware(self)

namespace_manager

Get Method:
_get_namespace_manager(self)
Set Method:
_set_namespace_manager(self, nm)

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