Example #1
0
    def search_word(self, word):
        word_stemmed = lyrics_to_bow.lyrics_to_bow(word).iterkeys()[0]
        result = self.lyrics.execute("SELECT count FROM lyrics WHERE word='%s';" % word_stemmed)
        total = 0
        for count in result:
            total += count[0]

        return total
Example #2
0
 def predict_lyrics(self, lyrics,user_pred=None):
     lyrics_stemmed = lyrics_to_bow.lyrics_to_bow(lyrics)
     print "LYRICS: %s" %lyrics
     print "STEMMED: %s" %lyrics_stemmed
     indexed_dict={}
     for key in lyrics_stemmed.iterkeys():
         try:
             indexed_dict[self.word_indices.index(key)]=lyrics_stemmed[key]
         
         #if the word isnt among the 5000
         except ValueError, err:
             pass
Example #3
0
def readLyrics(dir):

    mxmBow = fileManager(BOW, 'r').split(',')

    files = sorted(listdir(dir))

    newSet = []
    songLyrics = []
    bow = '{word}:{freq}'

    for lyrics in files:
        bow = lyrics_to_bow(fileManager(RANGE1 + lyrics, 'r'))

        try:

            for word, freq in bow.iteritems():

                try:

                    songLyrics.append(
                        bow.format(
                            word=str(mxmBow.index(word) + 1),
                            freq=str(freq)
                        )
                    )

                except ValueError:
                    continue

            newSet.append(
                [
                    sep.join(
                        lyrics[:-4].split('-lyrics-')[::-1]
                    ).replace('-', '')
                ] +
                sorted(
                    songLyrics, key=lambda s: int(s.partition(':')[0])
                )
            )
            songLyrics = []

        except AttributeError:
            print "Failed to index", lyrics
            continue

    return '\n'.join(sorted([','.join(line) for line in newSet]))
Example #4
0
def predict_genre(song_title, artist=None):
    # check if we already have the lryics
    #dfLyricBow=
    #if
    lyrics, title, url = gsl.get_song_lyricsProx(song_title, artist)

    if isinstance(lyrics, basestring):
        bow = lb.lyrics_to_bow(lyrics)
        #return title + lyrics
        features = create_features(bow)
        tfidfv = joblib.load('pkldir/tfidf_txf.pkl')

        tfFeatures = tfidfv.transform(features)
        furrest = joblib.load('pkldir/forest785.pkl')
        prediction = furrest.predict(tfFeatures)

        return prediction + title + lyrics

    elif np.isnan(lyrics):
        return 'Couldn\'t find the lyrics.'
        #print 'Are these the right lyrics? \n %s' % (lyrics)
    else:
        return '...nothing'
Example #5
0
def predict_genre(song_title,artist=None):
	# check if we already have the lryics
	#dfLyricBow=
	#if 
	lyrics, title, url = gsl.get_song_lyricsProx(song_title,artist)
	
	if isinstance(lyrics,basestring):
		bow = lb.lyrics_to_bow(lyrics)
		#return title + lyrics
		features = create_features(bow)
		tfidfv = joblib.load('pkldir/tfidf_txf.pkl')

		tfFeatures = tfidfv.transform(features)
		furrest = joblib.load('pkldir/forest785.pkl')
		prediction = furrest.predict(tfFeatures)

		return prediction + title + lyrics 


	elif np.isnan(lyrics):
		return 'Couldn\'t find the lyrics.'
		#print 'Are these the right lyrics? \n %s' % (lyrics)
	else:
		return '...nothing'
Example #6
0
def stem_word(word):
    """Use modified Porter-Stemmer to stem a given word."""
    stemmed_word = list(ltb.lyrics_to_bow(word).keys())
    stemmed_word = stemmed_word[0]
    return stemmed_word
def stem_word(word):
    """Use modified Porter-Stemmer to stem a given word."""
    stemmed_word = list(ltb.lyrics_to_bow(word).keys())
    stemmed_word = stemmed_word[0]
    return stemmed_word