Beispiel #1
0
 def correct_token(self, token):
     index = self.index
     orig_token = token
     token = token.lower()
     if len(token) > 2 and has_char(token):
         try:
             self._TIME()
             r = index.query(token, max_mistakes=0, keys_only=True)
             self._TIME('index')
             if r.exact_total == 0:
                 try:
                     self._TIME()
                     r = index.query(token, max_mistakes=1, keys_only=True)
                     self._TIME('index')
                     if r.exact_total == 0:
                         self._TIME()
                         r = index.query(token, max_mistakes=2, keys_only=True)
                         self._TIME('index')
                     if 0 < r.exact_total <= 10:
                         new = map(lambda rec: rec.key, r.values)
                         self.corrected.append((orig_token, new))
                         return new
                     else:
                         self.corrected.append((orig_token, None))
                 except rpcz.RpcDeadlineExceeded:
                     self.corrected.append((orig_token, None))
                     raise
         except rpcz.RpcDeadlineExceeded:
             self.correct_deadline = True
     return [token]
Beispiel #2
0
 def correct_token(self, token):
     index = self.index
     orig_token = token
     token = token.lower()
     if len(token) > 2 and has_char(token):
         try:
             self._TIME()
             r = index.query(token, max_mistakes=0, keys_only=True)
             self._TIME('index')
             if r.exact_total == 0:
                 try:
                     self._TIME()
                     r = index.query(token, max_mistakes=1, keys_only=True)
                     self._TIME('index')
                     if r.exact_total == 0:
                         self._TIME()
                         r = index.query(token,
                                         max_mistakes=2,
                                         keys_only=True)
                         self._TIME('index')
                     if 0 < r.exact_total <= 10:
                         new = map(lambda rec: rec.key, r.values)
                         self.corrected.append((orig_token, new))
                         return new
                     else:
                         self.corrected.append((orig_token, None))
                 except rpcz.RpcDeadlineExceeded:
                     self.corrected.append((orig_token, None))
                     raise
         except rpcz.RpcDeadlineExceeded:
             self.correct_deadline = True
     return [token]
Beispiel #3
0
def good(t):
    return len(t) > 3 and has_char(t)
Beispiel #4
0
def good(t):
    return len(t) > 3 and has_char(t)