| |
- RDFSink.RDFSink
-
- ToN3
- tmToN3
- exceptions.SyntaxError(exceptions.StandardError)
-
- BadSyntax
- SinkParser
class SinkParser |
| |
Methods defined here:
- UEscape(self, str, i, startline)
- __init__(self, store, openFormula=None, thisDoc='', baseURI=None, genPrefix='', metaURI=None, flags='', why=None)
- note: namespace names should *not* end in #;
the # will get added during qname processing
- anonymousNode(self, ln)
- Remember or generate a term for one of these _: anonymous nodes
- bareWord(self, str, i, res)
- abc -> :abc
- bind(self, qn, uri)
- blankNode(self, uri=None)
- checkDot(self, str, i)
- commaSeparatedList(self, str, j, res, what)
- return value: -1 bad syntax; >1 new position in str
res has things found appended
- directive(self, str, i)
- directiveOrStatement(self, str, h)
- endDoc(self)
- Signal end of document and stop parsing. returns formula
- feed(self, octets)
- Feed an octet stream tothe parser
if BadSyntax is raised, the string
passed in the exception object is the
remainder after any statements have been parsed.
So if there is more data to feed to the
parser, it should be straightforward to recover.
- formula(self)
- here(self, i)
- String generated from position in file
This is for repeatability when refering people to bnodes in a document.
This has diagnostic uses less formally, as it should point one to which
bnode the arbitrary identifier actually is. It gives the
line and character number of the '[' charcacter or path character
which introduced the blank node. The first blank node is boringly _L1C1.
It used to be used only for tracking, but for tests in general
it makes the canonical ordering of bnodes repeatable.
- item(self, str, i, res)
- loadBuf(self, buf)
- Parses a buffer and returns its top level formula
- loadStream(self, stream)
- makeStatement(self, quadruple)
- node(self, str, i, res, subjectAlready=None)
- Parse the <node> production.
Space is now skipped once at the beginning
instead of in multipe calls to skipSpace().
- nodeOrLiteral(self, str, i, res)
- object(self, str, i, res)
- objectList(self, str, i, res)
- path(self, str, i, res)
- Parse the path production.
- prop(self, str, i, res)
- property_list(self, str, i, subj)
- Parse property list
Leaves the terminating punctuation in the buffer
- qname(self, str, i, res)
- xyz:def -> ('xyz', 'def')
If not in keywords and keywordsSet: def -> ('', 'def')
:def -> ('', 'def')
- setKeywords(self, k)
- Takes a list of strings
- skipSpace(self, str, i)
- Skip white space, newlines and comments.
return -1 if EOF, else position of first non-ws character
- startDoc(self)
- statement(self, str, i)
- strconst(self, str, i, delim)
- parse an N3 string constant delimited by delim.
return index, val
- subject(self, str, i, res)
- tok(self, tok, str, i)
- Check for keyword. Space must have been stripped on entry and
we must not be at end of file.
- uEscape(self, str, i, startline)
- uriOf(self, sym)
- uri_ref2(self, str, i, res)
- Generate uri from n3 representation.
Note that the RDF convention of directly concatenating
NS and local name is now used though I prefer inserting a '#'
to make the namesapces look more like what XML folks expect.
- variable(self, str, i, res)
- ?abc -> variable(:abc)
- verb(self, str, i, res)
- has _prop_
is _prop_ of
a
=
_prop_
>- prop ->
<- prop -<
_operator_
|
class ToN3(RDFSink.RDFSink) |
|
Serializer output sink for N3
keeps track of most recent subject and predicate reuses them.
Adapted from Dan's ToRDFParser(Parser); |
|
Methods defined here:
- __init__(self, write, base=None, genPrefix=None, noLists=0, quiet=0, flags='')
- bind(self, prefixString, uri)
- Just accepting a convention here
- dummyClone(self)
- retun a version of myself which will only count occurrences
- endAnonymous(self, subject, verb)
- endAnonymousNode(self, subj=None)
- endDoc(self, rootFormulaPair=None)
- endFormulaObject(self, pred, subj)
- endFormulaSubject(self, subj)
- endListObject(self, subject, verb)
- endListSubject(self, subj=None)
- makeComment(self, str)
- makeStatement(self, triple, why=None, aIsPossible=1)
- representationOf(self, context, pair)
- Representation of a thing in the output stream
Regenerates genids if required.
Uses prefix dictionary to use qname syntax if possible.
- setDefaultNamespace(self, uri)
- startAnonymous(self, triple)
- startAnonymousNode(self, subj)
- startDoc(self)
- startFormulaObject(self, triple)
- startFormulaSubject(self, context)
- startListObject(self, triple)
- startListSubject(self, subj)
- writeEncoded(self, str)
- Write a possibly unicode string out to the output
Data and other attributes defined here:
- flagDocumentation = 'Flags for N3 output are as follows:-\n \na ...a existentially qualified explicitly named node.\n'
Methods inherited from RDFSink.RDFSink:
- 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)
- intern(self, something)
- 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.
- setGenPrefix(self, genPrefix)
|
class tmToN3(RDFSink.RDFSink) |
| |
Methods defined here:
- IsOf(self)
- __init__(self, write, base=None, genPrefix=None, noLists=0, quiet=0, flags='')
- addAnonymous(self, Id)
- If an anonymous shows up more than once, this is the
function to call
- addLiteral(self, lit, dt=None, lang=None)
- addNode(self, node)
- addQuestionMarkedSymbol(self, sym)
- addSymbol(self, sym)
- backwardPath(self)
- beginAnonymous(self)
- beginFormula(self)
- beginList(self)
- bind(self, prefixString, uri)
- Just accepting a convention here
- checkIsOf(self)
- declareExistential(self, sym)
- declareUniversal(self, sym)
- end(self)
- endAnonymous(self)
- endFormula(self)
- endList(self)
- endStatement(self)
- forewardPath(self)
- setDefaultNamespace(self, uri)
- start(self)
- symbolString(self, value)
- writeEncoded(self, str)
- Write a possibly unicode string out to the output
Methods inherited from RDFSink.RDFSink:
- 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.
- setGenPrefix(self, genPrefix)
- startDoc(self)
| |