[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [nepomuk-core/feature/virtuosoInference] services/storage: Remove the CrappyInferencer2.
From: Sebastian Trueg <trueg () kde ! org>
Date: 2012-03-31 19:00:30
Message-ID: 20120331190030.E107CA60C4 () git ! kde ! org
[Download RAW message or body]
Git commit 069e65ad38323610be6c9ce7cbe5fe3c592b4d5f by Sebastian Trueg.
Committed on 31/03/2012 at 20:57.
Pushed by trueg into branch 'feature/virtuosoInference'.
Remove the CrappyInferencer2.
Now that we will use Virtuoso's own inference engine there is no need
for the bloat anymore.
M +0 -1 services/storage/CMakeLists.txt
D +0 -622 services/storage/crappyinferencer2.cpp
D +0 -102 services/storage/crappyinferencer2.h
M +2 -13 services/storage/repository.cpp
M +0 -7 services/storage/repository.h
M +0 -10 services/storage/test/CMakeLists.txt
D +0 -317 services/storage/test/crappyinferencer2test.cpp
D +0 -61 services/storage/test/crappyinferencer2test.h
http://commits.kde.org/nepomuk-core/069e65ad38323610be6c9ce7cbe5fe3c592b4d5f
diff --git a/services/storage/CMakeLists.txt b/services/storage/CMakeLists.txt
index 9d52fc5..e02f25e 100644
--- a/services/storage/CMakeLists.txt
+++ b/services/storage/CMakeLists.txt
@@ -16,7 +16,6 @@ set(storage_SRCS
ontologymanagermodel.cpp
graphretriever.cpp
crappyinferencer.cpp
- crappyinferencer2.cpp
removablemediamodel.cpp
datamanagementmodel.cpp
datamanagementadaptor.cpp
diff --git a/services/storage/crappyinferencer2.cpp \
b/services/storage/crappyinferencer2.cpp deleted file mode 100644
index eedd4f9..0000000
--- a/services/storage/crappyinferencer2.cpp
+++ /dev/null
@@ -1,622 +0,0 @@
-/*
- This file is part of the Nepomuk KDE project.
- Copyright (C) 2010-2011 Sebastian Trueg <trueg@kde.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) version 3, or any
- later version accepted by the membership of KDE e.V. (or its
- successor approved by the membership of KDE e.V.), which shall
- act as a proxy defined in Section 6 of version 3 of the license.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "crappyinferencer2.h"
-#include "classandpropertytree.h"
-
-#include <Soprano/Vocabulary/NRL>
-#include <Soprano/Vocabulary/NAO>
-#include <Soprano/Vocabulary/RDF>
-#include <Soprano/Vocabulary/RDFS>
-#include <Soprano/Statement>
-#include <Soprano/StatementIterator>
-#include <Soprano/Node>
-#include <Soprano/NodeIterator>
-#include <Soprano/Graph>
-#include <Soprano/QueryResultIterator>
-
-#include <QtCore/QTime>
-#include <QtCore/QMutex>
-#include <QtCore/QMutexLocker>
-#include <QtCore/QThread>
-
-#include <kdebug.h>
-
-
-class CrappyInferencer2::Private
-{
-public:
- Private()
- : m_updateAllResourcesThread(0) {
- }
-
- /// get the list of super types for \p type
- QSet<QUrl> superClasses( const QUrl& type ) const;
-
- /// Check if a resource with the specified types is visible.
- bool isVisibleFromTypes( const QSet<QUrl>& types ) const;
-
- /// Performs a query to retrieve all types that were not added by us
- QSet<QUrl> queryResourceTypes( const QUrl& resource ) const;
-
- /// used to build m_superClasses (and nothing else!)
- QSet<QUrl> buildSuperClassesHash( const QUrl& type, QSet<QUrl>& visitedTypes, \
const QMultiHash<QUrl, QUrl>& rdfsSubClassRelations );
-
- QHash<QUrl, QSet<QUrl> > m_superClasses;
- Nepomuk::ClassAndPropertyTree* m_typeVisibilityTree;
- QMutex m_mutex;
-
- UpdateAllResourcesThread* m_updateAllResourcesThread;
-
- QUrl m_inferenceContext;
-
- CrappyInferencer2* q;
-};
-
-
-/**
- * Simple helper thread which updates the subclass and visibility inference on all \
resources
- * in the database. This is done in a separate thread since it takes up to half an \
hour the first time.
- */
-class CrappyInferencer2::UpdateAllResourcesThread : public QThread
-{
-public:
- UpdateAllResourcesThread( CrappyInferencer2* parent )
- : QThread(parent),
- m_canceled(false),
- m_model(parent) {
- }
-
- void cancel() {
- kDebug();
- m_canceled = true;
- }
-
- void run() {
- kDebug();
- m_canceled = false;
-#ifndef NDEBUG
- QTime timer;
- timer.start();
-#endif
-
- // Update visibility for all visible resources the fast way
- // resources that do not have visibility set are treated as invisible, thus \
there is no need
- // to write their visibility value
- Q_FOREACH(const QUrl& type, \
m_model->d->m_typeVisibilityTree->visibleTypes()) {
- if(m_canceled)
- break;
- if(m_model->d->m_typeVisibilityTree->isChildOf(type, \
Soprano::Vocabulary::NRL::Graph()))
- continue;
- const QString query = QString::fromLatin1("insert into graph %1 { ?r %2 \
1 . } where { "
- "graph ?g { ?r a %3 . } . "
- "FILTER(?g!=%1) . "
- "FILTER(!bif:exists((select \
(1) where { ?r %2 ?v . }))) . } ")
- .arg( Soprano::Node::resourceToN3( \
m_model->crappyInferenceContext() ),
- Soprano::Node::resourceToN3( \
Soprano::Vocabulary::NAO::userVisible() ),
- Soprano::Node::resourceToN3( type ) );
- m_model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
- }
-
-#ifndef NDEBUG
- kDebug() << "All resources with visible type updated. Elapsed:" << \
timer.elapsed()/1000.0 << "sec";
-#endif
-
- // update the resource type inference on all resources that were created \
before KDE 4.6.1
- // we ignore graphs entirely to save space and allow the DMS to use SPARUL \
to remove graphs
- Soprano::QueryResultIterator it = \
m_model->executeQuery(QString::fromLatin1("select distinct ?t where { \
?t a %1 . "
- \
"FILTER(bif:exists((select (1) where { graph ?g { ?r a ?t . } . FILTER(?g!=%2) . }))) \
. "
- \
"FILTER(!bif:exists((select (1) where { ?t %3 %4 . }))) . }")
- \
.arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::RDFS::Class()),
- \
Soprano::Node::resourceToN3(m_model->crappyInferenceContext()),
- \
Soprano::Node::resourceToN3(Soprano::Vocabulary::RDFS::subClassOf()),
- \
Soprano::Node::resourceToN3(Soprano::Vocabulary::NRL::Graph())),
- \
Soprano::Query::QueryLanguageSparql);
- while(!m_canceled && it.next()) {
- const QUrl type = it["t"].uri();
- const QSet<QUrl> superClasses = m_model->d->m_superClasses[type];
- QString superTypeTerms;
- Q_FOREACH(const QUrl& superType, superClasses) {
- superTypeTerms += QString::fromLatin1("?r a %1 . \
").arg(Soprano::Node::resourceToN3(superType));
- }
-
- // we cannot restrict to resources that already have types in the crappy \
inferencer 2 graph
- // since one resource could have more than one type and thus, needs to \
be updated with more
- // than one query here.
- const QString query = QString::fromLatin1("insert into graph %1 { %2 } \
where { "
- "graph ?g { ?r a %3 . } . \
FILTER(?g!=%1) . }")
- .arg(Soprano::Node::resourceToN3( \
m_model->crappyInferenceContext()),
- superTypeTerms,
- Soprano::Node::resourceToN3(type));
- m_model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
- }
-
-#ifndef NDEBUG
- kDebug() << "All resources' subClassOf inference updated. Elapsed:" << \
timer.elapsed()/1000.0 << "sec";
-#endif
- }
-
-private:
- bool m_canceled;
- CrappyInferencer2* m_model;
-};
-
-
-
-QSet<QUrl> CrappyInferencer2::Private::superClasses( const QUrl& type ) const
-{
- QHash<QUrl, QSet<QUrl> >::const_iterator it = m_superClasses.constFind(type);
- if( it != m_superClasses.constEnd() ) {
- return it.value();
- }
- else {
- return QSet<QUrl>() << Soprano::Vocabulary::RDFS::Resource();
- }
-}
-
-bool CrappyInferencer2::Private::isVisibleFromTypes(const QSet<QUrl> &types) const
-{
- // We need to extract the leaf types in the subgraph that is types
- // as those are the types that define if the resource will be visible
-
- // TODO: do the following in an efficient way
- // we remove all supertypes from the set of types and are left with the leaf \
types
- QSet<QUrl> leafTypes(types);
- Q_FOREACH(const QUrl& type, types) {
- leafTypes -= superClasses(type);
- if(leafTypes.isEmpty())
- break;
- }
-
- // if there is one leaf type left that is visible the resource is visible, too
- Q_FOREACH( const QUrl& type, leafTypes ) {
- if( m_typeVisibilityTree->isUserVisible(type) ) {
- return true;
- }
- }
-
- // no visible type found
- return false;
-}
-
-QSet<QUrl> CrappyInferencer2::Private::queryResourceTypes(const QUrl &resource) \
const
-{
- QSet<QUrl> resourceTypes;
- Soprano::QueryResultIterator it
- = q->parentModel()->executeQuery( QString::fromLatin1("select ?t where { \
graph ?g { %1 a ?t . } . FILTER(?g!=%2) . }")
- \
.arg(Soprano::Node::resourceToN3(resource),
- \
Soprano::Node::resourceToN3(m_inferenceContext)),
- Soprano::Query::QueryLanguageSparql);
- while(it.next()) {
- resourceTypes << it[0].uri();
- }
-
- return resourceTypes;
-}
-
-QSet<QUrl> CrappyInferencer2::Private::buildSuperClassesHash( const QUrl& type, \
QSet<QUrl>& visitedTypes, const QMultiHash<QUrl, QUrl>& rdfsSubClassRelations = \
QMultiHash<QUrl, QUrl>() )
-{
- QHash<QUrl, QSet<QUrl> >::const_iterator it = m_superClasses.constFind(type);
- if( it == m_superClasses.constEnd() ) {
- QSet<QUrl> superTypes;
- for(QMultiHash<QUrl, QUrl>::const_iterator it = \
rdfsSubClassRelations.constFind(type);
- it != rdfsSubClassRelations.constEnd() && it.key() == type; ++it) {
- // avoid endless loops in case we have circular hierarchies
- if( !visitedTypes.contains( it.value() ) ) {
- visitedTypes << it.value();
- superTypes << it.value();
- superTypes += buildSuperClassesHash( it.value(), visitedTypes, \
rdfsSubClassRelations );
- }
- }
- m_superClasses.insert( type, superTypes );
- return superTypes;
- }
- else {
- return it.value();
- }
-}
-
-CrappyInferencer2::CrappyInferencer2(Nepomuk::ClassAndPropertyTree* tree, \
Soprano::Model* parent)
- : Soprano::FilterModel(parent),
- d(new Private())
-{
- d->q = this;
- d->m_inferenceContext = \
QUrl::fromEncoded("urn:crappyinference2:inferredtriples");
- d->m_typeVisibilityTree = tree;
- if ( parent )
- updateInferenceIndex();
-}
-
-CrappyInferencer2::~CrappyInferencer2()
-{
- if( d->m_updateAllResourcesThread ) {
- d->m_updateAllResourcesThread->cancel();
- d->m_updateAllResourcesThread->wait();
- }
- delete d;
-}
-
-void CrappyInferencer2::setParentModel(Soprano::Model *model)
-{
- FilterModel::setParentModel( model );
- updateInferenceIndex();
-}
-
-Soprano::Error::ErrorCode CrappyInferencer2::addStatement(const Soprano::Statement \
&statement)
-{
- if( statement.context() == d->m_inferenceContext ) {
-#ifdef NDEBUG
- kDebug() << "No actions are allowed on the crappy inferencer context in \
release mode!" << statement;
- return Soprano::Error::ErrorInvalidArgument;
-#else
- kWarning() << "WARNING!!!!!!!!!!! Adding statement in crappy inferencer \
context!!!!!!!!!!!!" << statement;
-#endif
- }
-
- QMutexLocker lock( &d->m_mutex );
-
- Soprano::Error::ErrorCode r = parentModel()->addStatement( statement );
- if( r == Soprano::Error::ErrorNone ) {
- //
- // Handle the inference. However, we ignore inference for all graphs to save \
space and allow the DMS to use SPARUL there.
- //
- if ( statement.subject().isResource() &&
- statement.object().isResource() &&
- statement.predicate() == Soprano::Vocabulary::RDF::type() &&
- !d->m_typeVisibilityTree->isChildOf(statement.object().uri(), \
Soprano::Vocabulary::NRL::Graph())) {
- addInferenceStatements( statement.subject().uri(), \
statement.object().uri() );
- }
- }
-
- return r;
-}
-
-Soprano::Error::ErrorCode CrappyInferencer2::removeStatement(const \
Soprano::Statement &statement)
-{
- if( statement.context() == d->m_inferenceContext ) {
-#ifdef NDEBUG
- kDebug() << "No actions are allowed on the crappy inferencer context in \
release mode!" << statement;
- return Soprano::Error::ErrorInvalidArgument;
-#else
- kWarning() << "WARNING!!!!!!!!!!! Removing statement from crappy inferencer \
context!!!!!!!!!!!!" << statement;
-#endif
- }
-
- QMutexLocker lock( &d->m_mutex );
-
- Soprano::Error::ErrorCode error = parentModel()->removeStatement(statement);
- if( error == Soprano::Error::ErrorNone ) {
- if ( statement.isValid() &&
- statement.subject().isResource() &&
- statement.object().isResource() &&
- statement.predicate() == Soprano::Vocabulary::RDF::type() ) {
- removeInferenceStatements( statement.subject().uri(), \
statement.object().uri() );
- }
- return Soprano::Error::ErrorNone;
- }
- else {
- return error;
- }
-}
-
-Soprano::Error::ErrorCode CrappyInferencer2::removeAllStatements(const \
Soprano::Statement &statement)
-{
- if( statement.context() == d->m_inferenceContext ) {
-#ifdef NDEBUG
- kDebug() << "No actions are allowed on the crappy inferencer context in \
release mode!" << statement;
- return Soprano::Error::ErrorInvalidArgument;
-#else
- kWarning() << "WARNING!!!!!!!!!!! Removing statements from crappy inferencer \
context!!!!!!!!!!!!" << statement;
-#endif
- }
-
- QMutexLocker lock( &d->m_mutex );
-
- //
- // The following conditions need to be met in order for us to need to check for \
types
- // 1. Object or context need to be valid. Otherwise our types are removed anyway
- // 2. Object needs to be empty or a resource. Literals are never types
- // 3. Predicate needs to be empty or rdf:type. Otherwise the call is not related \
to types.
- //
- if ( statement.context() != d->m_inferenceContext &&
- ( ( statement.predicate().isEmpty() ||
- statement.predicate() == Soprano::Vocabulary::RDF::type() ) &&
- ( statement.object().isEmpty() ||
- statement.object().isResource() ) &&
- ( statement.object().isValid() ||
- statement.context().isValid() ) ) ) {
- //
- // If both resource and type are defined we can simply call \
removeInferenceStatements() on them
- //
- if( statement.subject().isResource() &&
- statement.object().isResource() ) {
- const Soprano::Error::ErrorCode error = \
parentModel()->removeAllStatements(statement);
- if( error == Soprano::Error::ErrorNone ) {
- removeInferenceStatements( statement.subject().uri(), \
statement.object().uri() );
- }
- return error;
- }
-
- //
- // if only the type is undefined we get the types and then call \
removeInferenceStatements(). This avoids
- // performing the query in the latter method over and over for each type
- //
- else if( statement.subject().isValid() ) {
- //
- // we need to first get the types to remove, then remove the statements, \
and only then call
- // removeInferenceStatements(). This is since the latter makes use of \
the types in the model
- //
- QString query;
- if( statement.context().isValid() ) {
- query = QString::fromLatin1("select ?t where { graph %2 { %1 a ?t . \
} . }")
- .arg(statement.subject().toN3(),
- statement.context().toN3());
- }
- else {
- query = QString::fromLatin1("select ?t where { graph ?g { %1 a ?t . \
} . FILTER(?g!=%2) . }")
- .arg(statement.subject().toN3(),
- Soprano::Node::resourceToN3(crappyInferenceContext()));
- }
- const QList<Soprano::Node> types = executeQuery( query, \
Soprano::Query::QueryLanguageSparql ).iterateBindings(0).allNodes();
- const Soprano::Error::ErrorCode error = \
parentModel()->removeAllStatements(statement);
- if( error == Soprano::Error::ErrorNone ) {
- removeInferenceStatements( statement.subject().uri(), types );
- }
- return error;
- }
-
- //
- // If the subject is not defined but the type is we need to update several \
resources. There is no way around
- // calling removeInferenceStatements() for each resource.
- //
- else if( statement.object().isValid() ) {
- //
- // We need to get the resources before actually removing the statements \
since otherwise we might miss them
- //
- QString query;
- if( statement.context().isValid() ) {
- query = QString::fromLatin1("select ?r where { graph %2 { ?r a %1 . \
} . }")
- .arg(statement.object().toN3(),
- statement.context().toN3());
- }
- else {
- query = QString::fromLatin1("select ?r where { graph ?g { ?r a %1 . \
} . FILTER(?g!=%2) . }")
- .arg(statement.object().toN3(),
- Soprano::Node::resourceToN3(crappyInferenceContext()));
- }
- const QList<Soprano::Node> resources = executeQuery( query, \
Soprano::Query::QueryLanguageSparql ).iterateBindings(0).allNodes();
- const Soprano::Error::ErrorCode error = \
parentModel()->removeAllStatements(statement);
- if( error == Soprano::Error::ErrorNone ) {
- Q_FOREACH( const Soprano::Node& res, resources ) {
- removeInferenceStatements( res.uri(), statement.object().uri() \
);
- }
- }
- return error;
- }
-
- //
- // Neither subject nor object are defined
- //
- else {
- QHash<QUrl, QList<QUrl> > resTypeHash;
- QString query;
- if( statement.context().isValid() ) {
- query = QString::fromLatin1("select distinct ?r ?t where { graph %1 \
{ ?r a ?t . } . }")
- .arg(statement.context().toN3());
- }
- else {
- query = QString::fromLatin1("select distinct ?r ?t where { graph ?g \
{ ?r a ?t . } . FILTER(?g!=%1) . }")
- .arg(Soprano::Node::resourceToN3(crappyInferenceContext()));
- }
- Soprano::QueryResultIterator it = parentModel()->executeQuery( query, \
Soprano::Query::QueryLanguageSparql );
- while( it.next() ) {
- resTypeHash[it["r"].uri()].append( it["t"].uri() );
- }
- const Soprano::Error::ErrorCode error = \
parentModel()->removeAllStatements(statement);
- if( error == Soprano::Error::ErrorNone ) {
- QHash<QUrl, QList<QUrl> >::const_iterator end = \
resTypeHash.constEnd();
- for( QHash<QUrl, QList<QUrl> >::const_iterator it = \
resTypeHash.constBegin(); it != end; ++it ) {
- removeInferenceStatements( it.key(), it.value() );
- }
- }
- return error;
- }
- }
- else {
- return parentModel()->removeAllStatements(statement);
- }
-}
-
-QUrl CrappyInferencer2::crappyInferenceContext() const
-{
- return d->m_inferenceContext;
-}
-
-void CrappyInferencer2::updateInferenceIndex()
-{
- kDebug();
-
- QMutexLocker lock( &d->m_mutex );
-
- // we only create ontology statements - we need to mark the graph as such
- parentModel()->addStatement(d->m_inferenceContext, \
Soprano::Vocabulary::RDF::type(), Soprano::Vocabulary::NRL::Ontology(), \
d->m_inferenceContext);
-
-
- // Build superclasses hash
- // ==============================================
-
- // clear cache
- d->m_superClasses.clear();
-
- // cache subClassOf relations (only the original ones)
- QMultiHash<QUrl, QUrl> rdfsSubClassRelations;
- Soprano::QueryResultIterator it = executeQuery( QString::fromLatin1("select ?x \
?y where { graph ?g { ?x %1 ?y . } . "
- "FILTER(?g \
!= <urn:crappyinference:inferredtriples>) . "
- \
"FILTER(?x!=?y) . }" )
- .arg( \
Soprano::Node::resourceToN3( Soprano::Vocabulary::RDFS::subClassOf() \
) ),
- \
Soprano::Query::QueryLanguageSparql );
- while ( it.next() ) {
- rdfsSubClassRelations.insert( it["x"].uri(), it["y"].uri() );
- }
-
- // complete the map of super classes
- Q_FOREACH( const QUrl& type, rdfsSubClassRelations.keys() ) {
- QSet<QUrl> visitedClasses;
- d->buildSuperClassesHash( type, visitedClasses, rdfsSubClassRelations );
- }
-
- // get the classes that do not have any parent class
- it = executeQuery( QString::fromLatin1("select ?c where { ?c a %1 . OPTIONAL { \
?c %2 ?p . } . FILTER(!BOUND(?p)) . }" )
- .arg( Soprano::Node::resourceToN3( \
Soprano::Vocabulary::RDFS::Class() ) )
- .arg( Soprano::Node::resourceToN3( \
Soprano::Vocabulary::RDFS::subClassOf() ) ),
- Soprano::Query::QueryLanguageSparql );
- while ( it.next() ) {
- d->m_superClasses.insert( it["c"].uri(), QSet<QUrl>() );
- }
-
- // add rdfs:Resource as parent for all classes
- QMutableHashIterator<QUrl, QSet<QUrl> > rdfsResIt( d->m_superClasses );
- while( rdfsResIt.hasNext() ) {
- rdfsResIt.next();
- rdfsResIt.value().insert(Soprano::Vocabulary::RDFS::Resource());
- }
-
-#ifndef NDEBUG
- // count for debugging
- int cnt = 0;
- for( QHash<QUrl, QSet<QUrl> >::const_iterator it = \
d->m_superClasses.constBegin();
- it != d->m_superClasses.constEnd(); ++it ) {
- //kDebug() << it.key() << "->" << it.value();
- cnt += it.value().count();
- }
- kDebug() << "Number of classes: " << d->m_superClasses.count();
- kDebug() << "Number of subclass relations:" << cnt;
-#endif
-}
-
-void CrappyInferencer2::updateAllResources()
-{
- kDebug();
- if( !d->m_updateAllResourcesThread ) {
- d->m_updateAllResourcesThread = new UpdateAllResourcesThread(this);
- connect(d->m_updateAllResourcesThread, SIGNAL(finished()), this, \
SIGNAL(allResourcesUpdated()));
- }
- d->m_updateAllResourcesThread->start();
-}
-
-void CrappyInferencer2::addInferenceStatements( const QUrl& resource, const QUrl& \
type )
-{
- return addInferenceStatements( resource, QSet<QUrl>() << type );
-}
-
-void CrappyInferencer2::addInferenceStatements( const QUrl& resource, const \
QSet<QUrl>& types )
-{
- // add missing types
- bool haveVisibleType = false;
- QSet<QUrl> superTypes;
- Q_FOREACH( const QUrl& type, types ) {
- superTypes += d->superClasses(type);
- if( !haveVisibleType && d->m_typeVisibilityTree->isUserVisible(type) )
- haveVisibleType = true;
- }
- QSet<QUrl>::const_iterator end = superTypes.constEnd();
- for( QSet<QUrl>::const_iterator typeIt = superTypes.constBegin(); typeIt != end; \
++typeIt ) {
- parentModel()->addStatement(resource,
- Soprano::Vocabulary::RDF::type(),
- *typeIt,
- crappyInferenceContext());
- }
-
- // the visibility can only change if we add a visible type
- if( haveVisibleType ) {
- setVisibility( resource, true );
- }
-}
-
-void CrappyInferencer2::removeInferenceStatements(const QUrl &resource, const QUrl \
&type)
-{
- removeInferenceStatements( resource, QList<QUrl>() << type );
-}
-
-void CrappyInferencer2::removeInferenceStatements( const QUrl& resource, const \
QList<Soprano::Node>& types )
-{
- QList<QUrl> uris;
- Q_FOREACH( const Soprano::Node& node, types )
- uris << node.uri();
- removeInferenceStatements( resource, uris );
-}
-
-// Always called *after* removing the actual statements
-void CrappyInferencer2::removeInferenceStatements(const QUrl &resource, const \
QList<QUrl> &types)
-{
- // we cannot simply remove all super types since the resource might still have \
types that are somewhere in that hierarchy
-
- // determine the types that should be in the database now
- const QSet<QUrl> correctTypes = d->queryResourceTypes(resource);
- QSet<QUrl> correctSuperTypes;
- Q_FOREACH( const QUrl& type, correctTypes ) {
- correctSuperTypes += d->superClasses(type);
- }
-
- // now compare that list with the ones that we could remove
- QSet<QUrl> typesToRemove;
- Q_FOREACH( const QUrl& type, QSet<QUrl>::fromList(types) )
- typesToRemove += d->superClasses(type);
- typesToRemove -= correctSuperTypes;
-
- bool haveVisibleType = false;
- Q_FOREACH( const QUrl& typeToRemove, typesToRemove ) {
- if( !haveVisibleType && d->m_typeVisibilityTree->isUserVisible(typeToRemove) \
)
- haveVisibleType = true;
- parentModel()->removeStatement(resource,
- Soprano::Vocabulary::RDF::type(),
- typeToRemove,
- crappyInferenceContext());
- }
-
- // remove the visibility if necessary
- // only be removing visible types we can change the actual visibility
- if( haveVisibleType ) {
- setVisibility( resource, !correctTypes.isEmpty() && \
d->isVisibleFromTypes(correctTypes) );
- }
-}
-
-void CrappyInferencer2::setVisibility(const QUrl &resource, bool visible)
-{
- // we use an integer instead of a boolean for performance reasons: virtuoso does \
not support bool and Soprano converts them to strings
- if( visible ) {
- // we only set the visibility if it is not set yet
- executeQuery(QString::fromLatin1("insert into graph %1 { %2 %3 1 . } where { \
FILTER(!bif:exists((select (1) where { %2 %3 ?v . }))) }")
- .arg( Soprano::Node::resourceToN3( crappyInferenceContext() ),
- Soprano::Node::resourceToN3( resource ),
- Soprano::Node::resourceToN3( \
Soprano::Vocabulary::NAO::userVisible() ) ),
- Soprano::Query::QueryLanguageSparql);
- }
- else {
- // we only remove the visibility value we created ourselves
- parentModel()->removeAllStatements(resource,
- Soprano::Vocabulary::NAO::userVisible(),
- Soprano::Node(),
- crappyInferenceContext());
- }
-}
-
-#include "crappyinferencer2.moc"
diff --git a/services/storage/crappyinferencer2.h \
b/services/storage/crappyinferencer2.h deleted file mode 100644
index 37c3598..0000000
--- a/services/storage/crappyinferencer2.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- This file is part of the Nepomuk KDE project.
- Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) version 3, or any
- later version accepted by the membership of KDE e.V. (or its
- successor approved by the membership of KDE e.V.), which shall
- act as a proxy defined in Section 6 of version 3 of the license.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef CRAPPYINFERENCER2_H
-#define CRAPPYINFERENCER2_H
-
-#include <Soprano/FilterModel>
-
-namespace Nepomuk {
-class ClassAndPropertyTree;
-}
-
-/**
- * The second version of the crappy inferencer it even crappier than the first.
- * It only does rdf:type inferencing, nothing else. In the long run this is not
- * enough but for now it is the only kind of inference we use in Nepomuk.
- * Thus, it is enough and makes for much faster queries than the first
- * crappy inferencer.
- *
- * \author Sebastian Trueg <trueg@kde.org>
- */
-class CrappyInferencer2 : public Soprano::FilterModel
-{
- Q_OBJECT
-
-public:
- CrappyInferencer2(Nepomuk::ClassAndPropertyTree* tree, Soprano::Model* parent = \
0);
- ~CrappyInferencer2();
-
- /**
- * \reimpl to update internal structures
- */
- void setParentModel( Soprano::Model* model );
-
- Soprano::Error::ErrorCode addStatement( const Soprano::Statement& statement );
- Soprano::Error::ErrorCode removeStatement( const Soprano::Statement& statement \
);
- Soprano::Error::ErrorCode removeAllStatements( const Soprano::Statement& \
statement );
-
- using Soprano::FilterModel::addStatement;
- using Soprano::FilterModel::removeStatement;
- using Soprano::FilterModel::removeAllStatements;
-
- /**
- * All inferred triples are stored in the one crappy inference graph.
- * Thus, removing inference is as simple as removing this one graph.
- */
- QUrl crappyInferenceContext() const;
-
-Q_SIGNALS:
- /**
- * Emitted once a call to updateAllResources() has finished.
- */
- void allResourcesUpdated();
-
-public Q_SLOTS:
- /**
- * Update the internal map of super types that is used to determine which
- * type statements need to be added and removed. It makes sense to call this
- * when the ontologies in the model change.
- */
- void updateInferenceIndex();
-
- /**
- * Update all types of all resources in the model. This method will add \
supertype
- * statements but NOT remove any superfluous statements. To achieve the latter \
call
- * removeContext(crappyInferenceContext()) before calling this method.
- */
- void updateAllResources();
-
-private:
- void addInferenceStatements( const QUrl& resource, const QUrl& type );
- void addInferenceStatements( const QUrl& resource, const QSet<QUrl>& types );
- void removeInferenceStatements( const QUrl& resource, const QUrl& type );
- void removeInferenceStatements( const QUrl& resource, const QList<QUrl>& types \
);
- void removeInferenceStatements( const QUrl& resource, const \
QList<Soprano::Node>& types );
-
- void setVisibility(const QUrl& resource, bool visible);
-
- class UpdateAllResourcesThread;
- class Private;
- Private* const d;
-};
-
-#endif // CRAPPYINFERENCER2_H
diff --git a/services/storage/repository.cpp b/services/storage/repository.cpp
index 54825d5..0be4a12 100644
--- a/services/storage/repository.cpp
+++ b/services/storage/repository.cpp
@@ -14,7 +14,6 @@
#include "repository.h"
#include "modelcopyjob.h"
-#include "crappyinferencer2.h"
#include "removablemediamodel.h"
#include "datamanagementmodel.h"
#include "datamanagementadaptor.h"
@@ -64,7 +63,6 @@ Nepomuk::Repository::Repository( const QString& name )
m_state( CLOSED ),
m_model( 0 ),
m_classAndPropertyTree( 0 ),
- m_inferencer( 0 ),
m_removableStorageModel( 0 ),
m_dataManagementModel( 0 ),
m_dataManagementAdaptor( 0 ),
@@ -104,9 +102,6 @@ void Nepomuk::Repository::close()
delete m_classAndPropertyTree;
m_classAndPropertyTree = 0;
- delete m_inferencer;
- m_inferencer = 0;
-
delete m_removableStorageModel;
m_removableStorageModel = 0;
@@ -212,17 +207,13 @@ void Nepomuk::Repository::open()
connect(m_graphMaintainer, SIGNAL(finished()), m_graphMaintainer, \
SLOT(deleteLater())); m_graphMaintainer->start();
- // create the one class and property tree to be used in the crappy inferencer 2 \
and in DMS + // create the one class and property tree to be used in DMS
// =================================
m_classAndPropertyTree = new Nepomuk::ClassAndPropertyTree(this);
- // create the crappy inference model which handles rdfs:subClassOf only -> we \
only use this to improve performance of ResourceTypeTerms
- // =================================
- m_inferencer = new CrappyInferencer2( m_classAndPropertyTree, m_model );
-
// create the RemovableMediaModel which does the transparent handling of \
removable mounts // =================================
- m_removableStorageModel = new Nepomuk::RemovableMediaModel(m_inferencer);
+ m_removableStorageModel = new Nepomuk::RemovableMediaModel(m_model);
// create a SignalCacheModel to make sure no client slows us down by listening \
to the stupid signals // =================================
@@ -446,8 +437,6 @@ void Nepomuk::Repository::updateInference()
// update the rest
m_classAndPropertyTree->rebuildTree(this);
- m_inferencer->updateInferenceIndex();
- m_inferencer->updateAllResources();
//
// Remove the old crappy inference graph
diff --git a/services/storage/repository.h b/services/storage/repository.h
index d02c3d8..f3a2078 100644
--- a/services/storage/repository.h
+++ b/services/storage/repository.h
@@ -30,7 +30,6 @@ namespace Soprano {
}
class KJob;
-class CrappyInferencer2;
namespace Nepomuk {
class RemovableMediaModel;
@@ -57,11 +56,6 @@ namespace Nepomuk {
* \li RemovableMediaModel is used to automatically convert the URLs of files
* on USB keys, network shares, and so on from and into mount-point \
independant URLs
* like nfs://<HOST>/<HOST-PATH>/local/path.ext.
- * \li CrappyInferencer2 keeps rdfs:subClassOf and nao:userVisible inference \
up-to-date.
- *
- * On construction it checks for and optionally performs conversion from an old \
repository
- * type (pre-Virtuoso times) and runs CrappyInferencer2::updateAllResources() \
which is
- * performed in a separate thread.
*
* \author Sebastian Trueg <trueg@kde.org>
*/
@@ -115,7 +109,6 @@ namespace Nepomuk {
Soprano::Model* m_model;
Nepomuk::ClassAndPropertyTree* m_classAndPropertyTree;
- CrappyInferencer2* m_inferencer;
RemovableMediaModel* m_removableStorageModel;
DataManagementModel* m_dataManagementModel;
Nepomuk::DataManagementAdaptor* m_dataManagementAdaptor;
diff --git a/services/storage/test/CMakeLists.txt \
b/services/storage/test/CMakeLists.txt index 53c8f3a..34101b3 100644
--- a/services/storage/test/CMakeLists.txt
+++ b/services/storage/test/CMakeLists.txt
@@ -9,16 +9,6 @@ include_directories(
${libnepomukcore_BINARY_DIR}
)
-kde4_add_unit_test(crappyinferencer2test
- crappyinferencer2test.cpp
- ../crappyinferencer2.cpp
- ../classandpropertytree.cpp)
-target_link_libraries(crappyinferencer2test
- ${QT_QTTEST_LIBRARY}
- ${SOPRANO_LIBRARIES}
- ${KDE4_KDECORE_LIBS}
- nepomukcore)
-
kde4_add_unit_test(removablemediamodeltest
removablemediamodeltest.cpp
../removablemediamodel.cpp
diff --git a/services/storage/test/crappyinferencer2test.cpp \
b/services/storage/test/crappyinferencer2test.cpp deleted file mode 100644
index f70b767..0000000
--- a/services/storage/test/crappyinferencer2test.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- This file is part of the Nepomuk KDE project.
- Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) version 3, or any
- later version accepted by the membership of KDE e.V. (or its
- successor approved by the membership of KDE e.V.), which shall
- act as a proxy defined in Section 6 of version 3 of the license.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "crappyinferencer2test.h"
-#include "../crappyinferencer2.h"
-#include "../classandpropertytree.h"
-
-#include <QtTest>
-#include "qtest_kde.h"
-
-#include <Soprano/Soprano>
-
-#include <ktempdir.h>
-
-using namespace Soprano;
-
-Q_DECLARE_METATYPE(Soprano::Statement)
-
-void CrappyInferencer2Test::initTestCase()
-{
- qRegisterMetaType<Soprano::Statement>();
-
- // we need to use a Virtuoso model as tmp model since redland misses important \
SPARQL features
- // that are used by libnepomuk below
- const Soprano::Backend* backend = \
Soprano::PluginManager::instance()->discoverBackendByName( \
"virtuosobackend" );
- QVERIFY( backend );
- m_storageDir = new KTempDir();
- m_baseModel = backend->createModel( Soprano::BackendSettings() << \
Soprano::BackendSetting(Soprano::BackendOptionStorageDir, \
m_storageDir->name()) );
- QVERIFY( m_baseModel );
-
- m_typeTree = new Nepomuk::ClassAndPropertyTree( this );
- m_model = new CrappyInferencer2( m_typeTree, m_baseModel );
-}
-
-void CrappyInferencer2Test::cleanupTestCase()
-{
- delete m_model;
- delete m_baseModel;
- delete m_storageDir;
-}
-
-
-void CrappyInferencer2Test::init()
-{
- m_baseModel->removeAllStatements();
-
- //
- // we create one fake ontology
- //
- // A
- // |- B
- // |- C - invisible
- // |- D
- // |- E
- //
- // F
- // |- E
- //
- // L1
- // |- L2
- // |- L1
- //
- QUrl graph("graph:/onto");
- m_baseModel->addStatement( graph, Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::NRL::Ontology(), graph );
- m_baseModel->addStatement( QUrl("nepomuk:/G"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::NRL::InstanceBase(), graph );
-
- m_baseModel->addStatement( QUrl("onto:/A"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
- m_baseModel->addStatement( QUrl("onto:/B"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
- m_baseModel->addStatement( QUrl("onto:/C"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
- m_baseModel->addStatement( QUrl("onto:/D"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
- m_baseModel->addStatement( QUrl("onto:/E"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
- m_baseModel->addStatement( QUrl("onto:/F"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
-
- m_baseModel->addStatement( QUrl("onto:/E"), \
Soprano::Vocabulary::RDFS::subClassOf(), QUrl("onto:/C"), graph );
- m_baseModel->addStatement( QUrl("onto:/B"), \
Soprano::Vocabulary::RDFS::subClassOf(), QUrl("onto:/A"), graph );
- m_baseModel->addStatement( QUrl("onto:/C"), \
Soprano::Vocabulary::RDFS::subClassOf(), QUrl("onto:/B"), graph );
- m_baseModel->addStatement( QUrl("onto:/D"), \
Soprano::Vocabulary::RDFS::subClassOf(), QUrl("onto:/C"), graph );
- m_baseModel->addStatement( QUrl("onto:/E"), \
Soprano::Vocabulary::RDFS::subClassOf(), QUrl("onto:/F"), graph );
-
- m_model->addStatement( QUrl("onto:/C"), Soprano::Vocabulary::NAO::userVisible(), \
LiteralValue(false), graph );
-
- // the loopy classes
- m_baseModel->addStatement( QUrl("onto:/L1"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
- m_baseModel->addStatement( QUrl("onto:/L1"), \
Soprano::Vocabulary::RDFS::subClassOf(), QUrl("onto:/L2"), graph );
- m_baseModel->addStatement( QUrl("onto:/L2"), Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Class(), graph );
- m_baseModel->addStatement( QUrl("onto:/L2"), \
Soprano::Vocabulary::RDFS::subClassOf(), QUrl("onto:/L1"), graph );
-
- m_typeTree->rebuildTree(m_model);
- m_model->updateInferenceIndex();
-}
-
-// make sure only the one statement is added
-void CrappyInferencer2Test::testAddAnyStatement()
-{
- const int cnt = m_model->statementCount();
- Statement s( QUrl("nepomuk:/A"), Soprano::Vocabulary::NAO::hasTag(), \
QUrl("nepomuk:/T"), QUrl("nepomuk:/G") );
- QVERIFY(!m_model->addStatement(s));
- QCOMPARE(m_model->statementCount(), cnt+1);
- QVERIFY(m_model->containsStatement(s));
-}
-
-// make sure all superclasses are added as type, too
-void CrappyInferencer2Test::testAddTypeStatement()
-{
- int cnt = m_model->statementCount();
- QUrl resA("nepomuk:/A");
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/A"), \
QUrl("nepomuk:/G"));
- QCOMPARE(m_model->statementCount(), cnt+3);
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-
- cnt = m_model->statementCount();
- QUrl resB("nepomuk:/B");
- m_model->addStatement(resB, Soprano::Vocabulary::RDF::type(), QUrl("onto:/B"), \
QUrl("nepomuk:/G"));
- QCOMPARE(m_model->statementCount(), cnt+4);
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-
- cnt = m_model->statementCount();
- QUrl resC("nepomuk:/C");
- m_model->addStatement(resC, Soprano::Vocabulary::RDF::type(), QUrl("onto:/C"), \
QUrl("nepomuk:/G"));
- QCOMPARE(m_model->statementCount(), cnt+4);
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
QUrl("onto:/C")));
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
-
- cnt = m_model->statementCount();
- QUrl resD("nepomuk:/D");
- m_model->addStatement(resD, Soprano::Vocabulary::RDF::type(), QUrl("onto:/E"), \
QUrl("nepomuk:/G"));
- QCOMPARE(m_model->statementCount(), cnt+7);
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/F")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/E")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/C")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-}
-
-// make sure the new relation is taken into account with the next addStatement
-void CrappyInferencer2Test::testAddSubClassOfStatement()
-{
- QEXPECT_FAIL("", "Not implemented yet", Abort);
-}
-
-// make sure only the one statement is removed
-void CrappyInferencer2Test::testRemoveAnyStatement()
-{
-}
-
-// make sure the appropriate types are removed, too
-// check 2 cases: 1. only the one type, 2. two types with intersecting superclasses
-void CrappyInferencer2Test::testRemoveTypeStatement()
-{
- int cnt = m_model->statementCount();
- QUrl resA("nepomuk:/A");
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/A"), \
QUrl("nepomuk:/G"));
- m_model->removeStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/A"), QUrl("nepomuk:/G"));
- QCOMPARE(m_model->statementCount(), cnt);
- QVERIFY(!m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(!m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(!m_model->containsAnyStatement(resA, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-
- // add two types with intersecting super types
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/B"), \
QUrl("nepomuk:/G"));
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/E"), \
QUrl("nepomuk:/G"));
- // remove one of them
- m_model->removeStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/B"), QUrl("nepomuk:/G"));
- // make sure all is well
- QCOMPARE(m_model->statementCount(), cnt+7);
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/F")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/E")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/C")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-}
-
-// make sure the removed subclass relation is taken into account with the next \
addStatement
-// make sure type statements that are no longer valid are removed
-void CrappyInferencer2Test::testRemoveSubClassOfStatement()
-{
- QEXPECT_FAIL("", "Not implemented yet", Abort);
-}
-
-// make sure the corresponing statements are removed and nothing else
-// test all combinations of invalid and valid nodes if possible
-void CrappyInferencer2Test::testRemoveAllStatements()
-{
- // 1. remove the whole resource
- int cnt = m_model->statementCount();
- QUrl resA("nepomuk:/A");
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/A"), \
QUrl("nepomuk:/G"));
- m_model->addStatement(resA, Soprano::Vocabulary::RDFS::label(), \
LiteralValue(QLatin1String("A")), QUrl("nepomuk:/G"));
- m_model->removeAllStatements(resA, Node(), Node());
- QCOMPARE(m_model->statementCount(), cnt);
- QVERIFY(!m_model->containsAnyStatement(resA, Node(), Node(), Node()));
-
- // 2. remove a type from several resources
- QUrl resB("nepomuk:/B");
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/A"), \
QUrl("nepomuk:/G"));
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/F"), \
QUrl("nepomuk:/G"));
- m_model->addStatement(resB, Soprano::Vocabulary::RDF::type(), QUrl("onto:/B"), \
QUrl("nepomuk:/G"));
- m_model->addStatement(resB, Soprano::Vocabulary::RDF::type(), QUrl("onto:/F"), \
QUrl("nepomuk:/G"));
- m_model->removeAllStatements(Node(), Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/F"));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(!m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/F")));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(!m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
QUrl("onto:/F")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
- QCOMPARE(m_model->statementCount(), cnt+7);
-
- // 3. remove all types from one resource
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/E"), \
QUrl("nepomuk:/G"));
- m_model->removeAllStatements(resA, Soprano::Vocabulary::RDF::type(), Node(), \
QUrl("nepomuk:/G"));
- QVERIFY(!m_model->containsAnyStatement(resA, Soprano::Vocabulary::RDF::type(), \
Node()));
- QVERIFY(!m_model->containsAnyStatement(resA, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-
- // 4. remove a graph
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/E"), \
QUrl("nepomuk:/G"));
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/A"), \
QUrl("nepomuk:/G2"));
- m_model->removeContext(QUrl("nepomuk:/G"));
- QVERIFY(!m_model->containsAnyStatement(resB, Node(), Node()));
- QVERIFY(m_model->containsAnyStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(!m_model->containsAnyStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/E")));
- QVERIFY(!m_model->containsAnyStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/D")));
- QVERIFY(!m_model->containsAnyStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/C")));
- QVERIFY(!m_model->containsAnyStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resA, Soprano::Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(!m_model->containsContext(QUrl("nepomuk:/G")));
-}
-
-// make sure we do not run into an endless loop
-void CrappyInferencer2Test::testCyclicSubClassRelation()
-{
- int cnt = m_model->statementCount();
- QUrl resA("nepomuk:/A");
- m_model->addStatement(resA, Soprano::Vocabulary::RDF::type(), QUrl("onto:/L1"), \
QUrl("nepomuk:/G"));
- QCOMPARE(m_model->statementCount(), cnt+4); // +4 since L1 is there twice: the \
one we added and the superclass of L2
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/L1")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/L2")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
-}
-
-void CrappyInferencer2Test::testUpdateAllResources()
-{
- // we add a bunch of statements to the base model instead of going through the \
crappy inference model
- QUrl resA("nepomuk:/A");
- QUrl resB("nepomuk:/B");
- QUrl resC("nepomuk:/C");
- QUrl resD("nepomuk:/D");
-
- m_baseModel->addStatement(resA, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/A"), QUrl("nepomuk:/G"));
- m_baseModel->addStatement(resB, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/B"), QUrl("nepomuk:/G"));
- m_baseModel->addStatement(resC, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/C"), QUrl("nepomuk:/G"));
- m_baseModel->addStatement(resD, Soprano::Vocabulary::RDF::type(), \
QUrl("onto:/E"), QUrl("nepomuk:/G"));
-
- m_model->updateAllResources();
-
- // wait for the above call to finish
- QEventLoop loop;
- connect(m_model, SIGNAL(allResourcesUpdated()), &loop, SLOT(quit()));
- loop.exec();
-
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resA, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resB, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
QUrl("onto:/C")));
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resC, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(!m_model->containsAnyStatement(resC, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/F")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/E")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/C")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/B")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
QUrl("onto:/A")));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::RDF::type(), \
Soprano::Vocabulary::RDFS::Resource()));
- QVERIFY(m_model->containsAnyStatement(resD, Vocabulary::NAO::userVisible(), \
LiteralValue(1)));
-}
-
-QTEST_KDEMAIN_CORE(CrappyInferencer2Test)
-
-#include "crappyinferencer2test.moc"
diff --git a/services/storage/test/crappyinferencer2test.h \
b/services/storage/test/crappyinferencer2test.h deleted file mode 100644
index 1ad41dd..0000000
--- a/services/storage/test/crappyinferencer2test.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- This file is part of the Nepomuk KDE project.
- Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) version 3, or any
- later version accepted by the membership of KDE e.V. (or its
- successor approved by the membership of KDE e.V.), which shall
- act as a proxy defined in Section 6 of version 3 of the license.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef CRAPPYINFERENCER2TEST_H
-#define CRAPPYINFERENCER2TEST_H
-
-#include <QObject>
-
-class KTempDir;
-class CrappyInferencer2;
-namespace Soprano {
-class Model;
-}
-namespace Nepomuk {
-class ClassAndPropertyTree;
-}
-
-class CrappyInferencer2Test : public QObject
-{
- Q_OBJECT
-
-private Q_SLOTS:
- void initTestCase();
- void cleanupTestCase();
- void init();
- void testAddAnyStatement();
- void testAddTypeStatement();
- void testAddSubClassOfStatement();
- void testRemoveAnyStatement();
- void testRemoveTypeStatement();
- void testRemoveSubClassOfStatement();
- void testRemoveAllStatements();
- void testCyclicSubClassRelation();
- void testUpdateAllResources();
-
-private:
- KTempDir* m_storageDir;
- Soprano::Model* m_baseModel;
- Nepomuk::ClassAndPropertyTree* m_typeTree;
- CrappyInferencer2* m_model;
-};
-
-#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic