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

List:       kde-commits
Subject:    [nepomuk-core] services/storage: ResourceIdentifier: Minor Optimizations
From:       Vishesh Handa <me () vhanda ! in>
Date:       2012-10-25 12:11:49
Message-ID: 20121025121149.BF556A60E1 () git ! kde ! org
[Download RAW message or body]

Git commit bbc71f3a32d953f5a322090dfcf38188fb6dc400 by Vishesh Handa.
Committed on 22/10/2012 at 11:19.
Pushed by vhanda into branch 'master'.

ResourceIdentifier: Minor Optimizations

Use a QSet instead of comparing to each of the meta properties. Also
remove unused code - Sync::ResourceIdentifier::isIdentifyingProperty

M  +5    -4    services/storage/resourceidentifier.cpp
M  +1    -0    services/storage/resourceidentifier.h
M  +7    -29   services/storage/syncresourceidentifier.cpp
M  +1    -1    services/storage/syncresourceidentifier.h

http://commits.kde.org/nepomuk-core/bbc71f3a32d953f5a322090dfcf38188fb6dc400

diff --git a/services/storage/resourceidentifier.cpp \
b/services/storage/resourceidentifier.cpp index 1491b7e..957cc8c 100644
--- a/services/storage/resourceidentifier.cpp
+++ b/services/storage/resourceidentifier.cpp
@@ -56,6 +56,10 @@ Nepomuk2::ResourceIdentifier::ResourceIdentifier( \
Nepomuk2::StoreIdentificationM  : Nepomuk2::Sync::ResourceIdentifier( model ),
       m_mode( mode )
 {
+    m_metaProperties.insert( NAO::created() );
+    m_metaProperties.insert( NAO::lastModified() );
+    m_metaProperties.insert( NAO::userVisible() );
+    m_metaProperties.insert( NAO::creator() );
 }
 
 
@@ -93,10 +97,7 @@ KUrl Nepomuk2::ResourceIdentifier::duplicateMatch(const KUrl& \
origUri,  
 bool Nepomuk2::ResourceIdentifier::isIdentifyingProperty(const QUrl& uri)
 {
-    if( uri == NAO::created()
-            || uri == NAO::creator()
-            || uri == NAO::lastModified()
-            || uri == NAO::userVisible() ) {
+    if( m_metaProperties.contains( uri ) ) {
         return false;
     }
     else {
diff --git a/services/storage/resourceidentifier.h \
b/services/storage/resourceidentifier.h index 8fe17f2..1c6678f 100644
--- a/services/storage/resourceidentifier.h
+++ b/services/storage/resourceidentifier.h
@@ -44,6 +44,7 @@ private:
     bool exists( const KUrl& uri );
 
     Nepomuk2::StoreIdentificationMode m_mode;
+    QSet<QUrl> m_metaProperties;
 };
 
 }
diff --git a/services/storage/syncresourceidentifier.cpp \
b/services/storage/syncresourceidentifier.cpp index 11583af..4cc1c96 100644
--- a/services/storage/syncresourceidentifier.cpp
+++ b/services/storage/syncresourceidentifier.cpp
@@ -159,7 +159,7 @@ void Nepomuk2::Sync::ResourceIdentifier::identify(const \
KUrl::List& uriList)  
 bool Nepomuk2::Sync::ResourceIdentifier::runIdentification(const KUrl& uri)
 {
-    const Sync::SyncResource & res = simpleResource( uri );
+    Sync::SyncResource res = simpleResource( uri );
 
     // Make sure that the res has some rdf:type statements
     if( !res.contains( RDF::type() ) ) {
@@ -167,28 +167,27 @@ bool \
Nepomuk2::Sync::ResourceIdentifier::runIdentification(const KUrl& uri)  return false;
     }
 
+    // Remove the types
+    QList<Soprano::Node> requiredTypes = res.values( RDF::type() );
+    res.remove( RDF::type() );
+
     QStringList identifyingProperties;
     QHash<KUrl, Soprano::Node> identifyingPropertiesHash;
 
     QHash< KUrl, Soprano::Node >::const_iterator it = res.constBegin();
     QHash< KUrl, Soprano::Node >::const_iterator constEnd = res.constEnd();
-    QList<Soprano::Node> requiredTypes;
     for( ; it != constEnd; it++ ) {
         const QUrl & prop = it.key();
 
-        // Special handling for rdf:type
-        if( prop == RDF::type() ) {
-            requiredTypes << it.value().uri();
-            continue;
-        }
-
         if( !isIdentifyingProperty( prop ) ) {
             continue;
         }
 
         identifyingProperties << Soprano::Node::resourceToN3( prop );
 
+        // For the case when the property has a resource range, and is still \
identifying  Soprano::Node object = it.value();
+        // vHanda: Should we really be identifying nepomuk uris?
         if( object.isBlank()
             || ( object.isResource() && object.uri().scheme() == \
QLatin1String("nepomuk") ) ) {  
@@ -396,24 +395,3 @@ void \
Nepomuk2::Sync::ResourceIdentifier::manualIdentification(const KUrl& oldUri  m_hash[ \
oldUri ] = newUri;  m_notIdentified.remove( oldUri );
 }
-
-bool Nepomuk2::Sync::ResourceIdentifier::isIdentifyingProperty(const QUrl& uri)
-{
-    if( uri == NAO::created()
-        || uri == NAO::creator()
-        || uri == NAO::lastModified()
-        || uri == NAO::userVisible() ) {
-        return false;
-    }
-
-    // TODO: Hanlde nxx:FluxProperty and nxx:resourceRangePropWhichCanIdentified
-    const QString query = QString::fromLatin1("ask { %1 %2 ?range . "
-                                                " %1 a %3 . "
-                                                "{ FILTER( regex(str(?range), \
                '^http://www.w3.org/2001/XMLSchema#') ) . }"
-                                                " UNION { %1 a rdf:Property . } }") \
                // rdf:Property should be nxx:resourceRangePropWhichCanIdentified
-                            .arg( Soprano::Node::resourceToN3( uri ),
-                                Soprano::Node::resourceToN3( RDFS::range() ),
-                                Soprano::Node::resourceToN3( RDF::Property() ) );
-
-    return m_model->executeQuery( query, Soprano::Query::QueryLanguageSparql \
                ).boolValue();
-}
diff --git a/services/storage/syncresourceidentifier.h \
b/services/storage/syncresourceidentifier.h index d08136a..bcce25a 100644
--- a/services/storage/syncresourceidentifier.h
+++ b/services/storage/syncresourceidentifier.h
@@ -117,7 +117,7 @@ namespace Nepomuk2 {
 
             ResourceHash resourceHash() const;
 
-            virtual bool isIdentifyingProperty( const QUrl & uri );
+            virtual bool isIdentifyingProperty( const QUrl & uri ) = 0;
 
         protected:
             /**


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

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