Esempio n. 1
0
 def test_number_of_syllables(self):
     MC = MCMarkov(self.where_the_sidewalk_ends, 1, True)
     new_song = MC.create_song(couplet_count=5, syllable_count=10)
     for couplet in new_song:
         for line in couplet:
             sylcount = sum(nsyl(word) for word in line)
             self.assertEqual(sylcount, 10)
Esempio n. 2
0
 def test_couplets_rhyme(self):
     MC = MCMarkov(self.where_the_sidewalk_ends, 1, True)
     new_song = MC.create_song(couplet_count=5, syllable_count=10)
     for couplet in new_song:
         endword1 = couplet[0][-1]
         endword2 = couplet[1][-1]
         self.assertTrue(rhymes_with(endword1, endword2))
Esempio n. 3
0
 def test_syllable_map(self):
     MC = MCMarkov(self.where_the_sidewalk_ends, 1, True)
     syllable_map = [[7, 10], [5, 12]]
     new_song = MC.create_song(couplet_count=None, syllable_count=None, syllable_map=syllable_map)
     for i, couplet in enumerate(new_song):
         couplet_map = syllable_map[i]
         for j, line in enumerate(couplet):
             line_map = couplet_map[j]
             sylcount = sum(nsyl(word) for word in line)
             self.assertEqual(sylcount, line_map)
Esempio n. 4
0
#s = Scraper()
#s.add_songs(['gucci mane'])
#s.add_lyrics()

def getlyrics(cursor, artist):
    SQL = "SELECT line from lyrics join songs on lyrics.song_id = songs.id where artist =?;" # Note: no quotes
    data = (artist, )
    cursor.execute(SQL, data)
    lyrics = cursor.fetchall()
    return [i[0].encode('UTF-8').decode('UTF-8').lower().split() for i in lyrics]

conn=sqlite3.connect("/usr/local/sqlite/rapgenerator.db")
c = conn.cursor()
corpus = getlyrics(c, 'gucci mane')

mc = MCMarkov(corpus, 4, True)
new_song = mc.create_song(couplet_count=10, syllable_count=10)

for couplet in new_song:
    for line in couplet:
        print ' '.join(line)



for line in corpus:
    if line and '?' in line[0]:
        print line


starting_words = [line[0] for line in self.corpus if line]
Esempio n. 5
0
 def test_number_of_couplets(self):
     MC = MCMarkov(self.where_the_sidewalk_ends, 1, True)
     new_song = MC.create_song(couplet_count=5, syllable_count=10)
     self.assertEqual(len(new_song), 5)