I have a list of messy titles (lets say 1000 of them). These titles I want to analyze for "keywords" that match a small number of genres that I have created (the titles arent a model, but the genres are).
For example, say the first title string is "awesome playlist of house, EDM and ambient"
Now, say I also have 15 Genres, each with an attribute name
My end goal is I want to assign genres to that title string. This is easy enough by doing some string normalization, and then using .include?
But it doesnt help if there are synonyms. For example, my @genre.name is called chill, which SHOULD apply to ambient on the string above. Likewise, my @genre.name for dance music is called dance, and should include EDM in the string above (edm = electronic dance music)
So what I'd love to do is for each genre add in 10 or so synonyms so it can check for those as well.
The problem is I'm not sure how to go about doing this in the loop.. I guess a loop inside a loop?
This is my code for a 'single level', without synonyms
def determine_genres(title)
relevant_genres = []
@genres.each do |genre|
if normalize_string(title).include? normalize_string(genre.name)
relevant_genres << genre.id
end
end
relevant_genres
end