DEV Community

victorfatala
victorfatala

Posted on

Rock Music Recommendation Software

(before anything, I really just want to sat that I am not a professional, or even have many years of experience in the area, so be concerned that there may be some mistakes in my explanation. I am posting this blog as a kind of exercise: explaining what I've built and how I built it, while using simple terms. In a way that anyone can understand! So feel free to make corrections and send me a feedback in the comments :)

A Brief Introduction...

Hello! I started this project with the simple idea of making an easy Python software that was capable of creating a good interface for users to find what they are looking for in a spreadsheet. This could be any kind of spreadsheet, but I decided to make it πŸ’«Rock 'n RollπŸ’« themed!πŸ€˜πŸ»πŸ§‘πŸ»β€πŸŽ€

Image description

And if matching the user input to the closest value in the spreadsheet wasn't enough, I have also included a sort of "autocomplete" search algorithm:

Image description

Now you may be wondering: why a spreadsheet? Well, from all the possibilities, it seemed to me that spreadsheets would be both: a good file type to practice (working with .CSV), and the simplest way for anyone to try this software on their own (as basically anyone knows how to use Excel or Google Sheets). 🧠

Gathering Data

To able to achieve this software I firstly needed to convert my spreadsheet into a more programmable kind of data. So I decided to set up a function to collect all the data stored in my .CSV file and organize it in a Tree Node structure. This made things much easier to manage since I was already thinking of something like:

  • Genres are composed of Artists. πŸ‘―
  • Artists (usually) produce Albums. πŸ’Ώ
  • And Albums are a collection of Songs. 🎢

Which, in a Tree, is basically:

Tree Structure example

My generate_tree() function is the one responsible for setting each value in its specific position in the Tree. 🌳

You can see the whole Tree generated by typing 'Library':

Image description

Once we have our Tree, all we need to do is search in it for the value asked by the user. Which takes us to...

Tree Search

For this project I decided to implement a Breadth-First Search algorithm. This works basically by following a FIFO (First In First Out) order to compare each Node in our Tree with the goal value (the value asked by the user). By using this FIFO ordering, we end up looking at each layer of the Tree before moving to the layer below:

Image description

If the current Node is equal to the goal Node β€” πŸ’₯ BOOM!πŸ’₯ β€” we got it! All we need to do is return the path to this Node (which we save at each step, using some loops). Otherwise, if we get to the end of the Tree without a match πŸ’” we return an empty path.

Interface

And, with all the values returned by these functions, the only thing left to do is present them to the user. πŸ‘€

Just mix some conditions and String concatenation with all these and tah-dah: πŸͺ„

https://github.com/vifatala/Rock-Music-Recommendation-Software/blob/main/tree_search.py

Top comments (0)