rdflib.plugins.parsers package¶
Submodules¶
rdflib.plugins.parsers.RDFVOC module¶
rdflib.plugins.parsers.hext module¶
This is a rdflib plugin for parsing Hextuple files, which are Newline-Delimited JSON (ndjson) files, into Conjunctive. The store that backs the graph must be able to handle contexts, i.e. multiple graphs.
- class rdflib.plugins.parsers.hext.HextuplesParser[source]¶
Bases:
Parser
An RDFLib parser for Hextuples
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.hext', '__doc__': '\n An RDFLib parser for Hextuples\n\n ', '__init__': <function HextuplesParser.__init__>, '_load_json_line': <function HextuplesParser._load_json_line>, '_parse_hextuple': <function HextuplesParser._parse_hextuple>, 'parse': <function HextuplesParser.parse>, '__dict__': <attribute '__dict__' of 'HextuplesParser' objects>, '__weakref__': <attribute '__weakref__' of 'HextuplesParser' objects>, '__annotations__': {}})¶
- __module__ = 'rdflib.plugins.parsers.hext'¶
- __weakref__¶
list of weak references to the object (if defined)
rdflib.plugins.parsers.jsonld module¶
This parser will interpret a JSON-LD document as an RDF Graph. See:
Example usage:
>>> from rdflib import Graph, URIRef, Literal
>>> test_json = '''
... {
... "@context": {
... "dc": "http://purl.org/dc/terms/",
... "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
... "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
... },
... "@id": "http://example.org/about",
... "dc:title": {
... "@language": "en",
... "@value": "Someone's Homepage"
... }
... }
... '''
>>> g = Graph().parse(data=test_json, format='json-ld')
>>> list(g) == [(URIRef('http://example.org/about'),
... URIRef('http://purl.org/dc/terms/title'),
... Literal("Someone's Homepage", lang='en'))]
True
- class rdflib.plugins.parsers.jsonld.JsonLDParser[source]¶
Bases:
Parser
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.jsonld', '__init__': <function JsonLDParser.__init__>, 'parse': <function JsonLDParser.parse>, '__dict__': <attribute '__dict__' of 'JsonLDParser' objects>, '__weakref__': <attribute '__weakref__' of 'JsonLDParser' objects>, '__doc__': None, '__annotations__': {}})¶
- __module__ = 'rdflib.plugins.parsers.jsonld'¶
- __weakref__¶
list of weak references to the object (if defined)
rdflib.plugins.parsers.notation3 module¶
notation3.py - Standalone Notation3 Parser Derived from CWM, the Closed World Machine
Authors of the original suite:
Dan Connolly <@@>
Tim Berners-Lee <@@>
Yosi Scharf <@@>
Joseph M. Reagle Jr. <reagle@w3.org>
Rich Salz <rsalz@zolera.com>
http://www.w3.org/2000/10/swap/notation3.py
Copyright 2000-2007, World Wide Web Consortium. Copyright 2001, MIT. Copyright 2001, Zolera Systems Inc.
License: W3C Software License http://www.w3.org/Consortium/Legal/copyright-software
Modified by Sean B. Palmer Copyright 2007, Sean B. Palmer.
Modified to work with rdflib by Gunnar Aastrand Grimnes Copyright 2010, Gunnar A. Grimnes
- exception rdflib.plugins.parsers.notation3.BadSyntax(uri, lines, argstr, i, why)[source]¶
Bases:
SyntaxError
- __module__ = 'rdflib.plugins.parsers.notation3'¶
- __weakref__¶
list of weak references to the object (if defined)
- class rdflib.plugins.parsers.notation3.Formula(parent)[source]¶
Bases:
object
- Parameters:
parent (
Graph
) –
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.notation3', 'number': 0, '__init__': <function Formula.__init__>, '__str__': <function Formula.__str__>, 'id': <function Formula.id>, 'newBlankNode': <function Formula.newBlankNode>, 'newUniversal': <function Formula.newUniversal>, 'declareExistential': <function Formula.declareExistential>, 'close': <function Formula.close>, '__dict__': <attribute '__dict__' of 'Formula' objects>, '__weakref__': <attribute '__weakref__' of 'Formula' objects>, '__doc__': None, '__annotations__': {'existentials': 'Dict[str, BNode]', 'universals': 'Dict[str, BNode]'}})¶
- __module__ = 'rdflib.plugins.parsers.notation3'¶
- __weakref__¶
list of weak references to the object (if defined)
- number = 0¶
- class rdflib.plugins.parsers.notation3.N3Parser[source]¶
Bases:
TurtleParser
An RDFLib parser for Notation3
See http://www.w3.org/DesignIssues/Notation3.html
- __annotations__ = {}¶
- __module__ = 'rdflib.plugins.parsers.notation3'¶
- class rdflib.plugins.parsers.notation3.RDFSink(graph)[source]¶
Bases:
object
- Parameters:
graph (
Graph
) –
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.notation3', '__init__': <function RDFSink.__init__>, 'newFormula': <function RDFSink.newFormula>, 'newGraph': <function RDFSink.newGraph>, 'newSymbol': <function RDFSink.newSymbol>, 'newBlankNode': <function RDFSink.newBlankNode>, 'newLiteral': <function RDFSink.newLiteral>, 'newList': <function RDFSink.newList>, 'newSet': <function RDFSink.newSet>, 'setDefaultNamespace': <function RDFSink.setDefaultNamespace>, 'makeStatement': <function RDFSink.makeStatement>, 'normalise': <function RDFSink.normalise>, 'intern': <function RDFSink.intern>, 'bind': <function RDFSink.bind>, 'startDoc': <function RDFSink.startDoc>, 'endDoc': <function RDFSink.endDoc>, '__dict__': <attribute '__dict__' of 'RDFSink' objects>, '__weakref__': <attribute '__weakref__' of 'RDFSink' objects>, '__doc__': None, '__annotations__': {'rootFormula': 'Optional[Formula]'}})¶
- __module__ = 'rdflib.plugins.parsers.notation3'¶
- __weakref__¶
list of weak references to the object (if defined)
- newGraph(identifier)[source]¶
- Parameters:
identifier (
Identifier
) –- Return type:
- class rdflib.plugins.parsers.notation3.SinkParser(store, openFormula=None, thisDoc='', baseURI=None, genPrefix='', why=None, turtle=False)[source]¶
Bases:
object
- Parameters:
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.notation3', '__init__': <function SinkParser.__init__>, 'here': <function SinkParser.here>, 'formula': <function SinkParser.formula>, 'loadStream': <function SinkParser.loadStream>, 'loadBuf': <function SinkParser.loadBuf>, 'feed': <function SinkParser.feed>, 'directiveOrStatement': <function SinkParser.directiveOrStatement>, 'tok': <function SinkParser.tok>, 'sparqlTok': <function SinkParser.sparqlTok>, 'directive': <function SinkParser.directive>, 'sparqlDirective': <function SinkParser.sparqlDirective>, 'bind': <function SinkParser.bind>, 'setKeywords': <function SinkParser.setKeywords>, 'startDoc': <function SinkParser.startDoc>, 'endDoc': <function SinkParser.endDoc>, 'makeStatement': <function SinkParser.makeStatement>, 'statement': <function SinkParser.statement>, 'subject': <function SinkParser.subject>, 'verb': <function SinkParser.verb>, 'prop': <function SinkParser.prop>, 'item': <function SinkParser.item>, 'blankNode': <function SinkParser.blankNode>, 'path': <function SinkParser.path>, 'anonymousNode': <function SinkParser.anonymousNode>, 'node': <function SinkParser.node>, 'property_list': <function SinkParser.property_list>, 'commaSeparatedList': <function SinkParser.commaSeparatedList>, 'objectList': <function SinkParser.objectList>, 'checkDot': <function SinkParser.checkDot>, 'uri_ref2': <function SinkParser.uri_ref2>, 'skipSpace': <function SinkParser.skipSpace>, 'variable': <function SinkParser.variable>, 'bareWord': <function SinkParser.bareWord>, 'qname': <function SinkParser.qname>, 'object': <function SinkParser.object>, 'nodeOrLiteral': <function SinkParser.nodeOrLiteral>, 'uriOf': <function SinkParser.uriOf>, 'strconst': <function SinkParser.strconst>, '_unicodeEscape': <function SinkParser._unicodeEscape>, 'uEscape': <function SinkParser.uEscape>, 'UEscape': <function SinkParser.UEscape>, 'BadSyntax': <function SinkParser.BadSyntax>, '__dict__': <attribute '__dict__' of 'SinkParser' objects>, '__weakref__': <attribute '__weakref__' of 'SinkParser' objects>, '__doc__': None, '__annotations__': {'_anonymousNodes': 'Dict[str, BNode]', '_variables': 'Dict[str, Variable]', '_parentVariables': 'Dict[str, Variable]', '_reason2': 'Optional[Callable[..., None]]', '_baseURI': 'Optional[str]', '_formula': 'Optional[Formula]', '_context': 'Optional[Formula]', '_parentContext': 'Optional[Formula]'}})¶
- __init__(store, openFormula=None, thisDoc='', baseURI=None, genPrefix='', why=None, turtle=False)[source]¶
note: namespace names should not end in # ; the # will get added during qname processing
- __module__ = 'rdflib.plugins.parsers.notation3'¶
- __weakref__¶
list of weak references to the object (if defined)
- bareWord(argstr, i, res)[source]¶
abc -> :abc
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- commaSeparatedList(argstr, j, res, what)[source]¶
return value: -1 bad syntax; >1 new position in argstr res has things found appended
- feed(octets)[source]¶
Feed an octet stream to the 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.
- here(i)[source]¶
String generated from position in file
This is for repeatability when referring 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(argstr, i, res)[source]¶
- Parameters:
argstr (
str
) –res (
MutableSequence
[Any
]) –
- Return type:
- node(argstr, i, res, subjectAlready=None)[source]¶
Parse the <node> production. Space is now skipped once at the beginning instead of in multiple calls to self.skipSpace().
- nodeOrLiteral(argstr, i, res)[source]¶
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- object(argstr, i, res)[source]¶
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- objectList(argstr, i, res)[source]¶
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- path(argstr, i, res)[source]¶
Parse the path production.
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- prop(argstr, i, res)[source]¶
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- property_list(argstr, i, subj)[source]¶
Parse property list Leaves the terminating punctuation in the buffer
- qname(argstr, i, res)[source]¶
xyz:def -> (‘xyz’, ‘def’) If not in keywords and keywordsSet: def -> (‘’, ‘def’) :def -> (‘’, ‘def’)
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Union
[Identifier
,Tuple
[str
,str
]]]) –
- Return type:
- skipSpace(argstr, i)[source]¶
Skip white space, newlines and comments. return -1 if EOF, else position of first non-ws character
- sparqlDirective(argstr, i)[source]¶
turtle and trig support BASE/PREFIX without @ and without terminating .
- sparqlTok(tok, argstr, i)[source]¶
Check for SPARQL keyword. Space must have been stripped on entry and we must not be at end of file. Case insensitive and not preceded by @
- strconst(argstr, i, delim)[source]¶
parse an N3 string constant delimited by delim. return index, val
- subject(argstr, i, res)[source]¶
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- tok(tok, argstr, i, colon=False)[source]¶
Check for keyword. Space must have been stripped on entry and we must not be at end of file.
if colon, then keyword followed by colon is ok (@prefix:<blah> is ok, rdf:type shortcut a must be followed by ws)
- uri_ref2(argstr, i, res)[source]¶
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.
- Parameters:
argstr (
str
) –i (
int
) –res (
MutableSequence
[Any
]) –
- Return type:
- class rdflib.plugins.parsers.notation3.TurtleParser[source]¶
Bases:
Parser
An RDFLib parser for Turtle
See http://www.w3.org/TR/turtle/
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.notation3', '__doc__': '\n An RDFLib parser for Turtle\n\n See http://www.w3.org/TR/turtle/\n ', '__init__': <function TurtleParser.__init__>, 'parse': <function TurtleParser.parse>, '__dict__': <attribute '__dict__' of 'TurtleParser' objects>, '__weakref__': <attribute '__weakref__' of 'TurtleParser' objects>, '__annotations__': {}})¶
- __module__ = 'rdflib.plugins.parsers.notation3'¶
- __weakref__¶
list of weak references to the object (if defined)
- rdflib.plugins.parsers.notation3.base()[source]¶
The base URI for this process - the Web equiv of cwd
Relative or absolute unix-standard filenames parsed relative to this yield the URI of the file. If we had a reliable way of getting a computer name, we should put it in the hostname just to prevent ambiguity
- Return type:
- rdflib.plugins.parsers.notation3.hexify(ustr)[source]¶
Use URL encoding to return an ASCII string corresponding to the given UTF8 string
>>> hexify("http://example/a b") b'http://example/a%20b'
- rdflib.plugins.parsers.notation3.join(here, there)[source]¶
join an absolute URI and URI reference (non-ascii characters are supported/doctested; haven’t checked the details of the IRI spec though)
here
is assumed to be absolute.there
is URI reference.>>> join('http://example/x/y/z', '../abc') 'http://example/x/abc'
Raise ValueError if there uses relative path syntax but here has no hierarchical path.
>>> join('mid:foo@example', '../foo') Traceback (most recent call last): raise ValueError(here) ValueError: Base <mid:foo@example> has no slash after colon - with relative '../foo'.
>>> join('http://example/x/y/z', '') 'http://example/x/y/z'
>>> join('mid:foo@example', '#foo') 'mid:foo@example#foo'
We grok IRIs
>>> len(u'Andr\xe9') 5
>>> join('http://example.org/', u'#Andr\xe9') u'http://example.org/#Andr\xe9'
- rdflib.plugins.parsers.notation3.runNamespace()[source]¶
Returns a URI suitable as a namespace for run-local objects
- Return type:
rdflib.plugins.parsers.nquads module¶
This is a rdflib plugin for parsing NQuad files into Conjunctive graphs that can be used and queried. The store that backs the graph must be able to handle contexts.
>>> from rdflib import ConjunctiveGraph, URIRef, Namespace
>>> g = ConjunctiveGraph()
>>> data = open("test/data/nquads.rdflib/example.nquads", "rb")
>>> g.parse(data, format="nquads")
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> assert len(g.store) == 449
>>> # There should be 16 separate contexts
>>> assert len([x for x in g.store.contexts()]) == 16
>>> # is the name of entity E10009 "Arco Publications"?
>>> # (in graph http://bibliographica.org/entity/E10009)
>>> # Looking for:
>>> # <http://bibliographica.org/entity/E10009>
>>> # <http://xmlns.com/foaf/0.1/name>
>>> # "Arco Publications"
>>> # <http://bibliographica.org/entity/E10009>
>>> s = URIRef("http://bibliographica.org/entity/E10009")
>>> FOAF = Namespace("http://xmlns.com/foaf/0.1/")
>>> assert(g.value(s, FOAF.name).eq("Arco Publications"))
- class rdflib.plugins.parsers.nquads.NQuadsParser(sink=None, bnode_context=None)[source]¶
Bases:
W3CNTriplesParser
- Parameters:
sink (
Union
[DummySink
,NTGraphSink
,None
]) –bnode_context (
Optional
[MutableMapping
[str
,BNode
]]) –
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.nquads', 'parse': <function NQuadsParser.parse>, 'parseline': <function NQuadsParser.parseline>, '__dict__': <attribute '__dict__' of 'NQuadsParser' objects>, '__weakref__': <attribute '__weakref__' of 'NQuadsParser' objects>, '__doc__': None, '__annotations__': {'sink': "Union[DummySink, 'NTGraphSink']", 'buffer': 'Optional[str]', 'file': 'Optional[Union[TextIO, codecs.StreamReader]]', 'line': 'Optional[str]'}})¶
- __module__ = 'rdflib.plugins.parsers.nquads'¶
- __weakref__¶
list of weak references to the object (if defined)
- buffer: Optional[str]¶
- file: Optional[Union[TextIO, codecs.StreamReader]]¶
- line: Optional[str]¶
- parse(inputsource, sink, bnode_context=None, **kwargs)[source]¶
Parse inputsource as an N-Quads file.
- Parameters:
inputsource (
InputSource
) – the source of N-Quads-formatted datasink (
ConjunctiveGraph
) – where to send parsed triplesbnode_context (
Optional
[MutableMapping
[str
,BNode
]]) – a dict mapping blank node identifiers to ~rdflib.term.BNode instances. See .W3CNTriplesParser.parsekwargs (
Any
) –
- Return type:
- parseline(bnode_context=None)[source]¶
- Parameters:
bnode_context (
Optional
[MutableMapping
[str
,BNode
]]) –- Return type:
- sink: Union[DummySink, 'NTGraphSink']¶
rdflib.plugins.parsers.ntriples module¶
N-Triples Parser License: GPL 2, W3C, BSD, or MIT Author: Sean B. Palmer, inamidst.com
- class rdflib.plugins.parsers.ntriples.DummySink[source]¶
Bases:
object
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.ntriples', '__init__': <function DummySink.__init__>, 'triple': <function DummySink.triple>, '__dict__': <attribute '__dict__' of 'DummySink' objects>, '__weakref__': <attribute '__weakref__' of 'DummySink' objects>, '__doc__': None, '__annotations__': {}})¶
- __module__ = 'rdflib.plugins.parsers.ntriples'¶
- __weakref__¶
list of weak references to the object (if defined)
- class rdflib.plugins.parsers.ntriples.NTGraphSink(graph)[source]¶
Bases:
object
- Parameters:
graph (
Graph
) –
- __module__ = 'rdflib.plugins.parsers.ntriples'¶
- __slots__ = ('g',)¶
- g¶
- class rdflib.plugins.parsers.ntriples.NTParser[source]¶
Bases:
Parser
parser for the ntriples format, often stored with the .nt extension
See http://www.w3.org/TR/rdf-testcases/#ntriples
- __annotations__ = {}¶
- __module__ = 'rdflib.plugins.parsers.ntriples'¶
- __slots__ = ()¶
- class rdflib.plugins.parsers.ntriples.W3CNTriplesParser(sink=None, bnode_context=None)[source]¶
Bases:
object
An N-Triples Parser. This is a legacy-style Triples parser for NTriples provided by W3C Usage:
p = W3CNTriplesParser(sink=MySink()) sink = p.parse(f) # file; use parsestring for a string
To define a context in which blank node identifiers refer to the same blank node across instances of NTriplesParser, pass the same dict as
bnode_context
to each instance. By default, a new blank node context is created for each instance of W3CNTriplesParser.- Parameters:
sink (
Union
[DummySink
,NTGraphSink
,None
]) –bnode_context (
Optional
[MutableMapping
[str
,BNode
]]) –
- __annotations__ = {}¶
- __init__(sink=None, bnode_context=None)[source]¶
- Parameters:
sink (
Union
[DummySink
,NTGraphSink
,None
]) –bnode_context (
Optional
[MutableMapping
[str
,BNode
]]) –
- __module__ = 'rdflib.plugins.parsers.ntriples'¶
- __slots__ = ('_bnode_ids', 'sink', 'buffer', 'file', 'line')¶
-
file:
Union
[TextIO
,StreamReader
,None
]¶
- parse(f, bnode_context=None)[source]¶
Parse f as an N-Triples file.
- Parameters:
f (
Union
[TextIO
,IO
[bytes
],StreamReader
]) – the N-Triples sourcebnode_context (
Optional
[MutableMapping
[str
,BNode
]]) – a dict mapping blank node identifiers (e.g.,a
in_:a
) to ~rdflib.term.BNode instances. An empty dict can be passed in to define a distinct context for a given call to parse.
- Return type:
- parseline(bnode_context=None)[source]¶
- Parameters:
bnode_context (
Optional
[MutableMapping
[str
,BNode
]]) –- Return type:
-
sink:
Union
[DummySink
,NTGraphSink
]¶
rdflib.plugins.parsers.rdfxml module¶
An RDF/XML parser for RDFLib
- class rdflib.plugins.parsers.rdfxml.BagID(value: str, base: str | None = None)[source]¶
Bases:
URIRef
- __annotations__ = {}¶
- __module__ = 'rdflib.plugins.parsers.rdfxml'¶
- __slots__ = ['li']¶
- li¶
- class rdflib.plugins.parsers.rdfxml.ElementHandler[source]¶
Bases:
object
- __module__ = 'rdflib.plugins.parsers.rdfxml'¶
- __slots__ = ['start', 'char', 'end', 'li', 'id', 'base', 'subject', 'predicate', 'object', 'list', 'language', 'datatype', 'declared', 'data']¶
- base¶
- char¶
- data¶
- datatype¶
- declared¶
- end¶
- id¶
- language¶
- li¶
- list¶
- object¶
- predicate¶
- start¶
- subject¶
- class rdflib.plugins.parsers.rdfxml.RDFXMLHandler(store)[source]¶
Bases:
ContentHandler
- Parameters:
store (
Graph
) –
- __module__ = 'rdflib.plugins.parsers.rdfxml'¶
- characters(content)[source]¶
Receive notification of character data.
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.
- property current: ElementHandler | None¶
- document_element_start(name, qname, attrs)[source]¶
- Parameters:
attrs (
AttributesImpl
) –
- Return type:
- endElementNS(name, qname)[source]¶
Signals the end of an element in namespace mode.
The name parameter contains the name of the element type, just as with the startElementNS event.
- endPrefixMapping(prefix)[source]¶
End the scope of a prefix-URI mapping.
See startPrefixMapping for details. This event will always occur after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.
- ignorableWhitespace(content)[source]¶
Receive notification of ignorable whitespace in element content.
Validating Parsers must use this method to report each chunk of ignorable whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.
SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
- Return type:
- literal_element_start(name, qname, attrs)[source]¶
- Parameters:
attrs (
AttributesImpl
) –
- Return type:
- property next: ElementHandler | None¶
- node_element_start(name, qname, attrs)[source]¶
- Parameters:
attrs (
AttributesImpl
) –
- Return type:
- property parent: ElementHandler | None¶
- processingInstruction(target, data)[source]¶
Receive notification of a processing instruction.
The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.
A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.
- Return type:
- property_element_start(name, qname, attrs)[source]¶
- Parameters:
attrs (
AttributesImpl
) –
- Return type:
- setDocumentLocator(locator)[source]¶
Called by the parser to give the application a locator for locating the origin of document events.
SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the DocumentHandler interface.
The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application’s business rules). The information returned by the locator is probably not sufficient for use with a search engine.
Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.
- Parameters:
locator (
Locator
) –
- startDocument()[source]¶
Receive notification of the beginning of a document.
The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).
- Return type:
- startElementNS(name, qname, attrs)[source]¶
Signals the start of an element in namespace mode.
The name parameter contains the name of the element type as a (uri, localname) tuple, the qname parameter the raw XML 1.0 name used in the source document, and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.
The uri part of the name tuple is None for elements which have no namespace.
- startPrefixMapping(prefix, namespace)[source]¶
Begin the scope of a prefix-URI Namespace mapping.
The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).
There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.
Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each-other: all startPrefixMapping events will occur before the corresponding startElement event, and all endPrefixMapping events will occur after the corresponding endElement event, but their order is not guaranteed.
- class rdflib.plugins.parsers.rdfxml.RDFXMLParser[source]¶
Bases:
Parser
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.rdfxml', '__init__': <function RDFXMLParser.__init__>, 'parse': <function RDFXMLParser.parse>, '__dict__': <attribute '__dict__' of 'RDFXMLParser' objects>, '__weakref__': <attribute '__weakref__' of 'RDFXMLParser' objects>, '__doc__': None, '__annotations__': {}})¶
- __module__ = 'rdflib.plugins.parsers.rdfxml'¶
- __weakref__¶
list of weak references to the object (if defined)
- rdflib.plugins.parsers.rdfxml.create_parser(target, store)[source]¶
- Parameters:
target (
InputSource
) –store (
Graph
) –
- Return type:
rdflib.plugins.parsers.trig module¶
- class rdflib.plugins.parsers.trig.TrigParser[source]¶
Bases:
Parser
An RDFLib parser for TriG
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.trig', '__doc__': '\n An RDFLib parser for TriG\n\n ', '__init__': <function TrigParser.__init__>, 'parse': <function TrigParser.parse>, '__dict__': <attribute '__dict__' of 'TrigParser' objects>, '__weakref__': <attribute '__weakref__' of 'TrigParser' objects>, '__annotations__': {}})¶
- __module__ = 'rdflib.plugins.parsers.trig'¶
- __weakref__¶
list of weak references to the object (if defined)
- class rdflib.plugins.parsers.trig.TrigSinkParser(store, openFormula=None, thisDoc='', baseURI=None, genPrefix='', why=None, turtle=False)[source]¶
Bases:
SinkParser
- Parameters:
- __annotations__ = {}¶
- __module__ = 'rdflib.plugins.parsers.trig'¶
- graph(argstr, i)[source]¶
Parse trig graph, i.e.
<urn:graphname> = { .. triples .. }
return -1 if it doesn’t look like a graph-decl raise Exception if it looks like a graph, but isn’t.
rdflib.plugins.parsers.trix module¶
A TriX parser for RDFLib
- class rdflib.plugins.parsers.trix.TriXHandler(store)[source]¶
Bases:
ContentHandler
An Sax Handler for TriX. See http://sw.nokia.com/trix/
- Parameters:
store (
Store
) –
- __annotations__ = {}¶
- __module__ = 'rdflib.plugins.parsers.trix'¶
- characters(content)[source]¶
Receive notification of character data.
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.
- endElementNS(name, qname)[source]¶
Signals the end of an element in namespace mode.
The name parameter contains the name of the element type, just as with the startElementNS event.
- endPrefixMapping(prefix)[source]¶
End the scope of a prefix-URI mapping.
See startPrefixMapping for details. This event will always occur after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.
- ignorableWhitespace(content)[source]¶
Receive notification of ignorable whitespace in element content.
Validating Parsers must use this method to report each chunk of ignorable whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.
SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
- Return type:
- processingInstruction(target, data)[source]¶
Receive notification of a processing instruction.
The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.
A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.
- Return type:
- setDocumentLocator(locator)[source]¶
Called by the parser to give the application a locator for locating the origin of document events.
SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the DocumentHandler interface.
The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application’s business rules). The information returned by the locator is probably not sufficient for use with a search engine.
Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.
- Parameters:
locator (
Locator
) –
- startDocument()[source]¶
Receive notification of the beginning of a document.
The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).
- Return type:
- startElementNS(name, qname, attrs)[source]¶
Signals the start of an element in namespace mode.
The name parameter contains the name of the element type as a (uri, localname) tuple, the qname parameter the raw XML 1.0 name used in the source document, and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.
The uri part of the name tuple is None for elements which have no namespace.
- startPrefixMapping(prefix, namespace)[source]¶
Begin the scope of a prefix-URI Namespace mapping.
The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).
There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.
Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each-other: all startPrefixMapping events will occur before the corresponding startElement event, and all endPrefixMapping events will occur after the corresponding endElement event, but their order is not guaranteed.
- class rdflib.plugins.parsers.trix.TriXParser[source]¶
Bases:
Parser
A parser for TriX. See http://sw.nokia.com/trix/
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'rdflib.plugins.parsers.trix', '__doc__': 'A parser for TriX. See http://sw.nokia.com/trix/', '__init__': <function TriXParser.__init__>, 'parse': <function TriXParser.parse>, '__dict__': <attribute '__dict__' of 'TriXParser' objects>, '__weakref__': <attribute '__weakref__' of 'TriXParser' objects>, '__annotations__': {}})¶
- __module__ = 'rdflib.plugins.parsers.trix'¶
- __weakref__¶
list of weak references to the object (if defined)