Redland RDF Application Framework - Python API Reference

 
 
RDF (version 0.7, $Date: 2003/01/29 17:36:23 $)
index

Redland Python API
 
  import RDF
 
  storage=RDF.Storage(...)
  model=RDF.Model(storage)
 
  ... do stuff
 
The Python interface to the Redland RDF library.  See
  http://www.redland.opensource.ac.uk/
for full details.
 
The main class that is used is Model which represents the RDF graph
formed from triples or Statement s.  These statements consist of
three Node objects for resource or literals and can be stored in
Storage (persistent or in-memory) as well as serialized to/from
syntaxes via the Serializer or Parser classes.

 
Modules
             
Redland
string
sys
 
Classes
             
exceptions.Exception
RedlandError
NodeTypeError
Iterator
Model
Node
Parser
Serializer
Statement
Storage
Stream
Uri
World
 
class Iterator
      Redland Node Iterator class
 
A class for iterating over a sequence of Node s such as
those returned from a Model query.  Some methods return
Iterator s or Python sequences.  If this is used, it works
as follows:
 
  iterator=model.get_targets_iterator(source, arc)
  while not iterator.end():
    # get the current Node
    node=iterator.current()
    # do something with it
    # (it is shared; you must copy it you want to keep it)
    ...
    iterator.next()
  iterator=None
 
   Methods defined here:
__del__(self)
__init__(self, object, creator1=None, creator2=None, creator3=None)
Create an RDF Iterator (constructor).
context(self)
Return a SHARED copy of the context Node of the current object on the Iterator
current(self)
Return a SHARED copy of the current object on the Iterator
end(self)
Return true if the iterator is exhausted
have_elements(self)
next(self)
Move to the next object on the Iterator

Data and non-method functions defined here:
__doc__ = 'Redland Node Iterator class\n\n A class for it... iterator.next()\n iterator=None\n\n '
__module__ = 'RDF'
 
class Model
      Redland Graph class
 
  import RDF
  m1=RDF.Model(storage=s)
 
The main interface to the Redland RDF graph (formed from triples, or
RDF statements).  There are many methods for adding, removing, querying
statements and serializing them to/from syntaxes using the Serializer
or Parser classes.
 
   Methods defined here:
__del__(self)
__init__(self, storage, **args)
Create an RDF Model (constructor).
 
Create a new RDF Model using any of these forms
 
  m1=RDF.Model(storage=s1)
Create a Model from an existing Storage (most common use).  
Optional fields:
  options_string - A string of options for the Model
  options_hash   - A Hash of options for the Model
 
  m2=RDF.Model(model=m1)
Copy an existing model m1, copying the underlying Storage of m1
add(self, subject, predicate, object)
Add the statement (subject,predicate,object) to the model
add_statement(self, statement, context=None)
Add the Statement to the Model with optional context Node
add_statements(self, statement_stream, context=None)
Add the Stream of Statements to the Model with the optional context Node
add_typed_literal_statement(self, subject, predicate, string, xml_language=None, datatype=None)
Add the Statement (subject,predicate, typed literal) to the Model
where the typed literal is constructed from the
literal string, optional XML language and optional datatype URI.
arcs(self, source, target)
Return a sequence of Node s that are the arcs
of Statements in the Model matching (source, ?, target).
contains_statement(self, statement)
Return true if the Statement is in the Model
context_remove_statements(self, context)
Remove all Statement s from the Model with the given context Node
find_statements(self, statement)
Return a Stream of Statements matching the given
partial Statement - the missing nodes of the
partial statement match any node in the Model.
get_arc(self, source, target)
Return one Node in the Model matching (source, ?, target).
get_arcs_iterator(self, source, target)
Return an Iterator of Node s that are the arcs
of Statements in the Model matching (source, ?, target).
The arcs method is recommended in preference to this.
get_source(self, arc, target)
Return one Node in the Model matching (?, arc, target).
get_sources_iterator(self, arc, target)
Return an Iterator of Node s that are the sources
of Statements in the Model matching (?, arc, target).
The sources method is recommended in preference to this.
get_target(self, source, arc)
Return one Node in the Model matching (source, arc, ?).
get_targets_iterator(self, source, arc)
Return an Iterator of Node s that are the targets
of Statements in the Model matching (source, arc, ?).
The targets method is recommended in preference to this.
remove_statement(self, statement, context=None)
Remove the Statement from the Model with the optional context Node
serialise(self)
Return the Model as a Stream of Statements
size(self)
Return the size of the Model in number of statements (<0 if not countabl)
sources(self, arc, target)
Return a sequence of Node s that are the source
of Statements in the Model matching (?, arc, target).
targets(self, source, arc)
Return a sequence of Node s that are the targets
of Statements in the Model matching (source, arc, ?).

Data and non-method functions defined here:
__doc__ = 'Redland Graph class\n\n import RDF\n m1=RDF.M...es using the Serializer\n or Parser classes.\n\n\n '
__module__ = 'RDF'
 
class Node
      Redland Node (RDF Resource, Property, Literal) Class
 
  import RDF
  node1=RDF.Node()
  node2=RDF.Node(uri_string="http://example.com/")
  node3=RDF.Node(uri=RDF.Uri("http://example.com/"))
  node4=RDF.Node(literal="Hello, World!")
  node5=RDF.Node(literal="<tag>content</tag>", is_wf_xml=1)
  node5=RDF.Node(blank="abc")
  node7=RDF.Node(node=node5)
...
 
  print node2
  if node7->is_resource:
    print "Resource with URI", node7->uri
 
   Methods defined here:
__del__(self)
Free an RDF Node (destructor).
__eq__(self, other)
Equality of an RDF Node compared to another RDF Node.
__getattr__(self, name)
__hash__(self)
__init__(self, **args)
Create an RDF Node (constructor).
 
Creates a new RDF Node using the following fields:
  uri_string  - create a resource node from a string URI
  uri         - create a resource node from a URI object
  literal     - create a literal node from a literal string   
    datatype     - the datatype URI
    is_wf_xml    - the literal is XML (alternative to datatype)
    xml_language - the literal XML language
  blank       - create a resource node from with a blank node identiifer
  node        - copy a node
__ne__(self, other)
Inequality of an RDF Node compared to another RDF Node.
__setattr__(self, name, value)
__str__(self)
Get a string representation of an RDF Node.
_get_type(self)
_get_uri(self)
_set_type(self, type)
_set_uri(self, uri)
get_literal_value(self)
Get a dictionary containing the value of the Node literal
is_blank(self)
Return true if node is a blank node
is_literal(self)
Return true if node is a literal
is_resource(self)
Return true if node is a resource  with a URI
set_literal_value(self, string, xml_language=None, datatype=None)
Set a literal Node string value, with optional XML language or datatype URI.

Data and non-method functions defined here:
__doc__ = 'Redland Node (RDF Resource, Property, Literal) C...:\n print "Resource with URI", node7->uri\n\n '
__module__ = 'RDF'
 
class NodeTypeError(RedlandError)
       
  
Method resolution order:
NodeTypeError
RedlandError
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'RDF'

Methods inherited from RedlandError:
__init__(self, value)
__str__(self)

Methods inherited from exceptions.Exception:
__getitem__(...)
 
class Parser
      Redland Syntax Parser Class
 
import RDF
parser1=RDF.Parser()
parser2=RDF.Parser(name="rdfxml")
parser3=RDF.Parser(mime_type="application/rdf+xml")
 
stream=parser2.parse_as_stream("file://dir/file.rdf")
parser3.parse_into_model(model, "file://dir/file.rdf", "http://example.org/")
 
   Methods defined here:
__del__(self)
__init__(self, name=None, mime_type='application/rdf+xml', uri=None)
Create an RDF Parser (constructor).
 
Create a new RDF Parser for a particular syntax.  The parser is
chosen by the fields given to the constructor, all of which are
optional.  When any are given, they must all match.
 
  name      - parser name (currently "raptor", "repat" and "ntriples")
  mime_type - currently "application/rdf+xml" (default) or "text/plain" (ntriples)
  uri       - URI identifying the syntax
              currently only "http://www.w3.org/TR/rdf-testcases/#ntriples"
get_feature(self, uri)
Return the value of Parser feature URI uri
parse_as_stream(self, uri, base_uri=None)
"Return a Stream of Statements from parsing the content at
(file: only at present) URI, for the optional base URI
parse_into_model(self, model, uri, base_uri=None)
"Parse into the Model model from the content at
(file: only at present) URI, for the optional base URI
set_feature(self, uri, value)
Set the value of Parser feature URI uri.

Data and non-method functions defined here:
__doc__ = 'Redland Syntax Parser Class\n\n import RDF\n pars... "file://dir/file.rdf", "http://example.org/")\n '
__module__ = 'RDF'
 
class RedlandError(exceptions.Exception)
      Redland Runtime errors
 
   Methods defined here:
__init__(self, value)
__str__(self)

Data and non-method functions defined here:
__doc__ = 'Redland Runtime errors'
__module__ = 'RDF'

Methods inherited from exceptions.Exception:
__getitem__(...)
 
class Serializer
       Redland Syntax Serializer Class
 
import RDF
ser1=RDF.Serializer(mime_type="application/rdf+xml")
 
A class for turning a Model into a syntax serialization (at present
only to local files).
 
   Methods defined here:
__del__(self)
__init__(self, name='', mime_type='application/rdf+xml', uri=None)
Create an RDF Serializer (constructor).
get_feature(self, uri)
Return the value of Serializer feature URI uri
serialize_model_to_file(self, name, model, base_uri=None)
Serialize to filename name the Model model using the
optional base URI.
set_feature(self, uri, value)
Set the value of Serializer feature URI uri.

Data and non-method functions defined here:
__doc__ = ' Redland Syntax Serializer Class\n\n import RDF\n ...ialization (at present\n only to local files).\n '
__module__ = 'RDF'
 
class Statement
      Redland Statement (triple) class
 
import RDF
statement1=RDF.Statement(subject=node1, predicate=node2, object=node3)
statement2=RDF.Statement(statement=statement1)
 
if statement2.subject.is_resource:
  print "statement2 subject is URI ",statement2.subject.uri
 
   Methods defined here:
__del__(self)
__getattr__(self, name)
__init__(self, **args)
Create an RDF Statement (constructor).
 
Creates a new RDF Statement from either of the two forms:
 
    s1=RDF.Statement(subject=node1, predicate=node2, object=node3)
Create a Statement from three Node objects.
 
    s2=RDF.Statement(statement=s1)
Copy an existing Statement s1.
__setattr__(self, name, value)
__str__(self)
_get_object(self)
_get_predicate(self)
_get_subject(self)
_set_object(self, value)
_set_predicate(self, value)
_set_subject(self, value)
_wrap_node(self, rednode)

Data and non-method functions defined here:
__doc__ = 'Redland Statement (triple) class\n\n import RDF...2 subject is URI ",statement2.subject.uri\n \n '
__module__ = 'RDF'
 
class Storage
      Redland Statement Storage class
 
   import RDF
   storage=RDF.Storage(storage_name="memory")
 
The Redland abstraction for storing RDF graphs as Statement s.
 
There are no user methods (can only be constructed).
 
   Methods defined here:
__del__(self)
__init__(self, **args)
Create an RDF Storage (constructor).
 
    Create a new RDF Storage using any of these forms
 
  s1=RDF.Storage(storage_name="name")
Create a Storage with the given name.  Currently the built in
storages are "memory" and "hashes".  "hashes" takes extra
arguments passed in the field options_string, some of which are
required:
  options_string="hash-type='memory',new='yes',write='yes'"
    hash-type - required and can be the name of any Hash type supported.
      'memory' is always present, and 'bdb' is available
      when BerkeleyDB is compiled in.
    new - optional and takes a boolean value (default false)
      If true, it allows updating of an existing Storage 
    write - optional and takes a boolean value (default true)
      If false, the Storage is opened read-only and for file-based
      Storages or those with locks, may be shared-read.
 
The other form is:
  s2=RDF.Storage(storage=s1)
Copy an existing Storage s1.

Data and non-method functions defined here:
__doc__ = 'Redland Statement Storage class\n\n import RDF...re no user methods (can only be constructed).\n\n '
__module__ = 'RDF'
 
class Stream
      Redland Statement Stream class
 
A class for iterating over a sequence of Statement s such as
those returned from a Model query.  Some methods return
Statement s or Python sequences.  If this is used, it works
as follows:
 
  stream=model.serialize()
  while not stream.end():
    # get the current Statement
    statement=stream.current()
    # do something with it
    # (it is shared; you must copy it you want to keep it)
    ...
    stream.next()
  stream=None
 
   Methods defined here:
__del__(self)
__init__(self, object, creator, free_statements)
Create an RDF Stream (constructor).
context(self)
Return a SHARED copy of the context Node of the current object on the Stream
current(self)
Return a SHARED copy of the current Statement on the Stream
end(self)
Return true if the stream is exhausted
next(self)
Move to the next Statement on the Stream

Data and non-method functions defined here:
__doc__ = 'Redland Statement Stream class\n\n A class for...\n stream.next()\n stream=None\n\n '
__module__ = 'RDF'
 
class Uri
      Redland URI Class
 
import RDF
uri1=RDF.Uri(string="http://example.com/")
uri2=RDF.Uri(uri=uri1)
 
   Methods defined here:
__del__(self)
__eq__(self, other)
Equality of RDF URI to another RDF URI.
__hash__(self)
__init__(self, **args)
Create an RDF URI (constructor).
 
Creates a new RDF Node from either of the following forms:
 
  uri1=RDF.Uri(string="http://example.com/")
Create a URI from the given string.
 
  uri2=RDF.Uri(uri=uri1)
Copy an existing URI uri1.
__ne__(self, other)
Inequality of RDF URI to another RDF URI.
__str__(self)
Get a string representation of an RDF URI.

Data and non-method functions defined here:
__doc__ = 'Redland URI Class\n\n import RDF\n uri1=RDF.Uri(s...ttp://example.com/")\n uri2=RDF.Uri(uri=uri1)\n\n '
__module__ = 'RDF'
 
class World
      Redland Initialisation class.
 
There are no user methods (can only be constructed).
 
   Methods defined here:
__del__(self)
Destroy RDF World object (destructor).
__init__(self, digest_name='', uri_hash=None)
Create new RDF World object (constructor)
message(type, message)
Internal message dispatcher from Redland to python

Data and non-method functions defined here:
__doc__ = 'Redland Initialisation class.\n\n There are no user methods (can only be constructed).\n\n '
__module__ = 'RDF'
 
Functions
             
debug(value=-1)
node_type(name)
Return the Redland node type of a node name
node_type_name(num)
Return the name of a Redland node type
 
Data
              __all__ = ['World', 'Node', 'Statement', 'Model', 'Iterator', 'Serializer', 'Stream', 'Storage', 'Uri', 'Parser']
__author__ = 'Dave Beckett - http://purl.org/net/dajobe'
__credits__ = 'Edd Dumbill for properly Pythonisising my Perl translation'
__date__ = '$Date: 2003/01/29 17:36:23 $'
__file__ = './RDF.py'
__name__ = 'RDF'
__version__ = '0.7'
_debug = 0
_node_types = {'NODE_TYPE_BLANK': 4, 'NODE_TYPE_LI': 3, 'NODE_TYPE_LITERAL': 2, 'NODE_TYPE_RESOURCE': 1, 'NODE_TYPE_UNKNOWN': 0}
_world = <RDF.World instance>
 
Author
              Dave Beckett - http://purl.org/net/dajobe
 
Credits
              Edd Dumbill for properly Pythonisising my Perl translation

Copyright 2000-2003 Dave Beckett, Institute for Learning and Research Technology, University of Bristol