2
This file is part of the Nepomuk KDE project.
3
Copyright (C) 2010-11 Vishesh Handa <handa.vish@gmail.com>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) version 3, or any
9
later version accepted by the membership of KDE e.V. (or its
10
successor approved by the membership of KDE e.V.), which shall
11
act as a proxy defined in Section 6 of version 3 of the license.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef NEPOMUK_RESOURCEMERGER_H
24
#define NEPOMUK_RESOURCEMERGER_H
26
#include <QtCore/QList>
27
#include <QtCore/QHash>
31
#include "nepomuksync_export.h"
32
#include <Soprano/Error/ErrorCode>
44
class ResourceManager;
53
* \class ResourceMerger resourcemerger.h
55
* This class can be used to push resources into repository after identification.
56
* It's default behavior is to create all the resources that have not been
59
* By default, it pushes all the statements with a nrl:InstanceBase graph. If a
60
* statement already exists in the repository then it is NOT overwritten.
62
* \author Vishesh Handa <handa.vish@gmail.com>
64
class NEPOMUKSYNC_EXPORT ResourceMerger : public Soprano::Error::ErrorCache
67
ResourceMerger( Soprano::Model * model =0, const QHash<KUrl, KUrl> & mappings = (QHash<KUrl, KUrl>()) );
68
virtual ~ResourceMerger();
70
void setModel( Soprano::Model * model );
71
Soprano::Model * model() const;
73
void setMappings( const QHash<KUrl, KUrl> & mappings );
74
QHash<KUrl, KUrl> mappings() const;
77
* Merges all the statements in \p graph into the model, by calling
80
* It stops merging if any of the statements in \p graph fail to merge
83
* \return \c true if merging was successful
85
virtual bool merge( const Soprano::Graph & graph );
88
* Merges the statement \p st into the model. If the statement
89
* already exists then resolveDuplicate() is called.
91
* If any of the statements contains a graph, then that graph is used. Otherwise
92
* createGraph() is called which returns a new graph.
94
* lastError() is set, if merging fails.
97
* \return \c true if the merging was sucessful.
98
* \c false if merging failed
100
virtual bool mergeStatement( const Soprano::Statement & st );
103
* Sets the graph metadata which will be used to create a graph.
107
void setAdditionalGraphMetadata( const QMultiHash<QUrl, Soprano::Node>& additionalMetadata );
109
QMultiHash<QUrl, Soprano::Node> additionalMetadata() const;
113
* Called when trying to merge a statement which contains a Resource that
114
* has not been identified.
116
* The default implementation of this creates the resource in the model.
117
* The resourceUri is generated using createResourceUri.
119
* If the resolution is supposed to fail, this function returns KUrl().
120
* The reason why resolution failed should also be set with setError()
122
* \sa createResourceUri
124
virtual KUrl resolveUnidentifiedResource( const KUrl & uri );
127
* Creates a new graph with the additional metadata.
128
* All graphs that are created should be a subtype of nrl:Graph
130
* \sa additionalMetadata
132
virtual KUrl createGraph();
135
* Push the statement into the Nepomuk repository.
136
* If a statement with the same subject, predicate and object already
137
* exists in the model, then resolveDuplicate is called.
139
* \sa resolveDuplicate
140
* \return \c true if pushing the statement was successful
142
bool push( const Soprano::Statement & st );
145
* If the statement being pushed already exists this method is called.
146
* By default it does nothing which means keeping the old statement
148
* \return \c true if resolution was successful
149
* \c false if resolution failed, and merging and should fail
151
virtual bool resolveDuplicate( const Soprano::Statement & newSt );
154
* Creates a new resource uri. By default this creates it using the
155
* ResourceManager::instace()->generateUniqueUri("res")
157
virtual QUrl createResourceUri();
160
* Creates a new graph uri. By default this creates it using the
161
* ResourceManager::instace()->generateUniqueUri("ctx")
163
virtual QUrl createGraphUri();
166
* Returns the graph that is being used to add new statements.
167
* If this graph does not exist it is created using createGraph
174
* Add the statement in the model. By default it just calls
175
* Soprano::Model::addStatement()
177
* \return \c Soprano::Error::ErrorNone if added to model
179
virtual Soprano::Error::ErrorCode addStatement( const Soprano::Statement & st );
180
Soprano::Error::ErrorCode addStatement( const Soprano::Node& subject, const Soprano::Node& property,
181
const Soprano::Node& object, const Soprano::Node& graph );
184
* Resolves the subject and object and gets the object ready for pushing
186
bool resolveStatement( Soprano::Statement& st );
193
#endif // NEPOMUK_RESOURCEMERGER_H