Genre Tree Provider


Get a list of genre via echonest and try to make a Tree out of them:

  • Genres:

    Melodic Death Metal
    Pagan Metal
    Japan Pop
  • Tree:

     +-- pop
     |    +-- japan
     +-- metal
          +-- death
          |    +-- melodic
          +-- pagan

This tree can be then used to map arbitrary genre names to a path in this tree. The advantage from this is that only paths (== a list of indices) through the tree can be saved, instead of whole genre strings. These indices can also be compared very easily.

With above’s example:

'Melodic death-metal' = metal -> death -> melodic (Path: 0, 1, 1, 0)
'Pagan Metal'         = metal -> pagan (Path: 0, 1, 0)
'Japan Pop Music'     = pop -> japan (Path: 0, 0, 0)

The actual Tree is of course a littler larger and gives you in most cases a path with 2-3 elements.


class munin.provider.genre.GenreTreeProvider(quality='all', **kwargs)[source]

Normalize a genre by matching it agains precalculated Tree of sub genres

Creates a GenreTreeProvider with a certain quality.

A GenreTreeProvider will try to normalize a genre by using a Tree of 705 single genres that will be matched with the input genre in a fast way.

The result will be a list of Paths. A Path is a tuple of indices, representing a possible way through the Tree. For debugging purpose you can use GenreTreeProvider.resolve_path() on the path to get the full genre back.

The Quality levels are:

  • all: Try to find all possible paths through the Tree, sorted

    by the first index (which is useful for comparing.)

  • single: Simply take the first possible path found. Fastest.

  • best_two: Like list, but also uses the reverse word list in a second try. Might give better results than ‘single’ at the cost of some speed.

Default is all.

This provider is reversible.

Parameters:quality (String) – One of all, best_two single [default: all]

Subclassed from Provider, will be called for you on the input.


Resolve a path like:

(197, 1, 0)


["metal", "death", "brutal"]

To get back the actual genre, do this:

>>> provider = GenreTreeProvider()
>>> ' '.join(reversed(provider.resolve_path((197, 1, 0))))
"brutal death metal"

or just use reverse().

Parameters:path (tuple of ints) – The path to resolve.
Returns:A list of subgenres ordered by specialization.
Return type:list of strings

Translate the paths in output_values back to genre strings.

Returns:A list of genre strings.
Return type:[str]

Table Of Contents

Related Topics

This Page

Useful links: