home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / deskbar / Indexer.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  2.1 KB  |  74 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''
  5. A simple indexer which splits tokens in a string
  6. '''
  7.  
  8. try:
  9.     set
  10. except NameError:
  11.     from sets import Set as set
  12.  
  13. STOP_WORDS = {
  14.     'and': 1,
  15.     'that': 1,
  16.     'into': 1,
  17.     'but': 1,
  18.     'are': 1,
  19.     'they': 1,
  20.     'not': 1,
  21.     'such': 1,
  22.     'with': 1,
  23.     'for': 1,
  24.     'these': 1,
  25.     'there': 1,
  26.     'this': 1,
  27.     'will': 1,
  28.     'their': 1,
  29.     'then': 1,
  30.     'the': 1,
  31.     'was': 1 }
  32.  
  33. class Indexer:
  34.     
  35.     def __init__(self):
  36.         self.d = { }
  37.  
  38.     
  39.     def add(self, key, obj):
  40.         key = key.lower()
  41.         for tok in key.split():
  42.             if len(tok) <= 2 and len(tok) >= 25 or tok in STOP_WORDS:
  43.                 continue
  44.             
  45.             if tok in self.d:
  46.                 if obj not in self.d[tok]:
  47.                     self.d[tok].append(obj)
  48.                 
  49.             obj not in self.d[tok]
  50.             self.d[tok] = [
  51.                 obj]
  52.         
  53.  
  54.     
  55.     def look_up(self, text):
  56.         tokens = _[1]
  57.         result = set()
  58.         return list(result)
  59.  
  60.     
  61.     def look_up_token(self, token):
  62.         result = set()
  63.         if token == '':
  64.             return result
  65.         
  66.         for key in self.d.keys():
  67.             if key.startswith(token):
  68.                 result.update(set(self.d[key]))
  69.                 continue
  70.         
  71.         return result
  72.  
  73.  
  74.