parsers Package¶
parsers
Package¶
hturtle
Module¶
Extraction parser RDF embedded verbatim into HTML or XML files. This is based on:
- The specification on embedding turtle into html:
- http://www.w3.org/TR/turtle/#in-html
For SVG (and currently SVG only) the method also extracts an embedded RDF/XML data, per SVG specification
License: W3C Software License, http://www.w3.org/Consortium/Legal/copyright-software Author: Ivan Herman Copyright: W3C
-
class
rdflib.plugins.parsers.hturtle.
HTurtle
(options=None, base='', media_type='')[source]¶ Bases:
rdflib.plugins.parsers.pyRdfa.pyRdfa
Bastardizing the RDFa 1.1 parser to do a hturtle extractions
-
__init__
(options=None, base='', media_type='')[source]¶ @keyword options: Options for the distiller @type options: L{Options} @keyword base: URI for the default “base” value (usually the URI of the file to be processed) @keyword media_type: explicit setting of the preferred media type (a.k.a. content type) of the the RDFa source @keyword rdfa_version: the RDFa version that should be used. If not set, the value of the global L{rdfa_current_version} variable is used
-
__module__
= 'rdflib.plugins.parsers.hturtle'¶
-
-
class
rdflib.plugins.parsers.hturtle.
HTurtleParser
[source]¶ Bases:
rdflib.parser.Parser
-
__module__
= 'rdflib.plugins.parsers.hturtle'¶
-
parse
(source, graph, pgraph=None, media_type='')[source]¶ @param source: one of the input sources that the RDFLib package defined @type source: InputSource class instance @param graph: target graph for the triples; output graph, in RDFa spec. parlance @type graph: RDFLib Graph @keyword media_type: explicit setting of the preferred media type (a.k.a. content type) of the the RDFa source. None means the content type of the HTTP result is used, or a guess is made based on the suffix of a file @type media_type: string
-
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
-
__init__
(uri, lines, argstr, i, why)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
__module__
= 'rdflib.plugins.parsers.notation3'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
message
¶
-
-
class
rdflib.plugins.parsers.notation3.
N3Parser
[source]¶ Bases:
rdflib.plugins.parsers.notation3.TurtleParser
An RDFLib parser for Notation3
See http://www.w3.org/DesignIssues/Notation3.html
-
__module__
= 'rdflib.plugins.parsers.notation3'¶
-
-
class
rdflib.plugins.parsers.notation3.
TurtleParser
[source]¶ Bases:
rdflib.parser.Parser
An RDFLib parser for Turtle
See http://www.w3.org/TR/turtle/
-
__module__
= 'rdflib.plugins.parsers.notation3'¶
-
-
rdflib.plugins.parsers.notation3.
splitFragP
(uriref, punct=0)[source]¶ split a URI reference before the fragment
Punctuation is kept.
e.g.
>>> splitFragP("abc#def") ('abc', '#def')
>>> splitFragP("abcdef") ('abcdef', '')
-
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') # doctest: +NORMALIZE_WHITESPACE 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('Andr\xe9') 5
>>> join('http://example.org/', '#Andr\xe9') 'http://example.org/#Andr\xe9'
-
rdflib.plugins.parsers.notation3.
base
()[source]¶ The base URI for this process - the Web equiv of cwd
Relative or abolute unix-standard filenames parsed relative to this yeild 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
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/nquads.rdflib/example.nquads", "rb")
>>> g.parse(data, format="nquads") # doctest:+ELLIPSIS
<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"))
nt
Module¶
-
class
rdflib.plugins.parsers.nt.
NTSink
(graph)[source]¶ Bases:
object
-
__module__
= 'rdflib.plugins.parsers.nt'¶
-
-
class
rdflib.plugins.parsers.nt.
NTParser
[source]¶ Bases:
rdflib.parser.Parser
parser for the ntriples format, often stored with the .nt extension
See http://www.w3.org/TR/rdf-testcases/#ntriples
-
__module__
= 'rdflib.plugins.parsers.nt'¶
-
ntriples
Module¶
N-Triples Parser License: GPL 2, W3C, BSD, or MIT Author: Sean B. Palmer, inamidst.com
-
class
rdflib.plugins.parsers.ntriples.
Sink
[source]¶ Bases:
object
-
__module__
= 'rdflib.plugins.parsers.ntriples'¶
-
rdfxml
Module¶
An RDF/XML parser for RDFLib
-
class
rdflib.plugins.parsers.rdfxml.
BagID
(val)[source]¶ Bases:
rdflib.term.URIRef
-
__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:
xml.sax.handler.ContentHandler
-
__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.
-
current
¶
-
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.
-
next
¶
-
parent
¶
-
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.
-
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.
-
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).
-
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.
-
structureddata
Module¶
Extraction parsers for structured data embedded into HTML or XML files. The former may include RDFa or microdata. The syntax and the extraction procedures are based on:
- The RDFa specifications: http://www.w3.org/TR/#tr_RDFa
- The microdata specification: http://www.w3.org/TR/microdata/
- The specification of the microdata to RDF conversion:
http://www.w3.org/TR/microdata-rdf/
License: W3C Software License, http://www.w3.org/Consortium/Legal/copyright-software Author: Ivan Herman Copyright: W3C
-
class
rdflib.plugins.parsers.structureddata.
MicrodataParser
[source]¶ Bases:
rdflib.parser.Parser
Wrapper around an HTML5 microdata, extracted and converted into RDF. For the specification of microdata, see the relevant section of the HTML5 spec: http://www.w3.org/TR/microdata/; for the algorithm used to extract microdata into RDF, see http://www.w3.org/TR/microdata-rdf/.
-
__module__
= 'rdflib.plugins.parsers.structureddata'¶
-
parse
(source, graph, vocab_expansion=False, vocab_cache=False)[source]¶ @param source: one of the input sources that the RDFLib package defined @type source: InputSource class instance @param graph: target graph for the triples; output graph, in RDFa spec. parlance @type graph: RDFLib Graph @keyword vocab_expansion: whether the RDFa @vocab attribute should also mean vocabulary expansion (see the RDFa 1.1 spec for further
details)@type vocab_expansion: Boolean @keyword vocab_cache: in case vocab expansion is used, whether the expansion data (i.e., vocabulary) should be cached locally. This requires the ability for the local application to write on the local file system @type vocab_chache: Boolean @keyword rdfOutput: whether Exceptions should be catched and added, as triples, to the processor graph, or whether they should be raised. @type rdfOutput: Boolean
-
-
class
rdflib.plugins.parsers.structureddata.
RDFa10Parser
[source]¶ Bases:
rdflib.parser.Parser
This is just a convenience class to wrap around the RDFa 1.0 parser.
-
__module__
= 'rdflib.plugins.parsers.structureddata'¶
-
parse
(source, graph, pgraph=None, media_type='')[source]¶ @param source: one of the input sources that the RDFLib package defined @type source: InputSource class instance @param graph: target graph for the triples; output graph, in RDFa spec. parlance @type graph: RDFLib Graph @keyword pgraph: target for error and warning triples; processor graph, in RDFa spec. parlance. If set to None, these triples are ignored @type pgraph: RDFLib Graph @keyword media_type: explicit setting of the preferred media type (a.k.a. content type) of the the RDFa source. None means the content type of the HTTP result is used, or a guess is made based on the suffix of a file @type media_type: string @keyword rdfOutput: whether Exceptions should be catched and added, as triples, to the processor graph, or whether they should be raised. @type rdfOutput: Boolean
-
-
class
rdflib.plugins.parsers.structureddata.
RDFaParser
[source]¶ Bases:
rdflib.parser.Parser
Wrapper around the RDFa 1.1 parser. For further details on the RDFa 1.1 processing, see the relevant W3C documents at http://www.w3.org/TR/#tr_RDFa. RDFa 1.1 is defined for XHTML, HTML5, SVG and, in general, for any XML language.
Note that the parser can also handle RDFa 1.0 if the extra parameter is used and/or the input source uses RDFa 1.0 specific @version or DTD-s.
-
__module__
= 'rdflib.plugins.parsers.structureddata'¶
-
parse
(source, graph, pgraph=None, media_type='', rdfa_version=None, embedded_rdf=False, space_preserve=True, vocab_expansion=False, vocab_cache=False, refresh_vocab_cache=False, vocab_cache_report=False, check_lite=False)[source]¶ @param source: one of the input sources that the RDFLib package defined @type source: InputSource class instance @param graph: target graph for the triples; output graph, in RDFa spec. parlance @type graph: RDFLib Graph @keyword pgraph: target for error and warning triples; processor graph, in RDFa spec. parlance. If set to None, these triples are ignored @type pgraph: RDFLib Graph @keyword media_type: explicit setting of the preferred media type (a.k.a. content type) of the the RDFa source. None means the content type of the HTTP result is used, or a guess is made based on the suffix of a file @type media_type: string @keyword rdfa_version: 1.0 or 1.1. If the value is “”, then, by default, 1.1 is used unless the source has explicit signals to use 1.0 (e.g., using a @version attribute, using a DTD set up for 1.0, etc) @type rdfa_version: string @keyword embedded_rdf: some formats allow embedding RDF in other formats: (X)HTML can contain turtle in a special <script> element, SVG can have RDF/XML embedded in a <metadata> element. This flag controls whether those triples should be interpreted and added to the output graph. Some languages (e.g., SVG) require this, and the flag is ignored. @type embedded_rdf: Boolean @keyword space_preserve: by default, space in the HTML source must be preserved in the generated literal; this behavior can be switched off @type space_preserve: Boolean @keyword vocab_expansion: whether the RDFa @vocab attribute should also mean vocabulary expansion (see the RDFa 1.1 spec for further details) @type vocab_expansion: Boolean @keyword vocab_cache: in case vocab expansion is used, whether the expansion data (i.e., vocabulary) should be cached locally. This requires the ability for the local application to write on the local file system @type vocab_chache: Boolean @keyword vocab_cache_report: whether the details of vocabulary file caching process should be reported in the processor graph as information (mainly useful for debug) @type vocab_cache_report: Boolean @keyword refresh_vocab_cache: whether the caching checks of vocabs should be by-passed, ie, if caches should be re-generated regardless of the stored date (important for vocab development) @type refresh_vocab_cache: Boolean @keyword check_lite: generate extra warnings in case the input source is not RDFa 1.1 check_lite @type check_lite: Boolean
-
-
class
rdflib.plugins.parsers.structureddata.
StructuredDataParser
[source]¶ Bases:
rdflib.parser.Parser
Convenience parser to extract both RDFa (including embedded Turtle) and microdata from an HTML file. It is simply a wrapper around the specific parsers.
-
__module__
= 'rdflib.plugins.parsers.structureddata'¶
-
parse
(source, graph, pgraph=None, rdfa_version='', vocab_expansion=False, vocab_cache=False, media_type='text/html')[source]¶ @param source: one of the input sources that the RDFLib package defined @type source: InputSource class instance @param graph: target graph for the triples; output graph, in RDFa spec. parlance @keyword rdfa_version: 1.0 or 1.1. If the value is “”, then, by default, 1.1 is used unless the source has explicit signals to use 1.0 (e.g., using a @version attribute, using a DTD set up for 1.0, etc) @type rdfa_version: string @type graph: RDFLib Graph @keyword pgraph: target for error and warning triples; processor graph, in RDFa spec. parlance. If set to None, these triples are ignored @type pgraph: RDFLib Graph @keyword vocab_expansion: whether the RDFa @vocab attribute should also mean vocabulary expansion (see the RDFa 1.1 spec for further
details)@type vocab_expansion: Boolean @keyword vocab_cache: in case vocab expansion is used, whether the expansion data (i.e., vocabulary) should be cached locally. This requires the ability for the local application to write on the local file system @type vocab_chache: Boolean @keyword rdfOutput: whether Exceptions should be catched and added, as triples, to the processor graph, or whether they should be raised. @type rdfOutput: Boolean
-
trix
Module¶
A TriX parser for RDFLib
-
class
rdflib.plugins.parsers.trix.
TriXHandler
(store)[source]¶ Bases:
xml.sax.handler.ContentHandler
An Sax Handler for TriX. See http://sw.nokia.com/trix/
-
__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.
-
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.
-
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.
-
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).
-
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:
rdflib.parser.Parser
A parser for TriX. See http://sw.nokia.com/trix/
-
__module__
= 'rdflib.plugins.parsers.trix'¶
-