コード例 #1
0
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])
コード例 #2
0
ファイル: poemline.py プロジェクト: pietdaniel/poetification
 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)
コード例 #3
0
ファイル: bot.py プロジェクト: classam/rhymenocerous
    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
コード例 #4
0
    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
コード例 #5
0
ファイル: web.py プロジェクト: natetarrh/dylan
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")