KDE 4.9 PyKDE API Reference

- KDE's Python API

# Parser Class Reference

`from PyKDE4.soprano import *`

Inherits: Soprano.Plugin,Soprano.Error.ErrorCache
Namespace: Soprano

## Detailed Description

\class Parser parser.h Soprano/Parser

Soprano.Parser defines the interface for a Soprano RDF parser plugin.

Each parser plugin may support multiple RDF serializations (supportedSerializations()).

Usage

Using a Parser is straightforward. One starts by getting a plugin that supports the requested RDF data serialization:

     const Soprano.Parser* p = Soprano.PluginManager.instance()->discoverParserForSerialization( Soprano.SerializationRdfXml );

Then parsing RDF data is done in a single method call resulting in a StatementIterator over the resulting graph (since parsers may support multiple serializations one always needs to provide the serialization type unless a parser plugin support autodetection).

     Soprano.StatementIterator it = p->parseFile( "myrdffile.rdf", Soprano.SerializationRdfXml );

\sa soprano_writing_plugins

Author:
  Daniele Galdi <daniele.galdi@gmail.com>
  Sebastian Trueg <trueg@kde.org>

## Methods

| __init__ (self, QString name)
Soprano.StatementIterator | parseFile (self, QString filename, QUrl baseUri, Soprano.RdfSerialization serialization, QString userSerialization=QString())
Soprano.StatementIterator | parseStream (self, QTextStream stream, QUrl baseUri, Soprano.RdfSerialization serialization, QString userSerialization=QString())
Soprano.StatementIterator | parseString (self, QString data, QUrl baseUri, Soprano.RdfSerialization serialization, QString userSerialization=QString())
Soprano.RdfSerializations | supportedSerializations (self)
QStringList | supportedUserSerializations (self)
bool | supportsSerialization (self, Soprano.RdfSerialization s, QString userSerialization=QString())

## Method Documentation

__init__ | ( | self, |
|  | QString | name
| ) |  |  |

Soprano.StatementIterator parseFile | ( | self, |
|  | QString | filename,
|  | QUrl | baseUri,
|  | Soprano.RdfSerialization | serialization,
|  | QString | userSerialization=QString()
| ) |  |  |

Parse an RDF model which has been serialized in a file, using the supplied baseURI to resolve any relative URI references.

The default implementation simply calls parseStream() on an opened QFile instance.

Parameters:

  | filename | The name (path) of the file to parse

Parameters:

  | baseUri | The base URI to be used for relative references.

Parameters:

  | serialization | The serialization used in the file.

Parameters:

  | userSerialization | If serialization is set to Soprano.SerializationUser this parameter specifies the serialization to use. It allows the extension of the %Soprano Parser interface with new RDF serializations that are not officially supported by %Soprano.

Returns:
  An iterator that iterates over the result statements.

Soprano.StatementIterator parseStream | ( | self, |
|  | QTextStream | stream,
|  | QUrl | baseUri,
|  | Soprano.RdfSerialization | serialization,
|  | QString | userSerialization=QString()
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Read a serialized RDF model from a test stream, using the supplied baseURI to resolve any relative URI references.

Parameters:

  | stream | The text stream to read the serialized RDF data from.

Parameters:

  | baseUri | The base URI to be used for relative references.

Parameters:

  | serialization | The serialization used for the string data from the stream.

Parameters:

  | userSerialization | If serialization is set to Soprano.SerializationUser this parameter specifies the serialization to use. It allows the extension of the %Soprano Parser interface with new RDF serializations that are not officially supported by %Soprano.

Returns:
  An iterator that iterates over the result statements.

Soprano.StatementIterator parseString | ( | self, |
|  | QString | data,
|  | QUrl | baseUri,
|  | Soprano.RdfSerialization | serialization,
|  | QString | userSerialization=QString()
| ) |  |  |

Parse an RDF model which has been serialized into a string, using the supplied baseURI to resolve any relative URI references.

The default implementation simply calls parseStream().

Parameters:

  | data | The serialized RDF string.

Parameters:

  | baseUri | The base URI to be used for relative references.

Parameters:

  | serialization | The serialization used for the string data.

Parameters:

  | userSerialization | If serialization is set to Soprano.SerializationUser this parameter specifies the serialization to use. It allows the extension of the %Soprano Parser interface with new RDF serializations that are not officially supported by %Soprano.

Returns:
  An iterator that iterates over the result statements.

Soprano.RdfSerializations supportedSerializations | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

The serialiazation types supported by this parser.

Returns:
  A combination of Soprano.RdfSerialization types. If the list contains Soprano.SerializationUser the parser supports additional RDF serializations not officially supported by %Soprano.

QStringList supportedUserSerializations | ( |  | self ) |

A parser can support additional RDF serializations that are not defined in Soprano.RdfSerialization. In that case supportedSerializations() has to include Soprano.SerializationUser.

The default implementation returns an empty list.

Returns:
  A list of supported user RDF serializations.

bool supportsSerialization | ( | self, |
|  | Soprano.RdfSerialization | s,
|  | QString | userSerialization=QString()
| ) |  |  |

Check if a plugin supports a specific serialization.

Parameters:

  | s | The requested serialization.

Parameters:

  | userSerialization | If serialization is set to Soprano.SerializationUser this parameter specifies the requested serialization. It allows the extension of the %Soprano Parser interface with new RDF serializations that are not officially supported by %Soprano.

Returns:
  true if the parser is able to parse RDF data encoded in serialization s, false otherwise.