Esempio n. 1
0
def _search_tokens(song_name, song_list):
    """Search song in the cache based on simple each word matching."""
    song_name = remove_punct(
        remove_stopwords(
            remove_multiple_spaces(unidecode(song_name)).lower()
        ))
    tokens1 = song_name.split()
    cached_songs = song_list

    res = []
    for song in cached_songs:
        song_back = song
        name = song.track_name.lower()
        # If there is a part like (featuring ..) or any extra data
        # we should remove it as it doesn't aid the search
        name = re.sub(r'\([^)]*\)', '', name)
        name = remove_stopwords(name)
        name = remove_punct(name)
        name = remove_multiple_spaces(name)
        name = unidecode(name)
        tokens2 = name.split()
        match = check_keywords(tokens1, tokens2)
        if match:
            dist = compute_jaccard(tokens1, tokens2)
            if dist >= preconfig.CONFIG().SEARCH_SENSITIVITY:
                res.append((song_back, dist))
    res = sorted(res, key=lambda x: x[1], reverse=True)

    # Return w/o the dist values
    for i in range(0, len(res)):
        res[i] = res[i][0]
    return res
Esempio n. 2
0
def _search_tokens(song_name, song_list):
    """Search song in the cache based on simple each word matching."""
    song_name = remove_punct(
        remove_stopwords(remove_multiple_spaces(unidecode(song_name)).lower()))
    tokens1 = song_name.split()
    cached_songs = song_list

    res = []
    for song in cached_songs:
        song_back = song
        name = song.track_name.lower()
        name = remove_punct(name)
        name = remove_multiple_spaces(name)
        name = unidecode(name)
        tokens2 = name.split()
        match = check_keywords(tokens1, tokens2)
        if match:
            dist = compute_jaccard(tokens1, tokens2)
            if dist >= 1:
                res.append((song_back, dist))
    res = sorted(res, key=lambda x: x[1], reverse=True)

    # Return w/o the dist values
    for i in range(0, len(res)):
        res[i] = res[i][0]
    return res
Esempio n. 3
0
    def _search_tokens(self, song_name):
        """Search song in the cache based on each word matching."""
        song_name = remove_stopwords(remove_multiple_spaces(song_name).lower())
        tokens1 = song_name.split()
        cached_songs = self.list_mp3()

        res = []
        for song in cached_songs:
            name = os.path.splitext(song)[0].lower()
            title = name
            name = remove_punct(name)
            name = remove_multiple_spaces(name)
            tokens2 = name.split()
            dist = compute_jaccard(tokens1, tokens2)
            res.append((song_name, song, title, dist))
        res = sorted(res, key=lambda x: x[-1], reverse=True)
        if res and res[0][-1] > 0:
            return res[0][2], self.get_full_location(res[0][1])
        else:
            return None