KDE 4.7 PyKDE API Reference

- KDE's Python API

# Serializer Class Reference

`from PyKDE4.soprano import *`

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

## Detailed Description

\class Serializer serializer.h Soprano/Serializer

Soprano.Serializer defines the interface for a Soprano RDF serializer plugin.

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

Usage

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

     Soprano.Serializer* s = Soprano.PluginManager.instance()->discoverSerializerForSerialization( Soprano.SerializationRdfXml );

Then serializing RDF data is done in a single method call which writes the serialized data to a QTextStream:

     QTextStream stream( stdout );
     s->serialize( model->listStatements(), stream, Soprano.SerializationRdfXml );

\sa soprano_writing_plugins

Author:
  Sebastian Trueg <trueg@kde.org>

## Methods

| __init__ (self, QString name)
| addPrefix (self, QString qname, QUrl uri)
| clearPrefixes (self)
{QString:QUrl} | prefixes (self)
bool | serialize (self, Soprano.StatementIterator it, QTextStream stream, 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
| ) |  |  |

addPrefix | ( | self, |
|  | QString | qname,
|  | QUrl | uri
| ) |  |  |

Add a prefix to be used by the serializer.

Be aware that serializer instances are reused. Thus, it is highly recommended to clear prefixes after using the Serializer. A future version of %Soprano will have a revised %Serializer API which handles this issue more effective.

Method is const for historical reasons.

Since:
  2.3

clearPrefixes | ( |  | self ) |

Clear all prefixes set via addPrefix.

Method is const for historical reasons.

Since:
  2.3

{QString:QUrl} prefixes | ( |  | self ) |

Retrieve all prefixes set via addPrefix.

Returns:
  a QHash containing of the prefixe qnames and their URIs.

Since:
  2.3

bool serialize | ( | self, |
|  | Soprano.StatementIterator | it,
|  | QTextStream | stream,
|  | Soprano.RdfSerialization | serialization,
|  | QString | userSerialization=QString()
| ) |  |  |

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

Serialize a list of statements.

Parameters:

  | it | An iterator containing the statements to be serialized.

Parameters:

  | stream | The stream the serialized data should be written to.

Parameters:

  | serialization | The encoding to be used.

Parameters:

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

Returns:
  true if the %serialization was successful, false otherwise.

Soprano.RdfSerializations supportedSerializations | ( |  | self ) |

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

The serialiazation types supported by this serializer.

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

QStringList supportedUserSerializations | ( |  | self ) |

A serializer 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 Serializer interface with new RDF serializations that are not officially supported by %Soprano.

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