File nepomuk-1.diff of Package kdelibs4

diff -urB kdelibs4/nepomuk/core/resourcedata.cpp new/nepomuk/core/resourcedata.cpp
--- kdelibs4/nepomuk/core/resourcedata.cpp	2010-12-08 23:18:05.625679000 +0100
+++ new/nepomuk/core/resourcedata.cpp	2011-01-11 22:42:01.293000048 +0100
@@ -371,8 +371,12 @@
         m_cache.clear();
 
         if ( m_uri.isValid() ) {
+            //
+            // We exclude properties that are part of the inference graph
+            // It would only pollute the user interface
+            //
             Soprano::QueryResultIterator it = MAINMODEL->executeQuery(QString("select distinct ?p ?o where { "
-                                                                              "%1 ?p ?o . "
+                                                                              "graph ?g { %1 ?p ?o . } . FILTER(?g!=<urn:crappyinference2:inferredtriples>) . "
                                                                               "}").arg(Soprano::Node::resourceToN3(m_uri)),
                                                                       Soprano::Query::QueryLanguageSparql);
             while ( it.next() ) {
diff -urB kdelibs4/nepomuk/query/query.cpp new/nepomuk/query/query.cpp
--- kdelibs4/nepomuk/query/query.cpp	2011-01-07 23:41:02.340194000 +0100
+++ new/nepomuk/query/query.cpp	2011-01-11 22:42:01.293000048 +0100
@@ -70,43 +70,6 @@
 */
 
 
-namespace {
-    /**
-     * term is optimized and ran through prepareForSparql. The only type terms
-     * we are interested in are those that are non-optional.
-     */
-    bool containsResourceTypeTerm( const Nepomuk::Query::Term& term )
-    {
-        if( term.isResourceTypeTerm() ) {
-            return true;
-        }
-
-        // in an and-term a single resource type term is sufficient
-        else if( term.isAndTerm() ) {
-            Q_FOREACH( const Nepomuk::Query::Term& subTerm, term.toAndTerm().subTerms() ) {
-                if( containsResourceTypeTerm(subTerm) ) {
-                    return true;
-                }
-            }
-        }
-
-        // an or-term which only consists of resource type terms is valid also
-        else if( term.isOrTerm() ) {
-            Q_FOREACH( const Nepomuk::Query::Term& subTerm, term.toOrTerm().subTerms() ) {
-                if( !containsResourceTypeTerm(subTerm) ) {
-                    return false;
-                }
-            }
-            // at this point all subterms contain a non-optional resource type term
-            return true;
-        }
-
-        // fallback
-        return false;
-    }
-}
-
-
 QString Nepomuk::Query::QueryPrivate::createFolderFilter( const QString& resourceVarName, QueryBuilderData* qbd ) const
 {
     if ( m_includeFolders.count() + m_excludeFolders.count() ) {
@@ -394,8 +357,26 @@
     // optimize whatever we can
     term = term.optimized();
 
+
     // actually build the SPARQL query patterns
     QueryBuilderData qbd( d.constData(), sparqlFlags );
+
+
+    // We restrict results to user visible types only.
+    //
+    // Here we use an optimizations:
+    // The storage service creates "nao:userVisible 1" entries for all visible resources. This contains two optimizations:
+    // - We use an integer instead of a boolean because Virtuoso does not support booleans and, thus, Soprano converts
+    //   booleans into a fake type which is stored as a string. This makes comparision much slower.
+    // - Instead of using crappy inference via "?r a ?t . ?t nao:userVisible true" we can directly check the resources.
+    //
+    QString userVisibilityRestriction;
+    if( !(queryFlags()&NoResultRestrictions) ) {
+        userVisibilityRestriction = QString::fromLatin1("?r %1 1 . ")
+                .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::userVisible()));
+    }
+
+
     QString termGraphPattern;
     if( term.isValid() ) {
         termGraphPattern = term.d_ptr->toSparqlGraphPattern( QLatin1String( "?r" ), 0, &qbd );
@@ -415,18 +396,6 @@
             selectVariables << scoringExpression;
     }
 
-    // restrict to resources to user visible types only. There is no need to do that for file queries
-    // as those already restrict the type.
-    // Since we do the restriction on the type it gets useless as soon as the query contains a non-optional
-    // type term itself
-    QString userVisibilityRestriction;
-    if( !d->m_isFileQuery && !containsResourceTypeTerm(term) && !(queryFlags()&NoResultRestrictions) ) {
-        userVisibilityRestriction = QString::fromLatin1( "?r a %1 . %1 %2 %3 . " )
-                                    .arg( qbd.uniqueVarName(),
-                                          Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::userVisible()),
-                                          Soprano::Node::literalToN3(true) );
-    }
-
     // build the core of the query - the part that never changes
     QString queryBase = QString::fromLatin1( "where { %1 %2 %3 }" )
                         .arg( termGraphPattern,
diff -urB kdelibs4/nepomuk/query/resourcetypeterm.cpp new/nepomuk/query/resourcetypeterm.cpp
--- kdelibs4/nepomuk/query/resourcetypeterm.cpp	2011-01-07 23:41:02.340194000 +0100
+++ new/nepomuk/query/resourcetypeterm.cpp	2011-01-11 22:42:01.301000048 +0100
@@ -39,16 +39,14 @@
 }
 
 
-QString Nepomuk::Query::ResourceTypeTermPrivate::toSparqlGraphPattern( const QString& resName, const TermPrivate* parentTerm, QueryBuilderData* qbd ) const
+QString Nepomuk::Query::ResourceTypeTermPrivate::toSparqlGraphPattern( const QString& resName, const TermPrivate* parentTerm, QueryBuilderData* ) const
 {
     Q_UNUSED(parentTerm);
 
     // we are using the crappy inferencing provided by the nepomuk ontology service where
     // each class is also a subclass of itself.
-    return QString::fromLatin1("%1 a %2 . %2 %3 %4 . ")
+    return QString::fromLatin1("%1 a %2 . ")
         .arg( resName,
-              qbd->uniqueVarName(),
-              Soprano::Node::resourceToN3( Soprano::Vocabulary::RDFS::subClassOf() ),
               Soprano::Node::resourceToN3( m_class.uri() ) );
 }
 
diff -urB kdelibs4/nepomuk/test/querytest.cpp new/nepomuk/test/querytest.cpp
--- kdelibs4/nepomuk/test/querytest.cpp	2011-01-07 23:41:02.340194000 +0100
+++ new/nepomuk/test/querytest.cpp	2011-01-11 22:48:57.251000048 +0100
@@ -128,16 +128,13 @@
 
     QTest::newRow( "type query" )
         << Query( ResourceTypeTerm( Soprano::Vocabulary::NAO::Tag() ) )
-        << QString::fromLatin1("select distinct ?r where { ?r a ?v1 . ?v1 %1 %2 . }")
-        .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::RDFS::subClassOf()))
+	<< QString::fromLatin1("select distinct ?r where { ?r a %1 . }")
         .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::Tag()));
 
     QTest::newRow( "negated resource type" )
         << Query( NegationTerm::negateTerm( ResourceTypeTerm( Soprano::Vocabulary::NAO::Tag() ) ) )
-        << QString::fromLatin1("select distinct ?r where { ?r a ?v1 . FILTER(!bif:exists((select (1) where { ?r a ?v2 . ?v2 %1 %2 . }))) . }")
-        .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::RDFS::subClassOf()),
-             Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::Tag()),
-             Soprano::Node::resourceToN3(Soprano::Vocabulary::RDF::type()));
+	<< QString::fromLatin1("select distinct ?r where { ?r a ?v1 . FILTER(!bif:exists((select (1) where { ?r a %1 . }))) . }")
+	.arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::Tag()));
 
     QDateTime now = QDateTime::currentDateTime();
     QTest::newRow( "nie:lastModified" )
@@ -161,8 +158,7 @@
     QTest::newRow( "negated hastag with resource" )
         << Query( NegationTerm::negateTerm(ComparisonTerm( Soprano::Vocabulary::NAO::hasTag(), ResourceTerm( QUrl("nepomuk:/res/foobar") ) )))
         << QString::fromLatin1("select distinct ?r where { ?r a ?v1 . FILTER(!bif:exists((select (1) where { ?r %1 <nepomuk:/res/foobar> . }))) . }")
-        .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::hasTag()),
-             Soprano::Node::resourceToN3(Soprano::Vocabulary::RDF::type()));
+           .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::hasTag()));
 
     QTest::newRow( "comparators <" )
         << Query( ComparisonTerm( Soprano::Vocabulary::NAO::numericRating(), LiteralTerm(4), ComparisonTerm::Smaller ) )
@@ -215,9 +211,8 @@
     setVarNameTerm1.setVariableName("myvar");
     QTest::newRow( "set variable name 1" )
         << Query( setVarNameTerm1 )
-        << QString::fromLatin1("select distinct ?r ?myvar where { ?r %1 ?myvar . ?myvar a ?v1 . ?v1 %2 %3 . }")
+        << QString::fromLatin1("select distinct ?r ?myvar where { ?r %1 ?myvar . ?myvar a %2 . }")
         .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::hasTag()),
-             Soprano::Node::resourceToN3(Soprano::Vocabulary::RDFS::subClassOf()),
              Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::Tag()));
 
     ComparisonTerm setVarNameTerm2( Soprano::Vocabulary::NAO::hasTag(), LiteralTerm( "nepomuk" ) );
@@ -386,12 +381,11 @@
 
     mainTerm.addSubTerm(ct.inverted());
 
-    QString sparql = QString::fromLatin1("select distinct ?r count(?v5) as ?cnt where { { "
-                                         "{ ?r a ?v1 . ?v1 %1 %2 . } UNION { ?r a ?v2 . ?v2 %1 %3 . } . "
-                                         "FILTER(!bif:exists((select (1) where { <nepomuk:/res/foobar> ?v3 ?r . }))) . "
-                                         "?v5 ?v4 ?r . } . } ORDER BY DESC ( ?cnt )")
-                     .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::RDFS::subClassOf()),
-                          Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NFO::RasterImage()),
+    QString sparql = QString::fromLatin1("select distinct ?r count(?v3) as ?cnt where { { "
+                                         "{ ?r a %1 . } UNION { ?r a %2 . } . "
+                                         "FILTER(!bif:exists((select (1) where { <nepomuk:/res/foobar> ?v1 ?r . }))) . "
+                                         "?v3 ?v2 ?r . } . } ORDER BY DESC ( ?cnt )")
+                     .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NFO::RasterImage()),
                           Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NFO::Audio()));
 
     QTest::newRow( "a complex one" )
Only in new/nepomuk/test: querytest.cpp.orig
openSUSE Build Service is sponsored by