← Back to team overview

team4alfanous team mailing list archive

[Branch ~team4alfanous/alfanous/alfanous-git] Rev 543: move functions LOCATE, FIND, FILTER_DOUBLES into alfanous.Misc

 

------------------------------------------------------------
revno: 543
committer: Assem Chelli <assem.ch@xxxxxxxxx>
timestamp: Tue 2013-01-22 05:39:54 +0100
message:
  move functions LOCATE, FIND, FILTER_DOUBLES into alfanous.Misc 
  to use them globally
  
  Update FILTER_DOUBLES to use list(set(X))
modified:
  src/alfanous/Misc.py
  src/alfanous/QueryProcessing.py


--
lp:alfanous
https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git

Your team Alfanous team is subscribed to branch lp:alfanous.
To unsubscribe from this branch go to https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git/+edit-subscription
=== modified file 'src/alfanous/Misc.py'
--- src/alfanous/Misc.py	2013-01-01 23:38:13 +0000
+++ src/alfanous/Misc.py	2013-01-22 04:39:54 +0000
@@ -46,13 +46,11 @@
 
 
 
-#filter doubles
-def filter_doubles( lst ):
-    """ deprecated : use list(set()) or filter(cond,list) instead"""
-    for i in range( len( lst ) ):
-        if lst[i] not in lst[i + 1:]:
-            yield lst[i]
+FILTER_DOUBLES = filter_doubles = lambda lst:list( set( lst ) )
+LOCATE = lambda source, dist, itm: dist[source.index( itm )] \
+												if itm in source else None
 
+FIND = lambda source, dist, itm: [dist[i] for i in [i for i in range( len( source ) ) if source[i] == itm]]
 
 
 

=== modified file 'src/alfanous/QueryProcessing.py'
--- src/alfanous/QueryProcessing.py	2013-01-09 00:32:17 +0000
+++ src/alfanous/QueryProcessing.py	2013-01-22 04:39:54 +0000
@@ -75,6 +75,7 @@
 from alfanous.Exceptions import  FeedBack  # , NotImplemented
 from alfanous.TextProcessing import QArabicSymbolsFilter, unicode_
 
+from alfanous.Misc import LOCATE, FIND, FILTER_DOUBLES
 # from alfanous.Misc import buck2uni
 
 
@@ -684,17 +685,12 @@
             elif leveldist == 2: indexdist = "root"
             else: indexdist = "root"  # new levels
 
-            filter_doubles = lambda lst:[lst[i] for i in range( len( lst ) ) \
-										if lst[i] not in lst[i + 1:]]
-            locate = lambda source, dist, itm: dist[source.index( itm )] \
-            									if itm in source else None
-            Find = lambda source, dist, itm: [dist[i] for i in [i for i in range( len( source ) ) if source[i] == itm]]
 
             lst = []
-            if indexsrc:  # if index source level is definded
-                itm = locate( derivedict[indexsrc], derivedict[indexdist], word )
+            if indexsrc:  # if index source level is defined
+                itm = LOCATE( derivedict[indexsrc], derivedict[indexdist], word )
                 if itm:  # if different of none
-                    lst = filter_doubles( Find( derivedict[indexdist], derivedict["word_"], itm ) )
+                    lst = FILTER_DOUBLES( FIND( derivedict[indexdist], derivedict["word_"], itm ) )
                 else:
                     lst = [word]
 
@@ -722,12 +718,12 @@
         @staticmethod
         def tuple( props ):
             """ search the words that have the specific properties """
-            Find = lambda source, dist, itm: [dist[i] for i in [i for i in range( len( source ) ) if source[i] == itm]]
+
             wset = set()
             firsttime = True
             for propkey in props.keys():
                 if worddict.has_key( propkey ):
-                    partial_wset = set( Find( worddict[propkey], worddict["word_"], props[propkey] ) )
+                    partial_wset = set( FIND( worddict[propkey], worddict["word_"], props[propkey] ) )
                     if firsttime:
                         wset = partial_wset;firsttime = False
                     else: