[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, debian, updated. upstream/0.9.5.5-717-g0f98819

Sebastian Krzyszkowiak seba.dos1 at gmail.com
Sat Aug 6 08:17:33 UTC 2011


The following commit has been merged in the debian branch:
commit 5813d689af8c3b4ffbd20e2e2ebfc6c3b90309dc
Author: Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
Date:   Sat Jul 25 15:09:25 2009 +0200

    opimd: Calls: use regexps instead of difflib
    
    Signed-off-by: Sebastian Krzyszkowiak <seba.dos1 at gmail.com>

diff --git a/framework/subsystems/opimd/pimd_calls.py b/framework/subsystems/opimd/pimd_calls.py
index ae14acf..3d6a22e 100644
--- a/framework/subsystems/opimd/pimd_calls.py
+++ b/framework/subsystems/opimd/pimd_calls.py
@@ -3,10 +3,10 @@
 """
 Open PIM Daemon
 
-(C) 2008 by Soeren Apel <abraxa at dar-clan.de>
+(C) 2008 Soeren Apel <abraxa at dar-clan.de>
 (C) 2008 Openmoko, Inc.
 (C) 2009 Michael 'Mickey' Lauer <mlauer at vanille-media.de>
-(C) 2009 by Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
+(C) 2009 Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
 GPLv2 or later
 
 Calls Domain Plugin
@@ -20,11 +20,11 @@ from dbus.service import FallbackObject as DBusFBObject
 from dbus.service import signal as dbus_signal
 from dbus.service import method as dbus_method
 
+import re
+
 import logging
 logger = logging.getLogger('opimd')
 
-from difflib import SequenceMatcher
-
 from backend_manager import BackendManager
 from backend_manager import PIMB_CAN_ADD_ENTRY, PIMB_CAN_DEL_ENTRY, PIMB_CAN_UPD_ENTRY, PIMB_CAN_UPD_ENTRY_WITH_NEW_FIELD, PIMB_NEEDS_SYNC
 
@@ -38,8 +38,6 @@ from framework.config import config, busmap
 
 _DOMAIN_NAME = "Calls"
 
-_MIN_MATCH_TRESHOLD = 0.75
-
 _DBUS_PATH_CALLS = DBUS_PATH_BASE_FSO + '/' + _DOMAIN_NAME
 _DIN_CALLS_BASE = DIN_BASE_FSO
 
@@ -77,13 +75,13 @@ class CallQueryMatcher(object):
         for (call_id, call) in enumerate(calls):
             if call:
                 match = call.match_query(self.query_obj)
-                if match > _MIN_MATCH_TRESHOLD:
+                if match > 0.0:
                     matches.append((match, call_id))
 
         result_count = len(matches)
         # Sort matches by relevance and return the best hits
         if result_count > 0:
-            matches.sort()
+            matches.sort(reverse = True)
 
             limit = result_count
             if self.query_obj.has_key("_limit"):
@@ -337,7 +335,6 @@ class Call():
         @return Accuracy of the match, ranging from 0.0 (no match) to 1.0 (complete match)"""
 
         overall_match = 1.0
-        matcher = SequenceMatcher()
 
         for field_name in query_obj.keys():
             # Skip fields only meaningful to the parser
@@ -346,8 +343,7 @@ class Call():
             field_value = str(query_obj[field_name])
             best_field_match = 0.0
 
-            # The matcher internally caches details about seq2, so let's make use of that
-            matcher.set_seq2(field_value)
+            matcher = re.compile(field_value)
             seq2_len = len(field_value)
 
             # Check if field value(s) of this call match(es) the query field
@@ -363,16 +359,19 @@ class Call():
                         comp_value = str(self._fields[field_id][1])
 
                     # Compare and determine the best match ratio
-                    matcher.set_seq1(comp_value)
-                    match = matcher.find_longest_match(0, len(comp_value), 0, seq2_len)
-                    match_len = match[2]
+                    match = matcher.search(comp_value)
+                    if match:
+                        match_len = match.end() - match.start()
+                    else:
+                        match_len = 0
+
                     if seq2_len==0:
                         field_match = 0.0
                     else:
-                        field_match = float(match_len) / seq2_len
+                        field_match = float(match_len) / len(comp_value)
 
                     if field_match > best_field_match: best_field_match = field_match
-                    logger.debug("calls: Field match for %s / %s: %f", comp_value, field_value, field_match)
+                    logger.debug("Calls: Field match for %s / %s: %f", comp_value, field_value, field_match)
 
             except KeyError:
                 # call has no data for this field contained in the query, so this entry cannot match
@@ -384,7 +383,7 @@ class Call():
             overall_match *= best_field_match
 
             # Stop comparing if there is too little similarity
-            if overall_match < _MIN_MATCH_TRESHOLD: break
+            if overall_match == 0.0: break
 
         return overall_match
 
diff --git a/framework/subsystems/opimd/pimd_messages.py b/framework/subsystems/opimd/pimd_messages.py
index 278dc48..b27202c 100644
--- a/framework/subsystems/opimd/pimd_messages.py
+++ b/framework/subsystems/opimd/pimd_messages.py
@@ -372,7 +372,6 @@ class Message():
             field_value = str(query_obj[field_name])
             best_field_match = 0.0
 
-            # The matcher internally caches details about seq2, so let's make use of that
             matcher = re.compile(field_value)
             seq2_len = len(field_value)
 

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list