Esempio n. 1
0
 def read_word(self):
     if self._index >= self._len:
         self._eof = True
         return False
     self._nxt = self._list[self._index]
     self._key = Alphabet.sortkey(self._nxt)
     self._index += 1
     return True
Esempio n. 2
0
 def read_word(self):
     """ Read lines until we have a legal word or EOF """
     while True:
         try:
             line = next(self._fin).strip()
         except StopIteration:
             # We're done with this file
             self._eof = True
             return False
         if line and len(line) < MAXLEN:
             # Valid word
             self._nxt = line
             self._key = Alphabet.sortkey(line)
             return True
Esempio n. 3
0
 def read_word(self):
     """ Read lines until we have a legal word or EOF """
     while True:
         try:
             line = self._fin.next()
         except StopIteration:
             # We're done with this file
             self._eof = True
             return False
         if line.endswith(u'\r\n'):
             # Cut off trailing CRLF (Windows-style)
             line = line[0:-2]
         elif line.endswith(u'\n'):
             # Cut off trailing LF (Unix-style)
             line = line[0:-1]
         if line and len(line) < MAXLEN:
             # Valid word
             self._nxt = line
             self._key = Alphabet.sortkey(line)
             return True
Esempio n. 4
0
 def done(self):
     """ Called when the whole navigation is done """
     self._result.sort(key=lambda x: (-len(x), Alphabet.sortkey(x)))
Esempio n. 5
0
 def done(self):
     """ Called when the whole navigation is done """
     self._result.sort(key = lambda x: (-len(x), Alphabet.sortkey(x)))
Esempio n. 6
0
 def _sorted(l):
     """ Return a list of (prefix, node) tuples sorted by prefix """
     return sorted(l, key=lambda x: Alphabet.sortkey(x[0]))
Esempio n. 7
0
 def _sorted(l):
     """ Return a list of (prefix, node) tuples sorted by prefix """
     return sorted(l, key = lambda x: Alphabet.sortkey(x[0]))