parsers Package

parsers Package

hturtle Module

Extraction parser RDF embedded verbatim into HTML or XML files. This is based on:

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]
__module__ = 'rdflib.plugins.parsers.hturtle'
graph_from_DOM(dom, graph, pgraph=None)[source]

Stealing the parsing function from the original class, to do turtle extraction only

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:

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: exceptions.SyntaxError

__init__(uri, lines, argstr, i, why)[source]
__module__ = 'rdflib.plugins.parsers.notation3'
__str__()[source]
__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

__init__()[source]
__module__ = 'rdflib.plugins.parsers.notation3'
parse(source, graph, encoding='utf-8')[source]
class rdflib.plugins.parsers.notation3.TurtleParser[source]

Bases: rdflib.parser.Parser

An RDFLib parser for Turtle

See http://www.w3.org/TR/turtle/

__init__()[source]
__module__ = 'rdflib.plugins.parsers.notation3'
parse(source, graph, encoding='utf-8', turtle=True)[source]
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') 
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.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

rdflib.plugins.parsers.notation3.runNamespace()[source]

Return a URI suitable as a namespace for run-local objects

rdflib.plugins.parsers.notation3.uniqueURI()[source]

A unique URI

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")
'http://example/a%20b'

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") 
<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)[source]

Bases: rdflib.plugins.parsers.ntriples.NTriplesParser

__module__ = 'rdflib.plugins.parsers.nquads'
parse(inputsource, sink, **kwargs)[source]

Parse f as an N-Triples file.

parseline()[source]

nt Module

class rdflib.plugins.parsers.nt.NTSink(graph)[source]

Bases: object

__init__(graph)[source]
__module__ = 'rdflib.plugins.parsers.nt'
triple(s, p, o)[source]
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

__init__()[source]
__module__ = 'rdflib.plugins.parsers.nt'
parse(source, sink, baseURI=None)[source]

ntriples Module

N-Triples Parser License: GPL 2, W3C, BSD, or MIT Author: Sean B. Palmer, inamidst.com

rdflib.plugins.parsers.ntriples.unquote(s)[source]

Unquote an N-Triples string.

rdflib.plugins.parsers.ntriples.uriquote(uri)[source]
class rdflib.plugins.parsers.ntriples.Sink[source]

Bases: object

__init__()[source]
__module__ = 'rdflib.plugins.parsers.ntriples'
triple(s, p, o)[source]
class rdflib.plugins.parsers.ntriples.NTriplesParser(sink=None)[source]

Bases: object

An N-Triples Parser.

Usage:

p = NTriplesParser(sink=MySink())
sink = p.parse(f) # file; use parsestring for a string
__init__(sink=None)[source]
__module__ = 'rdflib.plugins.parsers.ntriples'
eat(pattern)[source]
literal()[source]
nodeid()[source]
object()[source]
parse(f)[source]

Parse f as an N-Triples file.

parseline()[source]
parsestring(s)[source]

Parse s as an N-Triples string.

peek(token)[source]
predicate()[source]
readline()[source]

Read an N-Triples line from buffered input.

subject()[source]
uriref()[source]

rdfxml Module

An RDF/XML parser for RDFLib

rdflib.plugins.parsers.rdfxml.create_parser(target, store)[source]
class rdflib.plugins.parsers.rdfxml.BagID(val)[source]

Bases: rdflib.term.URIRef

__init__(val)[source]
__module__ = 'rdflib.plugins.parsers.rdfxml'
__slots__ = ['li']
li
next_li()[source]
class rdflib.plugins.parsers.rdfxml.ElementHandler[source]

Bases: object

__init__()[source]
__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
next_li()[source]
object
predicate
start
subject
class rdflib.plugins.parsers.rdfxml.RDFXMLHandler(store)[source]

Bases: xml.sax.handler.ContentHandler

__init__(store)[source]
__module__ = 'rdflib.plugins.parsers.rdfxml'
absolutize(uri)[source]
add_reified()[source]
characters(content)[source]
convert(name, qname, attrs)[source]
current
document_element_start(name, qname, attrs)[source]
endElementNS(name, qname)[source]
endPrefixMapping(prefix)[source]
error(message)[source]
get_current()[source]
get_next()[source]
get_parent()[source]
ignorableWhitespace(content)[source]
list_node_element_end(name, qname)[source]
literal_element_char(data)[source]
literal_element_end(name, qname)[source]
literal_element_start(name, qname, attrs)[source]
next
node_element_end(name, qname)[source]
node_element_start(name, qname, attrs)[source]
parent
processingInstruction(target, data)[source]
property_element_char(data)[source]
property_element_end(name, qname)[source]
property_element_start(name, qname, attrs)[source]
reset()[source]
setDocumentLocator(locator)[source]
startDocument()[source]
startElementNS(name, qname, attrs)[source]
startPrefixMapping(prefix, namespace)[source]
class rdflib.plugins.parsers.rdfxml.RDFXMLParser[source]

Bases: rdflib.parser.Parser

__init__()[source]
__module__ = 'rdflib.plugins.parsers.rdfxml'
parse(source, sink, **args)[source]

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:

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

rdflib.plugins.parsers.trix.create_parser(store)[source]
class rdflib.plugins.parsers.trix.TriXHandler(store)[source]

Bases: xml.sax.handler.ContentHandler

An Sax Handler for TriX. See http://sw.nokia.com/trix/

__init__(store)[source]
__module__ = 'rdflib.plugins.parsers.trix'
characters(content)[source]
endElementNS(name, qname)[source]
endPrefixMapping(prefix)[source]
error(message)[source]
get_bnode(label)[source]
ignorableWhitespace(content)[source]
processingInstruction(target, data)[source]
reset()[source]
setDocumentLocator(locator)[source]
startDocument()[source]
startElementNS(name, qname, attrs)[source]
startPrefixMapping(prefix, namespace)[source]
class rdflib.plugins.parsers.trix.TriXParser[source]

Bases: rdflib.parser.Parser

A parser for TriX. See http://sw.nokia.com/trix/

__init__()[source]
__module__ = 'rdflib.plugins.parsers.trix'
parse(source, sink, **args)[source]