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

List:       kde-commits
Subject:    playground/base/nepomuk-kde/scribo/plugins/pimo
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-10-21 11:28:05
Message-ID: 20101021112805.1850BAC897 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1188094 by trueg:

an optimized query and a very naive scoring

 M  +16 -3     pimotextmatchplugin.cpp  


--- trunk/playground/base/nepomuk-kde/scribo/plugins/pimo/pimotextmatchplugin.cpp #1188093:1188094
@@ -1,6 +1,6 @@
 /*
  * This file is part of the Nepomuk KDE project.
- * Copyright (c) 2009 Sebastian Trueg <trueg@kde.org>
+ * Copyright (c) 2009-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 Library General Public
@@ -100,6 +100,13 @@
 }
 
 
+namespace {
+double calculateRankTheDumbWay(const QString& queryString, const QString& name)
+{
+    return 1.0 - double(name.length() - queryString.length()) / double(name.length());
+}
+}
+
 bool PimoTextMatchPlugin::queryWord( const QString& word )
 {
     if ( word.length() < s_minLength ) {
@@ -112,13 +119,19 @@
 
 //    kDebug() << "checking word" << word;
 
+    //
+    // We search quite a lot of words. Thus, we restrict ourselves to pimo things and tags and
+    // only check their prefLabel.
+    //
     Nepomuk::Query::Query query =
         Nepomuk::Query::Query(
             Nepomuk::Query::AndTerm(
                 Nepomuk::Query::OrTerm(
                     Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Thing() ),
                     Nepomuk::Query::ResourceTypeTerm( Soprano::Vocabulary::NAO::Tag() ) ),
-                Nepomuk::Query::LiteralTerm( word ) ) );
+                Nepomuk::Query::ComparisonTerm( Soprano::Vocabulary::NAO::prefLabel(),
+                                                Nepomuk::Query::LiteralTerm( word ) ) ) );
+    query.setLimit( 5 );
 
     kDebug() << query.toSparqlQuery();
 
@@ -132,7 +145,7 @@
         Scribo::TextOccurrence oc;
         oc.setStartPos( m_pos );
         oc.setLength( word.length() );
-        oc.setRelevance( it[1].literal().toDouble() );
+        oc.setRelevance( calculateRankTheDumbWay(word, entity.label()) );
         entity.addOccurrence( oc );
 
         addNewMatch( entity );
[prev in list] [next in list] [prev in thread] [next in thread] 

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