[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [nepomuk-core/feature/virtuosoInference] services/storage: Enable Virtuoso inference on all queries.
From:       Sebastian Trueg <trueg () kde ! org>
Date:       2012-03-31 19:00:30
Message-ID: 20120331190030.BC751A60BB () git ! kde ! org
[Download RAW message or body]

Git commit 7076acfd44d3b9f9709ade6663d03be4df5db6c4 by Sebastian Trueg.
Committed on 31/03/2012 at 20:54.
Pushed by trueg into branch 'feature/virtuosoInference'.

Enable Virtuoso inference on all queries.

Thanks to Virtuoso's graph groups it is fairly simple to enable
inference on all queries.

However, we need to allow clients to disable inference as there are
many situations in which inference just makes for weird results (think
property listings in the UI).
This will be a bit harder as it might require changes in Soprano.

M  +47   -0    services/storage/repository.cpp
M  +5    -0    services/storage/repository.h

http://commits.kde.org/nepomuk-core/7076acfd44d3b9f9709ade6663d03be4df5db6c4

diff --git a/services/storage/repository.cpp b/services/storage/repository.cpp
index 9fd4d82..54825d5 100644
--- a/services/storage/repository.cpp
+++ b/services/storage/repository.cpp
@@ -26,8 +26,11 @@
 #include <Soprano/Global>
 #include <Soprano/Version>
 #include <Soprano/StorageModel>
+#include <Soprano/QueryResultIterator>
+#include <Soprano/Node>
 #include <Soprano/Error/Error>
 #include <Soprano/Vocabulary/RDF>
+#include <Soprano/Vocabulary/NRL>
 #include <Soprano/Util/SignalCacheModel>
 #define USING_SOPRANO_NRLMODEL_UNSTABLE_API
 #include <Soprano/NRLModel>
@@ -380,6 +383,17 @@ QString Nepomuk::Repository::usedSopranoBackend() const
         return QString();
 }
 
+Soprano::QueryResultIterator Nepomuk::Repository::executeQuery(const QString &query, \
Soprano::Query::QueryLanguage language, const QString &userQueryLanguage) const +{
+    if(language == Soprano::Query::QueryLanguageSparql) {
+        // FIXME: some other model puts prefixes in front of this which results in \
invlide queries! +        return FilterModel::executeQuery(QLatin1String("DEFINE \
input:inference <nepomuk:/ontographgroup> ") + query, language); +    }
+    else {
+        return FilterModel::executeQuery(query, language, userQueryLanguage);
+    }
+}
+
 
 Soprano::BackendSettings Nepomuk::Repository::readVirtuosoSettings() const
 {
@@ -434,6 +448,39 @@ void Nepomuk::Repository::updateInference()
     m_classAndPropertyTree->rebuildTree(this);
     m_inferencer->updateInferenceIndex();
     m_inferencer->updateAllResources();
+
+    //
+    // Remove the old crappy inference graph
+    //
+    m_model->executeQuery(QLatin1String("clear graph \
<urn:crappyinference2:inferredtriples>"), +                          \
Soprano::Query::QueryLanguageSparql); +
+    //
+    // Update ontology graph group
+    //
+    Soprano::QueryResultIterator it
+            = m_model->executeQuery(QString::fromLatin1("select RGG_IID from \
DB.DBA.RDF_GRAPH_GROUP where RGG_IRI='nepomuk:/ontographgroup'"), +                   \
Soprano::Query::QueryLanguageUser, +                                    \
QLatin1String("sql")); +    if(!it.next()) {
+        m_model->executeQuery(QLatin1String("DB.DBA.RDF_GRAPH_GROUP_CREATE('nepomuk:/ontographgroup', \
1, null, 'The Nepomuk graph group which contains all nrl:Ontology graphs.')"), +      \
Soprano::Query::QueryLanguageUser, +                              \
QLatin1String("sql")); +    }
+
+    // fetch all nrl:Ontology graphs and add them to the group
+    it = m_model->executeQuery(QString::fromLatin1("select distinct ?r where { ?r a \
%1 . }").arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NRL::Ontology())), +    \
Soprano::Query::QueryLanguageSparql); +    while(it.next()) {
+        m_model->executeQuery(QString::fromLatin1("DB.DBA.RDF_GRAPH_GROUP_INS('nepomuk:/ontographgroup', \
'%1')").arg(it[0].uri().toString()), +                              \
Soprano::Query::QueryLanguageUser, +                              \
QLatin1String("sql")); +    }
+
+    // create the rdfs rule graph on the graph group
+    m_model->executeQuery(QLatin1String("rdfs_rule_set('nepomuk:/ontographgroup','nepomuk:/ontographgroup')"),
 +                          Soprano::Query::QueryLanguageUser,
+                          QLatin1String("sql"));
 }
 
 void Nepomuk::Repository::slotVirtuosoStopped(bool normalExit)
diff --git a/services/storage/repository.h b/services/storage/repository.h
index e1eecb2..d02c3d8 100644
--- a/services/storage/repository.h
+++ b/services/storage/repository.h
@@ -85,6 +85,11 @@ namespace Nepomuk {
 
         QString usedSopranoBackend() const;
 
+        /**
+         * Reimplemented to enable Virtuoso inference.
+         */
+        Soprano::QueryResultIterator executeQuery(const QString &query, \
Soprano::Query::QueryLanguage language, const QString &userQueryLanguage) const; +
     public Q_SLOTS:
         /**
          * Will emit the opened signal


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic