Rock Music Recommendation Software
victorfatala
Posted on September 30, 2023
(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!π€π»π§π»βπ€
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:
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:
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':
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:
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
Posted on September 30, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.