# 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='')

  Bases: `rdflib.plugins.parsers.pyRdfa.pyRdfa`

  Bastardizing the RDFa 1.1 parser to do a hturtle extractions

  `__init__`(options=None, base='', media_type='')
  `__module__` = 'rdflib.plugins.parsers.hturtle'
  `graph_from_DOM`(dom, graph, pgraph=None)

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

class `rdflib.plugins.parsers.hturtle.``HTurtleParser`

  Bases: `rdflib.parser.Parser`

  `__module__` = 'rdflib.plugins.parsers.hturtle'
  `parse`(source, graph, pgraph=None, media_type='')

    @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)

  Bases: `exceptions.SyntaxError`

  `__init__`(uri, lines, argstr, i, why)
  `__module__` = 'rdflib.plugins.parsers.notation3'
  `__str__`()
  `__weakref__`

    list of weak references to the object (if defined)

  `message`

class `rdflib.plugins.parsers.notation3.``N3Parser`

  Bases: `rdflib.plugins.parsers.notation3.TurtleParser`

  An RDFLib parser for Notation3

  See http://www.w3.org/DesignIssues/Notation3.html

  `__init__`()
  `__module__` = 'rdflib.plugins.parsers.notation3'
  `parse`(source, graph, encoding='utf-8')

class `rdflib.plugins.parsers.notation3.``TurtleParser`

  Bases: `rdflib.parser.Parser`

  An RDFLib parser for Turtle

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

  `__init__`()
  `__module__` = 'rdflib.plugins.parsers.notation3'
  `parse`(source, graph, encoding='utf-8', turtle=True)

`rdflib.plugins.parsers.notation3.``splitFragP`(uriref, punct=0)

  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)

  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`()

  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`()

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

`rdflib.plugins.parsers.notation3.``uniqueURI`()

  A unique URI

`rdflib.plugins.parsers.notation3.``hexify`(ustr)

  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)

  Bases: `rdflib.plugins.parsers.ntriples.NTriplesParser`

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

    Parse f as an N-Triples file.

  `parseline`()

## `nt` Module

class `rdflib.plugins.parsers.nt.``NTSink`(graph)

  Bases: `object`

  `__init__`(graph)
  `__module__` = 'rdflib.plugins.parsers.nt'
  `triple`(s, p, o)

class `rdflib.plugins.parsers.nt.``NTParser`

  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__`()
  `__module__` = 'rdflib.plugins.parsers.nt'
  `parse`(source, sink, baseURI=None)

## `ntriples` Module

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

`rdflib.plugins.parsers.ntriples.``unquote`(s)

  Unquote an N-Triples string.

`rdflib.plugins.parsers.ntriples.``uriquote`(uri)

class `rdflib.plugins.parsers.ntriples.``Sink`

  Bases: `object`

  `__init__`()
  `__module__` = 'rdflib.plugins.parsers.ntriples'
  `triple`(s, p, o)

class `rdflib.plugins.parsers.ntriples.``NTriplesParser`(sink=None)

  Bases: `object`

  An N-Triples Parser.

  Usage:

      p = NTriplesParser(sink=MySink())
      sink = p.parse(f) # file; use parsestring for a string

  `__init__`(sink=None)
  `__module__` = 'rdflib.plugins.parsers.ntriples'
  `eat`(pattern)
  `literal`()
  `nodeid`()
  `object`()
  `parse`(f)

    Parse f as an N-Triples file.

  `parseline`()
  `parsestring`(s)

    Parse s as an N-Triples string.

  `peek`(token)
  `predicate`()
  `readline`()

    Read an N-Triples line from buffered input.

  `subject`()
  `uriref`()

## `rdfxml` Module

An RDF/XML parser for RDFLib

`rdflib.plugins.parsers.rdfxml.``create_parser`(target, store)

class `rdflib.plugins.parsers.rdfxml.``BagID`(val)

  Bases: `rdflib.term.URIRef`

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

class `rdflib.plugins.parsers.rdfxml.``ElementHandler`

  Bases: `object`

  `__init__`()
  `__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`()
  `object`
  `predicate`
  `start`
  `subject`

class `rdflib.plugins.parsers.rdfxml.``RDFXMLHandler`(store)

  Bases: `xml.sax.handler.ContentHandler`

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

class `rdflib.plugins.parsers.rdfxml.``RDFXMLParser`

  Bases: `rdflib.parser.Parser`

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

## `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`

  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)

    @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`

  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='')

    @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`

  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, vocab_expansion=False, vocab_cache=False)

    @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 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

class `rdflib.plugins.parsers.structureddata.``StructuredDataParser`

  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')

    @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)

class `rdflib.plugins.parsers.trix.``TriXHandler`(store)

  Bases: `xml.sax.handler.ContentHandler`

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

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

class `rdflib.plugins.parsers.trix.``TriXParser`

  Bases: `rdflib.parser.Parser`

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

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

## Subpackages

- pyMicrodata Package
  - `pyMicrodata` Package
    - (Simple) Usage
      - Return formats
  - `microdata` Module
  - `registry` Module
  - `utils` Module
- pyRdfa Package
  - `pyRdfa` Package
    - (Simple) Usage
      - Return (serialization) formats
    - Options
    - Host Languages
    - Vocabularies
      - Vocabulary caching
    - RDFa 1.1 vs. RDFa 1.0
    - Transformers
  - `embeddedRDF` Module
  - `initialcontext` Module
  - `options` Module
  - `parse` Module
  - `property` Module
  - `state` Module
  - `termorcurie` Module
  - `utils` Module
  - Subpackages
    - extras Package
      - `extras` Package
      - `httpheader` Module
    - host Package
      - `host` Package
      - `atom` Module
      - `html5` Module
    - rdfs Package
      - `rdfs` Package
      - `cache` Module
      - `process` Module
    - transform Package
      - `transform` Package
      - `DublinCore` Module
      - `OpenID` Module
      - `lite` Module
      - `metaname` Module
      - `prototype` Module