2
This file is part of the Nepomuk KDE project.
3
Copyright (C) 2010 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_RESOURCEIDENTIFIER_H
24
#define NEPOMUK_RESOURCEIDENTIFIER_H
26
#include <QtCore/QObject>
29
#include "nepomuksync_export.h"
46
* \class ResourceIdentifier resourceidentifier.h
48
* This class is used to identify already existing resources from a set of
49
* properties and objects. It identifies the resources on the basis of the
50
* identifying statements provided.
52
* \author Vishesh Handa <handa.vish@gmail.com>
54
class NEPOMUKSYNC_EXPORT ResourceIdentifier
57
ResourceIdentifier( Soprano::Model * model = 0 );
58
virtual ~ResourceIdentifier();
60
Soprano::Model * model();
61
void setModel( Soprano::Model * model );
68
bool identify( const KUrl & uri );
71
* Identifies all the resources present in the \p uriList.
73
void identify( const KUrl::List & uriList );
76
* This returns true if ALL the external ResourceUris have been identified.
77
* If this is false, you should manually identify some of the resources by
78
* providing the resource.
82
bool allIdentified() const;
84
virtual void addStatement( const Soprano::Statement & st );
85
virtual void addStatements( const Soprano::Graph& graph );
86
virtual void addStatements( const QList<Soprano::Statement> & stList );
87
virtual void addSyncResource( const SyncResource & res );
93
* Returns the detected uri for the given resourceUri.
94
* This method useful only after identifyAll() method was called
96
KUrl mappedUri( const KUrl & resourceUri ) const;
98
KUrl::List mappedUris() const;
101
* Returns mappings of the identified uri
103
QHash<QUrl, QUrl> mappings() const;
106
* Returns urls that were not successfully identified
108
QSet<KUrl> unidentified() const;
110
QSet< QUrl > identified() const;
113
* Returns all the statements that are being used to identify \p uri
115
Soprano::Graph statements( const KUrl & uri );
117
QList<Soprano::Statement> identifyingStatements() const;
119
SyncResource simpleResource( const KUrl & uri );
124
* The property \p prop will be matched during identification, but it will
125
* not contribute to the actual score if it cannot be matched.
127
void addOptionalProperty( const QUrl & property );
129
void clearOptionalProperties();
131
KUrl::List optionalProperties() const;
134
// Manual Identification
137
* Used for manual identification when both the old Resource uri, and
138
* the new resource Uri is provided.
140
* If the resource \p res provided is of type nfo:FileDataObject and has
141
* a nie:url. That url will be used to attempt to identify the unidentified
142
* resources having a similar nie:url ( same directory or common base directory )
143
* It does not perform the actual identification, but changes the internal identification
144
* statements so that the unidentified resources may be identified during the next
145
* call to identifyAll
147
* This method should typically be called after identifyAll has been called at least once.
149
void forceResource( const KUrl & oldUri, const Resource & res);
152
* Ignores resourceUri (It will no longer play a part in identification )
153
* if @p ignoreSub is true and resourceUri is a Folder, all the sub folders
154
* and files are also ignored.
156
* This is an expensive method. It will also remove all the statements which
157
* contain \p uri as the object.
159
bool ignore( const KUrl& uri, bool ignoreSub = false );
162
// Identification Statement generator
164
static Soprano::Graph createIdentifyingStatements( const KUrl::List & uriList );
166
virtual bool isIdentifyingProperty( const QUrl & uri );
173
* Called during identification if there is more than one match for one resource.
175
* The default behavior is to return an empty uri, which depicts identification failure
177
virtual KUrl duplicateMatch( const KUrl & uri, const QSet<KUrl> & matchedUris );
180
* This function returns true if identification was successful, and false if it was not.
181
* If you need to customize the identification process, you will need to overload this
184
virtual bool runIdentification( const KUrl& uri );
187
* Sets oldUri -> newUri in the mappings.
188
* This is useful when runIdentification has been reimplemented.
190
void manualIdentification( const KUrl & oldUri, const KUrl & newUri );
195
#endif // NEPOMUK_RESOURCEIDENTIFIER_H