コード例 #1
0
def islimerick(limerick):
    #ensure the same lines aren't used multiple times
    if limerick[0] == limerick[1]:
        #print('0 1 same')
        #print(limerick)
        return False
    if limerick[0] == limerick[4]:
        #print(limerick)
        #print('0 4 same')
        return False
    if limerick[1] == limerick[4]:
        #print(limerick)
        #print('1 4 same')
        return False
    if limerick[2] == limerick[3]:
        #print(limerick)
        #print('2 3 same')
        return False
    A1 = rhymeDBGenerate.syllableCount(limerick[0])
    A2 = rhymeDBGenerate.syllableCount(limerick[1])
    A3 = rhymeDBGenerate.syllableCount(limerick[4])
    B1 = rhymeDBGenerate.syllableCount(limerick[2])
    B2 = rhymeDBGenerate.syllableCount(limerick[3])
    #print(A1[1] + " and " + B1[1])
    #check not same rhyme
    if A1[1] == B1[1]:
        return False
    #Check they are not the same last words
    if A1[2] == A2[2]:
        return False
    if A1[2] == A3[2]:
        return False
    if A2[2] == A3[2]:
        return False
    if B1[2] == B2[2]:
        return False
    #ensure the lines rhyme
    if A1[1] == A2[1] == A3[1]:
        if B1[1] == B2[1]:
            #print(limerick)
            return True
    return False
コード例 #2
0
def islimerick(limerick):
    #ensure the same lines aren't used multiple times
    if limerick[0] == limerick[1]:
        #print('0 1 same')
        #print(limerick)
        return False
    if limerick[0] == limerick[4]:
        #print(limerick)
        #print('0 4 same')
        return False
    if limerick[1] == limerick[4]:
        #print(limerick)
        #print('1 4 same')
        return False
    if limerick[2] == limerick[3]:
        #print(limerick)
        #print('2 3 same')
        return False
    A1 = rhymeDBGenerate.syllableCount(limerick[0])
    A2 = rhymeDBGenerate.syllableCount(limerick[1])
    A3 = rhymeDBGenerate.syllableCount(limerick[4])
    B1 = rhymeDBGenerate.syllableCount(limerick[2])
    B2 = rhymeDBGenerate.syllableCount(limerick[3])
    #print(A1[1] + " and " + B1[1])
    #check not same rhyme
    if A1[1] == B1[1]:
        return False
    #Check they are not the same last words
    if A1[2] == A2[2]:
        return False
    if A1[2] == A3[2]:
        return False
    if A2[2] == A3[2]:
        return False
    if B1[2] == B2[2]:
        return False
    #ensure the lines rhyme
    if A1[1] == A2[1] == A3[1]:
        if B1[1] == B2[1]:
            #print(limerick)
            return True
    return False
コード例 #3
0
def customLimerick():
    response.content_type = 'text/html; charset=UTF-8'
    line1 = request.query.line1.replace("%27","'").replace("%22","\"")
    line2 = request.query.line2.replace("%27","'").replace("%22","\"")
    line3 = request.query.line3.replace("%27","'").replace("%22","\"")
    line4 = request.query.line4.replace("%27","'").replace("%22","\"")
    line5 = request.query.line5.replace("%27","'").replace("%22","\"")

    limerickDB = limerickDBGenerate.getLimerickDB()
    SylA = random.choice(list(limerickDB[0].keys()))
    SylB = random.choice(list(limerickDB[1].keys()))

    #headlinesA = map(lambda s: s.encode('ascii', 'ignore'), (limerickDB[0][SylA]))
    headlinesA = reduce(set.union, (set(soundgroups) for soundgroups in (limerickDB[0][SylA].values())))
    headlinesB = reduce(set.union, (set(soundgroups) for soundgroups in (limerickDB[1][SylB].values())))
    #(headlinesA, headlinesB) = makeLimerickRhymeList()
    poemhtml="<html><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>"
    poemhtml+= "<head><center><font size='5'><b>Make a Custom News Headline Limerick</b><br></font>"
    poemhtml+= "<script src='https://code.jquery.com/jquery-1.10.2.js'></script></head><body><br>"
    if line5 == "":
        poemhtml+= "<form action='/custom/limerick' method='get'>"
    else:
        poemhtml+= "<form action='/custom/limericksave' method='get'>"
    #poemhtml+= "<form action='/custom/limericksave' method='get'>"
    if line1 == "":
        poemhtml+= "<p>First Line:<select name='line1'>"
        for title in headlinesA:
            poemhtml+="""<option value=\""""+str(title[0])+"""\">"""+str(title[0])+"""</option>"""
        poemhtml+="</select></p>"
    else:
        poemhtml+= line1+"""<br> <input type='hidden' name='line1' value=\""""+line1+"""\">"""
        Adata = rhymeDBGenerate.syllableCount(line1)
        if line2 == "":
            poemhtml+= "<p>Second Line:<select name='line2'>"
            for title in headlinesA:
                if title[1] == Adata[1] and title[2] == Adata[0]:
                    poemhtml+="""<option value=\""""+str(title[0])+"""\">"""+str(title[0])+"""</option>"""
            poemhtml+="</select></p>"
        else:
            poemhtml+= line2+"""<br> <input type='hidden' name='line2' value=\""""+line2+"""\">"""
            if line3 == "":
                poemhtml+= "<p>Third Line:<select name='line3'>"
                for title in headlinesB:
                    poemhtml+="""<option value=\""""+str(title[0])+"""\">"""+str(title[0])+"""</option>"""
                poemhtml+="</select></p>"
            else:
                poemhtml+= line3+"""<br> <input type='hidden' name='line3' value=\""""+line3+"""\">"""
                Bdata = rhymeDBGenerate.syllableCount(line3)
                if line4 == "":
                    poemhtml+= "<p>Fourth Line:<select name='line4'>"
                    for title in headlinesB:
                        if title[1] == Bdata[1] and title[2] == Bdata[0]:
                            poemhtml+="""<option value=\""""+str(title[0])+"""\">"""+str(title[0])+"""</option>"""
                    poemhtml+="</select></p>"
                else:
                    poemhtml+= line4+"""<br> <input type='hidden' name='line4' value=\""""+line4+"""\">"""
                    if line5 == "":
                        poemhtml+= "<p>Final Line:<select name='line5'>"
                        for title in headlinesA:
                            if title[1] == Adata[1] and title[2] == Adata[0]:
                                poemhtml+="""<option value=\""""+str(title[0])+"""\">"""+str(title[0])+"""</option>"""
                        poemhtml+="</select></p>"
                    else:
                        poemhtml+= line5+"""<br> <input type='hidden' name='line5' value=\""""+line5+"""\">"""
    if line5 == "":
        poemhtml+="<input value='Next' type='submit' />"
        #pass
    else:
        poemhtml+="<br><input value='Save' type='submit' /><br>"
    poemhtml+="<br><font size='2'>"
    poemhtml+="<br><a href = 'limerick'>Start Again</a>"
    poemhtml+="</font>"
    poemhtml+="<br><font size='1'>"
    poemhtml+="<br> back to <a href='/'>random poems</a>"
    poemhtml+="</center></font>"
    poemhtml+="</form></body></html>"
    #rhymeDBGenerate.syllableCount()

    return poemhtml