toXML
index
/home/syosi/cvs-trunk/WWW/2000/10/swap/toXML.py

$Id: toXML.html,v 1.22 2004/11/10 00:50:21 syosi Exp $
 
 
This module implements basic sources and sinks for RDF data.
It defines a stream interface for such data.
It has a command line interface, can work as a web query engine,
and has built in test(), all of which demosntrate how it is used.
 
To make a new RDF processor, subclass RDFSink.
 
See also:
 
Notation 3
http://www.w3.org/DesignIssues/Notation3
 
Closed World Machine - and RDF Processor
http;//www.w3.org/2000/10/swap/cwm
 
To DO: See also "@@" in comments
 
Internationlization:
- Decode incoming N3 file as unicode
- Encode outgoing file
- unicode \u  (??) escapes in parse
- unicode \u  (??) escapes in string output
 
Note currently unicode strings work in this code
but fail when they are output into the python debugger
interactive window.
 
______________________________________________
 
Module originally by Dan Connolly.
TimBL added RDF stream model.

 
Modules
       
RDFSink
codecs
re
string
sys
urllib
urlparse

 
Classes
       
RDFSink.RDFStructuredOutput(RDFSink.RDFSink)
ToRDF
XMLWriter

 
class ToRDF(RDFSink.RDFStructuredOutput)
    keeps track of most recent subject, reuses it
 
 
Method resolution order:
ToRDF
RDFSink.RDFStructuredOutput
RDFSink.RDFSink

Methods defined here:
__init__(self, outFp, thisURI=None, base=None, flags='')
#@ Not actually complete, and can encode anyway
dummyClone(self)
retun a version of myself which will only count occurrences
endAnonymous(self, subject, verb)
endAnonymousNode(self, subj=None)
endBagObject(self, pred, subj)
endBagSubject(self, subj)
endDoc(self, rootFormulaPair=None)
flushStart(self)
makeComment(self, str)
makeStatement(self, tuple, why=None, aIsPossible=0)
referenceTo(self, uri)
Conditional relative URI
startAnonymous(self, tuple, isList=0)
startAnonymousNode(self, subj, li=0)
startBagObject(self, tuple)
startBagSubject(self, context)
startDoc(self)

Data and other attributes defined here:
flagDocumentation = '\nFlags to control RDF/XML output (after --rdf=) ...e URIs.\nz - Allow relative URIs for namespaces\n\n'

Methods inherited from RDFSink.RDFStructuredOutput:
endBagNamed(self, subj)
startBagNamed(self, context, subj)

Methods inherited from RDFSink.RDFSink:
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
genId(self)
namespaceCounts(self)
newBlankNode(self, context, uri=None, why=None)
newExistential(self, context, uri=None, why=None)
newFormula(self, uri=None)
newLiteral(self, str, dt=None, lang=None)
newSymbol(self, uri)
newUniversal(self, context, uri=None, why=None)
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)

 
class XMLWriter
    taken from
Id: tsv2xml.py,v 1.1 2000/10/02 19:41:02 connolly Exp connolly
 
Takes as argument a writer which does the (eg utf-8) encoding
 
  Methods defined here:
__init__(self, encodingWriter, counter, squeaky=0, version='1.0')
closeTag(self)
data(self, str)
emptyElement(self, n, attrs=[], prefixes={})
endDocument(self)
endElement(self)
figurePrefix(self, uriref, rawAttrs, prefixes)
flushClose(self)
indent(self, extra=0)
makeComment(self, str)
makePI(self, str)
newline(self, howmany=1)
startElement(self, n, attrs=[], prefixes={})

Data and other attributes defined here:
attrEsc = <_sre.SRE_Pattern object>
dataEsc = <_sre.SRE_Pattern object>

 
Functions
       
bNodePredicate()
dummyWrite(x)
xmldata(write, str, markupChars)

 
Data
        ADDED_HASH = '#'
ALL4 = (0, 1, 2, 3)
ANONYMOUS = 3
CONTEXT = 0
DAML_LISTS = 1
DAML_NS = 'http://www.daml.org/2001/03/daml+oil#'
DAML_sameAs = (0, 'http://www.daml.org/2001/03/daml+oil#sameAs')
DAML_sameAs_URI = 'http://www.daml.org/2001/03/daml+oil#sameAs'
DPO_NS = 'http://www.daml.org/2001/03/daml+oil#'
FORMULA = 1
LITERAL = 2
List_NS = 'http://www.daml.org/2001/03/daml+oil#'
Logic_NS = 'http://www.w3.org/2000/10/swap/log#'
N3_Empty = (0, 'http://www.daml.org/2001/03/daml+oil#Empty')
N3_List = (0, 'http://www.daml.org/2001/03/daml+oil#List')
N3_first = (0, 'http://www.daml.org/2001/03/daml+oil#first')
N3_forAll_URI = 'http://www.w3.org/2000/10/swap/log#forAll'
N3_forSome_URI = 'http://www.w3.org/2000/10/swap/log#forSome'
N3_nil = (0, 'http://www.daml.org/2001/03/daml+oil#nil')
N3_rest = (0, 'http://www.daml.org/2001/03/daml+oil#rest')
NCNameChar = 0
NCNameStartChar = 1
NODE_MERGE_URI = 'http://www.w3.org/2000/10/swap/log#is'
OBJ = 3
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 = (0, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
RDF_type_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
SUBJ = 2
SYMBOL = 0
XML_NS_URI = 'http://www.w3.org/XML/1998/namespace'
option_noregen = 0
parsesTo_URI = 'http://www.w3.org/2000/10/swap/log#parsesTo'