24 #include <Soprano/Node>
25 #include <Soprano/Statement>
26 #include <Soprano/StatementIterator>
27 #include <Soprano/NodeIterator>
28 #include <Soprano/QueryResultIterator>
29 #include <Soprano/Query/QueryLanguage>
30 #include <Soprano/Util/DummyModel>
31 #include <Soprano/StorageModel>
33 #include <Soprano/Backend>
34 #include <Soprano/PluginManager>
37 #include <kstandarddirs.h>
39 #include <ksharedconfig.h>
40 #include <KConfigGroup>
42 #include <QtCore/QTimer>
43 #include <QtCore/QMutex>
44 #include <QtCore/QMutexLocker>
45 #include <QtCore/QFile>
47 using namespace Soprano;
49 class Nepomuk2::MainModel::Private
55 m_initMutex( QMutex::Recursive ) {
63 Soprano::StorageModel* virtuosoModel;
64 Soprano::Util::DummyModel* dummyModel;
66 void init(
bool forced ) {
67 QMutexLocker lock( &m_initMutex );
69 if( !forced && virtuosoModel )
72 Soprano::PluginManager* pm = Soprano::PluginManager::instance();
73 const Soprano::Backend* backend = pm->discoverBackendByName( QLatin1String(
"virtuosobackend" ) );
75 if ( !backend || !backend->isAvailable() ) {
76 kError() <<
"Could not find virtuoso backend";
79 Soprano::BackendSettings settings;
81 KConfig config(
"nepomukserverrc");
82 KConfigGroup repoConfig = config.group(
"main Settings" );
83 int portNumber = repoConfig.readEntry(
"Port", 0);
85 kError() <<
"Could not find virtuoso to connect to. Aborting";
89 settings << Soprano::BackendSetting( Soprano::BackendOptionHost,
"localhost" );
90 settings << Soprano::BackendSetting( Soprano::BackendOptionPort, portNumber );
91 settings << Soprano::BackendSetting( Soprano::BackendOptionUsername,
"dba" );
92 settings << Soprano::BackendSetting( Soprano::BackendOptionPassword,
"dba" );
93 settings << Soprano::BackendSetting(
"noStatementSignals",
true );
94 settings << Soprano::BackendSetting(
"fakeBooleans",
false );
95 settings << Soprano::BackendSetting(
"emptyGraphs",
false );
99 virtuosoModel->deleteLater();
101 virtuosoModel = backend ? backend->createModel( settings ) : 0;
105 Soprano::Model* model() {
106 QMutexLocker lock( &m_initMutex );
110 if ( virtuosoModel ) {
111 return virtuosoModel;
115 dummyModel =
new Soprano::Util::DummyModel();
141 QMutexLocker lock( &d->m_initMutex );
142 return d->virtuosoModel;
154 QMutexLocker lock( &d->m_initMutex );
155 d->virtuosoModel->deleteLater();
156 d->virtuosoModel = 0;
162 Soprano::StatementIterator it = d->model()->listStatements( partial );
163 setError( d->model()->lastError() );
170 Soprano::NodeIterator it = d->model()->listContexts();
171 setError( d->model()->lastError() );
179 const char* s_nepomukInferenceRuleSetName =
"nepomukinference";
183 Soprano::Query::QueryLanguage language,
184 const QString& userQueryLanguage )
const
186 Soprano::QueryResultIterator it;
187 if(language == Soprano::Query::QueryLanguageSparqlNoInference) {
188 it = d->model()->executeQuery(query, Soprano::Query::QueryLanguageSparql);
190 else if(language == Soprano::Query::QueryLanguageSparql ) {
191 it = d->model()->executeQuery(QString::fromLatin1(
"DEFINE input:inference <%1> ")
192 .arg(QLatin1String(s_nepomukInferenceRuleSetName)) + query, language);
195 it = d->model()->executeQuery(query, language, userQueryLanguage);
197 setError( d->model()->lastError() );
204 bool b = d->model()->containsStatement( statement );
205 setError( d->model()->lastError() );
212 bool b = d->model()->containsAnyStatement( statement );
213 setError( d->model()->lastError() );
220 bool b = d->model()->isEmpty();
221 setError( d->model()->lastError() );
228 int c = d->model()->statementCount();
229 setError( d->model()->lastError() );
237 setError( d->model()->lastError() );
245 setError( d->model()->lastError() );
253 setError( d->model()->lastError() );
260 Soprano::Node n = d->model()->createBlankNode();
261 setError( d->model()->lastError() );
265 #include "nepomukmainmodel.moc"
Soprano::Node createBlankNode()
bool isValid() const
Check the connection to the Nepomuk server.
MainModel(QObject *parent=0)
Create a new main model.
bool containsAnyStatement(const Soprano::Statement &statement) const
bool init()
Try connecting to the Nepomuk storage service.
bool containsStatement(const Soprano::Statement &statement) const
Soprano::Error::ErrorCode addStatement(const Soprano::Statement &statement)
int statementCount() const
Soprano::NodeIterator listContexts() const
Soprano::StatementIterator listStatements(const Soprano::Statement &partial) const
void disconnect()
This function explicitly marks the connection to soprano as disconnected.
Soprano::Error::ErrorCode removeStatement(const Soprano::Statement &statement)
Soprano::QueryResultIterator executeQuery(const QString &query, Soprano::Query::QueryLanguage language, const QString &userQueryLanguage=QString()) const
Soprano::Error::ErrorCode removeAllStatements(const Soprano::Statement &statement)