示例#1
0
    def add(self, word):
        if not self.fits(word):
            raise Exception('word does not fit: ' + word)

        if word in lex.puncts():
            self.words.insert(0, word)
        else:
            stresslen = len(min(lex.stresskeys(word), key=len))
            self.stresses = self.stresses[:-stresslen]
            self.words.insert(0, word)
示例#2
0
 def fits(self, word):
     if self.full(): return False
     if word in lex.puncts():
         return not self.words or self.words[0] not in lex.puncts()
     else:
         stresskeys = lex.stresskeys(word)
         for stresskey in stresskeys:
             if len(stresskey) > self.stresses: continue
             stresszip = zip(reversed(stresskey), reversed(self.stresses))
             if all(x == y for x, y in stresszip):
                 return True
         return False