def testModel(): lyricLines = [] for filename in glob.glob('lyrics/*'): print filename with codecs.open(filename, 'r', encoding='utf-8') as lyrics: lyricLines.extend(lyrics.read().split('\n')) tokens = [[word.encode('ascii', 'ignore') for word in line.split()] for line in lyricLines] lm = buildLM(tokens, 3) for i in range(0, 5): print "___________________\n" line = generateLine(lm, 3) while len(line) > 15: line = generateLine(lm, 3) print line stressPattern = ''.join(getStress(word).replace('*', '') for word in line) candidateLines = [] for j in range(0, 12): matchingLine = ' '.join(generateMatchingLines(lm, 3, stressPattern)) candidateLines.append(matchingLine) rhymedLines = rhyme.rhyme(candidateLines, 'aabb') for i, line in enumerate(rhymedLines): print ' '.join(line) if (i+1) % 4 == 0: print "" for line in rhymedLines: print ''.join([getStress(word) in line])
def create_poemline(self, string): # original text self.originalString = string # texts without symbols or urls self.cleanString = remove_symbols(remove_urls(string)) # number of syllables in line self.syl = line_syl(self.cleanString) # rhymes against last word self.rhymes = rhyme(string.split()[-1], self.RHYME_LEVEL)
def on_pubmsg(self, connection, event): text = event.arguments()[0] try: source = event.source().split("!")[0] except IndexError: source = "" # If you talk to the bot, this is how he responds. if self.nick_reg.search(text): if len(text.split(":")) > 1: message = ":".join(text.split(":")[1:]) connection.privmsg(self.channel, source+": "+rhyme.rhyme(message)) else: print text
def on_pubmsg(self, connection, event): text = event.arguments()[0] try: source = event.source().split("!")[0] except IndexError: source = "" # If you talk to the bot, this is how he responds. if self.nick_reg.search(text): if len(text.split(":")) > 1: message = ":".join(text.split(":")[1:]) connection.privmsg(self.channel, source + ": " + rhyme.rhyme(message)) else: print text
def challenge(): if flask.request.method == "POST": challenge = flask.request.form["challenge"] fire = rhyme.rhyme(flask.request.form["challenge"]) return flask.render_template("response.html", challenge=challenge, fire=fire) return flask.render_template("challenge.html")