RDFSink (version $Id: RDFSink.py,v 1.36 2007/06/26 02:36:15 syosi Exp $)
index
/Users/yosi/CVSROOT/WWW/2000/10/swap/RDFSink.py

RDFSink -- RDF parser/serializer/store interface
 
This is a simple API for a push-stream of RDF data. It doesn't use
a particular classof obejcts, but just uses python pairs.
It is kinda crude but it does allow for example data to be squirted efficiently 
between modules which use different python classes for RDF.
 
HISTORY
 
This module was factored out of notation3.py
 
REFERENCES
  Python Style Guide
  Author: Guido van Rossum
  http://www.python.org/doc/essays/styleguide.html

 
Modules
       
uripath

 
Classes
       
RDFSink
RDFStructuredOutput
TracingRDFSink
exceptions.ValueError(exceptions.StandardError)
URISyntaxError

 
class RDFSink
    interface to connect modules in RDF processing.
OBSOLETE
 
This is a superclass for other RDF processors which accept RDF events
or indeed Swell events. It is superceded, effectively, by the class Formula,
as a sink of data and a soiurce of new symbols.
 
Keeps track of prefixes.
 
This interface has the advantage that it does n ot have any dependencies
on object types, it is really one-way (easily serialized as no return values).
It has the disadvantages that
    - It uses the pseudoproperties log:forSome and log:forAll to
      make variables, which is a bit of a kludge.
    - It may involve on the receiver side the same thing being interned
      many times, which wastes time searching hash tables.
The superclass handles common functions such as craeting new arbitray
identifiers
 
  Methods defined here:
__init__(self, genPrefix=None)
If you give it a URI prefix to use for generated IDs it
will use one; otherwise, it will use the name of an imaginary temporary file
in the current directory.
bind(self, prefix, uri)
Pass on a binding hint for later use in output
 
This really is just a hint. The parser calls bind to pass on
the prefix which it came across, as this is a useful hint for
a human readable prefix for output of the same
namespace. Otherwise, output processors will have to invent or
avoid useing namespaces, which will look ugly
checkNewId(self, uri)
The store can override this to raise an exception if the
id is not in fact new. This is useful because it is usfeul
to generate IDs with useful diagnostic ways but this lays them
open to possibly clashing in pathalogical cases.
countNamespace(self, namesp)
On output, count how many times each namespace is used
endDoc(self, rootFormulaPair)
End a document
 
Call this once only at the end of parsing so that the receiver can wrap
things up, oprimize, intern, index and so on.  The pair given is the (type, value)
identifier of the root formula of the thing parsed.
genId(self)
intern(self, something)
makeComment(self, str)
This passes on a comment line which of course has no semantics.
 
This is only useful in direct piping of parsers to output, to preserve
comments in the original file.
makeStatement(self, tuple, why=None)
add a statement to a stream/store.
 
raises URISyntaxError on bad URIs
tuple is a quad (context, predicate, subject, object) of things generated by calls to newLiteral etc
why is reason for the statement.
namespaceCounts(self)
newBlankNode(self, context, uri=None, why=None)
newExistential(self, context, uri=None, why=None)
newFormula(self, uri=None)
newList(self, l, context)
newLiteral(self, str, dt=None, lang=None)
newSymbol(self, uri)
newUniversal(self, context, uri=None, why=None)
newXMLLiteral(self, doc)
reopen(self)
Un-End a document
 
If you have added stuff to a document, thought you were done, and
then want to add more, call this to get back into the sate that makeSatement
is again acceptable. Remember to end the document again when done.
setDefaultNamespace(self, uri)
Pass on a binding hint for later use in output
 
This really is just a hint. The parser calls this to pass on
the default namespace which it came across, as this is a
useful hint for a human readable prefix for output of the same
namespace. Otherwise, output processors will have to invent or
avoid useing namespaces, which will look ugly.
setGenPrefix(self, genPrefix)
startDoc(self)

 
class RDFStructuredOutput(RDFSink)
     Methods defined here:
endAnonymous(self, subject, verb)
endAnonymousNode(self, endAnonymousNode)
endFormulaObject(self, pred, subj)
endFormulaSubject(self, subj)
startAnonymous(self, triple, isList=0)
startAnonymousNode(self, subj)
startFormulaObject(self, triple)
startFormulaSubject(self, context)

Methods inherited from RDFSink:
__init__(self, genPrefix=None)
If you give it a URI prefix to use for generated IDs it
will use one; otherwise, it will use the name of an imaginary temporary file
in the current directory.
bind(self, prefix, uri)
Pass on a binding hint for later use in output
 
This really is just a hint. The parser calls bind to pass on
the prefix which it came across, as this is a useful hint for
a human readable prefix for output of the same
namespace. Otherwise, output processors will have to invent or
avoid useing namespaces, which will look ugly
checkNewId(self, uri)
The store can override this to raise an exception if the
id is not in fact new. This is useful because it is usfeul
to generate IDs with useful diagnostic ways but this lays them
open to possibly clashing in pathalogical cases.
countNamespace(self, namesp)
On output, count how many times each namespace is used
endDoc(self, rootFormulaPair)
End a document
 
Call this once only at the end of parsing so that the receiver can wrap
things up, oprimize, intern, index and so on.  The pair given is the (type, value)
identifier of the root formula of the thing parsed.
genId(self)
intern(self, something)
makeComment(self, str)
This passes on a comment line which of course has no semantics.
 
This is only useful in direct piping of parsers to output, to preserve
comments in the original file.
makeStatement(self, tuple, why=None)
add a statement to a stream/store.
 
raises URISyntaxError on bad URIs
tuple is a quad (context, predicate, subject, object) of things generated by calls to newLiteral etc
why is reason for the statement.
namespaceCounts(self)
newBlankNode(self, context, uri=None, why=None)
newExistential(self, context, uri=None, why=None)
newFormula(self, uri=None)
newList(self, l, context)
newLiteral(self, str, dt=None, lang=None)
newSymbol(self, uri)
newUniversal(self, context, uri=None, why=None)
newXMLLiteral(self, doc)
reopen(self)
Un-End a document
 
If you have added stuff to a document, thought you were done, and
then want to add more, call this to get back into the sate that makeSatement
is again acceptable. Remember to end the document again when done.
setDefaultNamespace(self, uri)
Pass on a binding hint for later use in output
 
This really is just a hint. The parser calls this to pass on
the default namespace which it came across, as this is a
useful hint for a human readable prefix for output of the same
namespace. Otherwise, output processors will have to invent or
avoid useing namespaces, which will look ugly.
setGenPrefix(self, genPrefix)
startDoc(self)

 
class TracingRDFSink
    An implementation of the RDFSink interface which helps me
understand it, especially how it gets used by parsers vs. by an
RDF store.    [ -sandro ]
 
Set .backing to be some other RDFSink if you want to get proper
results while tracing.
 
Try:
 
bash-2.04$ python cwm.py test/rules12.n3 --language=trace
bash-2.04$ python cwm.py --pipe test/rules12.n3 --language=trace
bash-2.04$ python cwm.py test/rules12.n3 --bySubject --language=trace
 
... and see the different outputs
 
  Methods defined here:
__init__(self, outURI, base=None, flags=None)
bind(self, prefix, uri)
endDoc(self, rootFormulaPair='<<strangely omitted>>')
endFormulaObject(self, pred, subj)
endFormulaSubject(self, subj)
makeComment(self, comment)
makeStatement(self, tuple, why=None)
newFormula(self, uri=None)
newLiteral(self, str, dt=None, lang=None)
newSymbol(self, uri)
setDefaultNamespace(self, ns)
startDoc(self)
startFormulaObject(self, triple)
startFormulaSubject(self, context)

 
class URISyntaxError(exceptions.ValueError)
    A parameter is passed to a routine that requires a URI reference
 
 
Method resolution order:
URISyntaxError
exceptions.ValueError
exceptions.StandardError
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
Functions
       
getpid(...)
getpid() -> pid
 
Return the current process id
runNamespace()
Return a URI suitable as a namespace for run-local objects
time(...)
time() -> floating point number
 
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.
uniqueURI()
A unique URI

 
Data
        ALL4 = (0, 1, 2, 3)
ANONYMOUS = 3
CONTEXT = 0
DAML_sameAs_URI = 'http://www.w3.org/2002/07/owl#sameAs'
FORMULA = 1
LITERAL = 2
LITERAL_DT = 21
LITERAL_LANG = 22
List_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
Logic_NS = 'http://www.w3.org/2000/10/swap/log#'
N3_Empty = (0, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Empty')
N3_List = (0, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#List')
N3_first = (0, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first')
N3_li = (0, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#li')
N3_nil = (0, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil')
N3_rest = (0, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest')
NODE_MERGE_URI = 'http://www.w3.org/2000/10/swap/log#is'
OBJ = 3
OWL_NS = 'http://www.w3.org/2002/07/owl#'
PARTS = (1, 2, 3)
PRED = 1
RDF_NS_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
RDF_spec = 'http://www.w3.org/TR/REC-rdf-syntax/'
RDF_type_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
SUBJ = 2
SYMBOL = 0
XMLLITERAL = 25
__version__ = '$Id: RDFSink.py,v 1.36 2007/06/26 02:36:15 syosi Exp $'
environ = {'XDG_DATA_HOME': '/Users/yosi/.local/share', 'T...P', 'SGML_CATALOG_FILES': '/sw/etc/sgml/catalog'}
forAllSym = 'http://www.w3.org/2000/10/swap/log#forAll'
forSomeSym = 'http://www.w3.org/2000/10/swap/log#forSome'
nextu = 0
parsesTo_URI = 'http://www.w3.org/2000/10/swap/log#parsesTo'
runNamespaceValue = None