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

List:       kde-commits
Subject:    Re: [nepomuk-core] services/queryservice: Port to resultiterator
From:       Vishesh Handa <handa.vish () gmail ! com>
Date:       2012-08-07 5:55:58
Message-ID: CAOPTMKC4gadgrMJqO3swn9v5F4cNUs2PA9eOm=3sXHd6t06CpQ () mail ! gmail ! com
[Download RAW message or body]

Congratulations on your first commit!

Btw, in case you haven't already read the Git KDE Manual [1]. Please do so.
Oh, and could you please mark the review request as submitted?

[1] http://community.kde.org/Sysadmin/GitKdeOrgManual

On Tue, Aug 7, 2012 at 4:36 AM, Simeon Bird <spb41@ias.edu> wrote:

> Git commit 6d245db57a02d0a59a71224f0f404796d7fc82c2 by Simeon Bird.
> Committed on 05/08/2012 at 19:31.
> Pushed by sbird into branch 'master'.
>
> Port to resultiterator
>
> M  +6    -65   services/queryservice/searchrunnable.cpp
> M  +0    -6    services/queryservice/searchrunnable.h
>
>
> http://commits.kde.org/nepomuk-core/6d245db57a02d0a59a71224f0f404796d7fc82c2
>
> diff --git a/services/queryservice/searchrunnable.cpp
> b/services/queryservice/searchrunnable.cpp
> index 451db46..8d9db6f 100644
> --- a/services/queryservice/searchrunnable.cpp
> +++ b/services/queryservice/searchrunnable.cpp
> @@ -20,38 +20,18 @@
>  #include "searchrunnable.h"
>  #include "folder.h"
>
> -#include "resourcemanager.h"
>  #include "resource.h"
>
> -#include <Soprano/Version>
> -#include <Soprano/Model>
> -#include <Soprano/QueryResultIterator>
> -#include <Soprano/Node>
> -#include <Soprano/Statement>
> -#include <Soprano/LiteralValue>
> -#include <Soprano/StatementIterator>
> -#include <Soprano/Vocabulary/RDF>
> -#include <Soprano/Vocabulary/RDFS>
> -#include <Soprano/Vocabulary/NRL>
> -#include <Soprano/Vocabulary/NAO>
> -#include <Soprano/Vocabulary/XMLSchema>
> -#include <Soprano/Vocabulary/OWL>
> -#include <Soprano/Vocabulary/Xesam>
> -#include "nfo.h"
> +#include "query/resultiterator.h"
>
>  #include <KDebug>
> -#include <KDateTime>
> -#include <KRandom>
>
> +#ifndef NDEBUG
>  #include <QtCore/QTime>
> -#include <QtCore/QRegExp>
> -#include <QtCore/QLatin1String>
> +#endif
>  #include <QtCore/QStringList>
>
>
> -
> -using namespace Soprano;
> -
>  Nepomuk2::Query::SearchRunnable::SearchRunnable( Folder* folder )
>      : QRunnable(),
>        m_folder( folder )
> @@ -86,11 +66,11 @@ void Nepomuk2::Query::SearchRunnable::run()
>      time.start();
>  #endif
>
> -    Soprano::QueryResultIterator hits =
> ResourceManager::instance()->mainModel()->executeQuery( sparql,
> Soprano::Query::QueryLanguageSparql );
> +    //Iterator of results
> +    ResultIterator hits(sparql);
>      while ( m_folder &&
>              hits.next() ) {
> -        Result result = extractResult( hits );
> -
> +        Result result = hits.result();
>          kDebug() << "Found result:" << result.resource().uri() <<
> result.score();
>
>          lock.relock();
> @@ -113,42 +93,3 @@ void Nepomuk2::Query::SearchRunnable::run()
>  }
>
>
> -Nepomuk2::Query::Result Nepomuk2::Query::SearchRunnable::extractResult(
> const Soprano::QueryResultIterator& it ) const
> -{
> -    Result result( Resource::fromResourceUri( it[0].uri() ) );
> -
> -    // make sure we do not store values twice
> -    QStringList names = it.bindingNames();
> -    names.removeAll( QLatin1String( "r" ) );
> -
> -    m_folderMutex.lock();
> -    if( m_folder ) {
> -        RequestPropertyMap requestProperties =
> m_folder->requestPropertyMap();
> -        for ( RequestPropertyMap::const_iterator rpIt =
> requestProperties.constBegin();
> -             rpIt != requestProperties.constEnd(); ++rpIt ) {
> -            result.addRequestProperty( rpIt.value(), it.binding(
> rpIt.key() ) );
> -            names.removeAll( rpIt.key() );
> -        }
> -    }
> -    m_folderMutex.unlock();
> -
> -    static const char* s_scoreVarName = "_n_f_t_m_s_";
> -    static const char* s_excerptVarName = "_n_f_t_m_ex_";
> -
> -    Soprano::BindingSet set;
> -    int score = 0;
> -    Q_FOREACH( const QString& var, names ) {
> -        if ( var == QLatin1String( s_scoreVarName ) )
> -            score = it[var].literal().toInt();
> -        else if ( var == QLatin1String( s_excerptVarName ) )
> -            result.setExcerpt( it[var].toString() );
> -        else
> -            set.insert( var, it[var] );
> -    }
> -
> -    result.setAdditionalBindings( set );
> -    result.setScore( ( double )score );
> -
> -    // score will be set above
> -    return result;
> -}
> diff --git a/services/queryservice/searchrunnable.h
> b/services/queryservice/searchrunnable.h
> index 1c12a9b..a458699 100644
> --- a/services/queryservice/searchrunnable.h
> +++ b/services/queryservice/searchrunnable.h
> @@ -29,10 +29,6 @@
>  #include "folder.h"
>
>
> -namespace Soprano {
> -    class QueryResultIterator;
> -}
> -
>  namespace Nepomuk2 {
>      namespace Query {
>          class Folder;
> @@ -55,8 +51,6 @@ namespace Nepomuk2 {
>              void run();
>
>          private:
> -            Nepomuk2::Query::Result extractResult( const
> Soprano::QueryResultIterator& it ) const;
> -
>              QPointer<Folder> m_folder;
>              mutable QMutex m_folderMutex;
>          };
>

[Attachment #3 (text/html)]

Congratulations on your first commit!<br><br>Btw, in case you haven&#39;t already \
read the Git KDE Manual [1]. Please do so. Oh, and could you please mark the review \
request as submitted?<br><br>[1] <a \
href="http://community.kde.org/Sysadmin/GitKdeOrgManual">http://community.kde.org/Sysadmin/GitKdeOrgManual</a> \
<br> <br><div class="gmail_quote">On Tue, Aug 7, 2012 at 4:36 AM, Simeon Bird <span \
dir="ltr">&lt;<a href="mailto:spb41@ias.edu" \
target="_blank">spb41@ias.edu</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> Git commit 6d245db57a02d0a59a71224f0f404796d7fc82c2 by \
Simeon Bird.<br> Committed on 05/08/2012 at 19:31.<br>
Pushed by sbird into branch &#39;master&#39;.<br>
<br>
Port to resultiterator<br>
<br>
M  +6    -65   services/queryservice/searchrunnable.cpp<br>
M  +0    -6    services/queryservice/searchrunnable.h<br>
<br>
<a href="http://commits.kde.org/nepomuk-core/6d245db57a02d0a59a71224f0f404796d7fc82c2" \
target="_blank">http://commits.kde.org/nepomuk-core/6d245db57a02d0a59a71224f0f404796d7fc82c2</a><br>
 <br>
diff --git a/services/queryservice/searchrunnable.cpp \
b/services/queryservice/searchrunnable.cpp<br> index 451db46..8d9db6f 100644<br>
--- a/services/queryservice/searchrunnable.cpp<br>
+++ b/services/queryservice/searchrunnable.cpp<br>
@@ -20,38 +20,18 @@<br>
 #include &quot;searchrunnable.h&quot;<br>
 #include &quot;folder.h&quot;<br>
<br>
-#include &quot;resourcemanager.h&quot;<br>
 #include &quot;resource.h&quot;<br>
<br>
-#include &lt;Soprano/Version&gt;<br>
-#include &lt;Soprano/Model&gt;<br>
-#include &lt;Soprano/QueryResultIterator&gt;<br>
-#include &lt;Soprano/Node&gt;<br>
-#include &lt;Soprano/Statement&gt;<br>
-#include &lt;Soprano/LiteralValue&gt;<br>
-#include &lt;Soprano/StatementIterator&gt;<br>
-#include &lt;Soprano/Vocabulary/RDF&gt;<br>
-#include &lt;Soprano/Vocabulary/RDFS&gt;<br>
-#include &lt;Soprano/Vocabulary/NRL&gt;<br>
-#include &lt;Soprano/Vocabulary/NAO&gt;<br>
-#include &lt;Soprano/Vocabulary/XMLSchema&gt;<br>
-#include &lt;Soprano/Vocabulary/OWL&gt;<br>
-#include &lt;Soprano/Vocabulary/Xesam&gt;<br>
-#include &quot;nfo.h&quot;<br>
+#include &quot;query/resultiterator.h&quot;<br>
<br>
 #include &lt;KDebug&gt;<br>
-#include &lt;KDateTime&gt;<br>
-#include &lt;KRandom&gt;<br>
<br>
+#ifndef NDEBUG<br>
 #include &lt;QtCore/QTime&gt;<br>
-#include &lt;QtCore/QRegExp&gt;<br>
-#include &lt;QtCore/QLatin1String&gt;<br>
+#endif<br>
 #include &lt;QtCore/QStringList&gt;<br>
<br>
<br>
-<br>
-using namespace Soprano;<br>
-<br>
 Nepomuk2::Query::SearchRunnable::SearchRunnable( Folder* folder )<br>
     : QRunnable(),<br>
       m_folder( folder )<br>
@@ -86,11 +66,11 @@ void Nepomuk2::Query::SearchRunnable::run()<br>
     time.start();<br>
 #endif<br>
<br>
-    Soprano::QueryResultIterator hits = \
ResourceManager::instance()-&gt;mainModel()-&gt;executeQuery( sparql, \
Soprano::Query::QueryLanguageSparql );<br> +    //Iterator of results<br>
+    ResultIterator hits(sparql);<br>
     while ( m_folder &amp;&amp;<br>
             hits.next() ) {<br>
-        Result result = extractResult( hits );<br>
-<br>
+        Result result = hits.result();<br>
         kDebug() &lt;&lt; &quot;Found result:&quot; &lt;&lt; result.resource().uri() \
&lt;&lt; result.score();<br> <br>
         lock.relock();<br>
@@ -113,42 +93,3 @@ void Nepomuk2::Query::SearchRunnable::run()<br>
 }<br>
<br>
<br>
-Nepomuk2::Query::Result Nepomuk2::Query::SearchRunnable::extractResult( const \
                Soprano::QueryResultIterator&amp; it ) const<br>
-{<br>
-    Result result( Resource::fromResourceUri( it[0].uri() ) );<br>
-<br>
-    // make sure we do not store values twice<br>
-    QStringList names = it.bindingNames();<br>
-    names.removeAll( QLatin1String( &quot;r&quot; ) );<br>
-<br>
-    m_folderMutex.lock();<br>
-    if( m_folder ) {<br>
-        RequestPropertyMap requestProperties = \
                m_folder-&gt;requestPropertyMap();<br>
-        for ( RequestPropertyMap::const_iterator rpIt = \
                requestProperties.constBegin();<br>
-             rpIt != requestProperties.constEnd(); ++rpIt ) {<br>
-            result.addRequestProperty( rpIt.value(), it.binding( rpIt.key() ) );<br>
-            names.removeAll( rpIt.key() );<br>
-        }<br>
-    }<br>
-    m_folderMutex.unlock();<br>
-<br>
-    static const char* s_scoreVarName = &quot;_n_f_t_m_s_&quot;;<br>
-    static const char* s_excerptVarName = &quot;_n_f_t_m_ex_&quot;;<br>
-<br>
-    Soprano::BindingSet set;<br>
-    int score = 0;<br>
-    Q_FOREACH( const QString&amp; var, names ) {<br>
-        if ( var == QLatin1String( s_scoreVarName ) )<br>
-            score = it[var].literal().toInt();<br>
-        else if ( var == QLatin1String( s_excerptVarName ) )<br>
-            result.setExcerpt( it[var].toString() );<br>
-        else<br>
-            set.insert( var, it[var] );<br>
-    }<br>
-<br>
-    result.setAdditionalBindings( set );<br>
-    result.setScore( ( double )score );<br>
-<br>
-    // score will be set above<br>
-    return result;<br>
-}<br>
diff --git a/services/queryservice/searchrunnable.h \
b/services/queryservice/searchrunnable.h<br> index 1c12a9b..a458699 100644<br>
--- a/services/queryservice/searchrunnable.h<br>
+++ b/services/queryservice/searchrunnable.h<br>
@@ -29,10 +29,6 @@<br>
 #include &quot;folder.h&quot;<br>
<br>
<br>
-namespace Soprano {<br>
-    class QueryResultIterator;<br>
-}<br>
-<br>
 namespace Nepomuk2 {<br>
     namespace Query {<br>
         class Folder;<br>
@@ -55,8 +51,6 @@ namespace Nepomuk2 {<br>
             void run();<br>
<br>
         private:<br>
-            Nepomuk2::Query::Result extractResult( const \
                Soprano::QueryResultIterator&amp; it ) const;<br>
-<br>
             QPointer&lt;Folder&gt; m_folder;<br>
             mutable QMutex m_folderMutex;<br>
         };<br>
</blockquote></div><br>



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

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