22
22
#ifndef SOPRANO_PARSER_H
23
23
#define SOPRANO_PARSER_H
25
#include <soprano/soprano_export.h>
26
#include "soprano_export.h"
27
#include "sopranotypes.h"
30
#include <QtCore/QObject>
38
class StatementIterator;
37
* Different types of RDF serialization.
41
* \class Parser parser.h Soprano/Parser
43
* \brief Soprano::Parser defines the interface for a Soprano RDF parser plugin.
45
* Each parser plugin may support multiple RDF serializations (supportedSerializations()).
50
* Using a Parser is straightforward. Once starts by getting a plugin that supports the requested
51
* RDF data serilization:
54
* Parser* p = PluginManager::instance()->discoverParserForSerialization( SerializationRdfXml );
57
* Then parsing RDF data is done in a single method call resulting in a StatementIterator over
58
* the resulting graph (since parsers may support multiple serializations one always needs to
59
* provide the serialization type unless a parser plugin support autodetection).
62
* StatementIterator it = p->parseFile( "myrdffile.rdf", SerializationRdfXml );
65
* \sa \ref soprano_writing_plugins
67
* \author Daniele Galdi <daniele.galdi@gmail.com><br>Sebastian Trueg <trueg@kde.org>
39
// FIXME: what about the used charsets? Should we and if so, how should we include them?
40
enum RdfSerialization {
41
UNKNOWN = 0x0, /**< The serialization is unknown. */
42
RDF_XML = 0x1, /**< Standard RDF/XML serialization */
43
N3 = 0x2, /**< Notation 3: http://www.w3.org/DesignIssues/Notation3 */
44
N_TRIPLES = 0x4, /**< N-Triples as defined by W3: http://www.w3.org/TR/rdf-testcases/#ntriples */
45
TURTLE = 0x8, /**< Turtle - Terse RDF Triple Language: http://www.dajobe.org/2004/01/turtle/ */
46
TRIG = 0x10 /**< TriG - Turtle + Named Graphs: http://sites.wiwiss.fu-berlin.de/suhl/bizer/TriG/ */
69
class SOPRANO_EXPORT Parser : public Plugin, public Error::ErrorCache
75
* The serialiazation types supported by this parser.
76
* \return A combination of Soprano::RdfSerialization types. If
77
* the list contains Soprano::SerializationUser the parser
78
* supports additional RDF serialiazations not
79
* officially supported by %Soprano.
81
virtual RdfSerializations supportedSerializations() const = 0;
84
* A parser can support additional RDF serializations that are not defined in Soprano::RdfSerialization.
85
* In that case supportedSerializations() has to include Soprano::SerializationUser.
87
* The default implementation returns an empty list.
89
* \return A list of supported user RDF serializations.
91
virtual QStringList supportedUserSerializations() const;
94
* Check if a plugin supports a specific serialization.
96
* \param s The requested serialization.
97
* \param userSerialization If serialization is set to Soprano::SerializationUser this parameter specifies the
98
* requested serialization. It allows the extension of the %Soprano Parser interface with new
99
* RDF serializations that are not officially supported by %Soprano.
101
* \return \p true if the parser is able to parse RDF data encoded
102
* in serialization s, \p false otherwise.
104
bool supportsSerialization( RdfSerialization s, const QString& userSerialization = QString() ) const;
107
* Parse an RDF model which has been serialized in a file,
108
* using the supplied baseURI to resolve any relative URI references.
110
* The default implementation simply calls parseStream() on an opened
113
* \param filename The name (path) of the file to parse
114
* \param baseUri The base URI to be used for relative references.
115
* \param serialization The serialization used in the file.
116
* \param userSerialization If serialization is set to Soprano::SerializationUser this parameter specifies the
117
* serialization to use. It allows the extension of the %Soprano Parser interface with new
118
* RDF serializations that are not officially supported by %Soprano.
120
* \return An iterator that iterates over the result statements.
122
virtual StatementIterator parseFile( const QString& filename, const QUrl& baseUri, RdfSerialization serialization, const QString& userSerialization = QString() ) const;
125
* Parse an RDF model which has been serialized into a string,
126
* using the supplied baseURI to resolve any relative URI references.
128
* The default implementation simply calls parseStream().
130
* \param data The serialized RDF string.
131
* \param baseUri The base URI to be used for relative references.
132
* \param serialization The serialization used for the string data.
133
* \param userSerialization If serialization is set to Soprano::SerializationUser this parameter specifies the
134
* serialization to use. It allows the extension of the %Soprano Parser interface with new
135
* RDF serializations that are not officially supported by %Soprano.
137
* \return An iterator that iterates over the result statements.
139
virtual StatementIterator parseString( const QString& data, const QUrl& baseUri, RdfSerialization serialization, const QString& userSerialization = QString() ) const;
142
* Read a serialized RDF model from a test stream,
143
* using the supplied baseURI to resolve any relative URI references.
145
* \param stream The text stream to read the serialized RDF data from.
146
* \param baseUri The base URI to be used for relative references.
147
* \param serialization The serialization used for the string data from the stream.
148
* \param userSerialization If serialization is set to Soprano::SerializationUser this parameter specifies the
149
* serialization to use. It allows the extension of the %Soprano Parser interface with new
150
* RDF serializations that are not officially supported by %Soprano.
152
* \return An iterator that iterates over the result statements.
154
virtual StatementIterator parseStream( QTextStream& stream, const QUrl& baseUri, RdfSerialization serialization, const QString& userSerialization = QString() ) const = 0;
157
Parser( const QString& name );
48
Q_DECLARE_FLAGS(RdfSerializations, RdfSerialization)
51
* \return The mimetype of serialization or an empty string is serialization is UNKNOWN
53
SOPRANO_EXPORT QString serializationMimeType( RdfSerialization serialization );
56
* Parse a mimetype and match it to the RdfSerialization enum.
57
* \return the RdfSerialization type that matches mimetype or UNKNOWN if the mimetype
58
* could not be parsed.
60
SOPRANO_EXPORT RdfSerialization mimeTypeToSerialization( const QString& mimetype );
62
class SOPRANO_EXPORT Parser
68
* The serialiazation types supported by this parser.
69
* \return A combination of RdfSerialization types.
71
virtual RdfSerializations supportedSerializations() const = 0;
75
* Calls parseFile with RDF_XML serialization
77
Model* parse( const QUrl& url ) const;
80
* Parse an RDF model which has been serialized in a file,
81
* using the supplied baseURI to resolve any relative URI references.
83
* The default implementation simply calls parseStream on an opened
86
* \param filename The name (path) of the file to parse
87
* \param baseUri The base URI to be used for relative references.
88
* \param serialization The serialization used in the file.
89
* If UNKNOWN the parser is supposed to auto detect the serialization type.
90
* Might not be reliable.
92
virtual Model* parseFile( const QString& filename, const QUrl& baseUri, RdfSerialization serialization = UNKNOWN ) const;
95
* Parse an RDF model which has been serialized into a string,
96
* using the supplied baseURI to resolve any relative URI references.
98
* The default implementation simply calls parseStream.
100
* \param data The serialized RDF string.
101
* \param baseUri The base URI to be used for relative references.
102
* \param serialization The serialization used for the string data.
103
* If UNKNOWN the parser is supposed to auto detect the serialization type.
104
* Might not be reliable.
106
virtual Model* parseString( const QString& data, const QUrl& baseUri, RdfSerialization serialization = UNKNOWN ) const;
109
* Read a serialized RDF model from a test stream,
110
* using the supplied baseURI to resolve any relative URI references.
112
* \param stream The text stream to read the serialized RDF data from.
113
* \param baseUri The base URI to be used for relative references.
114
* \param serialization The serialization used for the string data from the stream.
115
* If UNKNOWN the parser is supposed to auto detect the serialization type.
116
* Might not be reliable.
118
virtual Model* parseStream( QTextStream* stream, const QUrl& baseUri, RdfSerialization serialization = UNKNOWN ) const = 0;
125
Q_DECLARE_OPERATORS_FOR_FLAGS(Soprano::RdfSerializations)
165
Q_DECLARE_INTERFACE(Soprano::Parser, "org.soprano.plugins.Parser/1.0")
127
167
#endif // SOPRANO_PARSER_H