Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mapper_predict_songs(song: Int, similar_songs: Iterable[(Int,Int,Double)]) : Iterable[(Int,Double)] = {
- val result = new ListBuffer[(Int,Double)]
- val sim_songs = new scala.collection.mutable.HashMap[Int,Double]()
- val playlists = new scala.collection.mutable.HashMap[Int,scala.collection.mutable.Set[Int]]
- for(tuple <- similar_songs){
- val s = tuple._1
- val u = tuple._2
- val n = tuple._3
- if(!playlists.contains(u))
- playlists(u) = new scala.collection.mutable.HashSet[Int]()
- playlists(u) += s
- sim_songs(s) = sim_songs.getOrElse(s, 0.0) + 1.0/n
- }
- for(tuple <- sim_songs){
- val s = tuple._1
- val c = tuple._2
- for(uAndp <- playlists){
- if(!uAndp._2.contains(s)){
- result += ((s,c))
- }
- }
- }
- result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement