Exemplo n.º 1
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
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def __str__(self):
     out = []
     for i, word in enumerate(self.words):
         if word in lex.puncts() and i != 0:
             out[-1] += word
         else:
             out.append(word)
     if not self.full():
         out = [str(stress) for stress in self.stresses] + out
         out = [self.rhymegroup + ':'] + out
     return ' '.join(out)
Exemplo n.º 4
0
 def needsrhyme(self):
     for word in self.words:
         if word not in lex.puncts(): return False
     return True