solutions2/danube.scala
changeset 284 9a04eb6a2291
parent 209 40bdf9064e13
child 325 ca9c1cf929fa
equal deleted inserted replaced
283:ef5f62bf5987 284:9a04eb6a2291
     1 // Part 2 and 3 about Movie Recommendations 
     1 // Core Part about Movie Recommendations 
     2 // at Danube.co.uk
     2 // at Danube.co.uk
     3 //===========================================
     3 //========================================
     4 
     4 
     5 import io.Source
     5 import io.Source
     6 import scala.util._
     6 import scala.util._
     7 
     7 
     8 object CW7b { // for purposes of generating a jar
     8 object CW7b { // for purposes of generating a jar
   115 // map and a movie_name as arguments. It calculates all the recommended
   115 // map and a movie_name as arguments. It calculates all the recommended
   116 // movies sorted according to the most frequently suggested movie(s) first.
   116 // movies sorted according to the most frequently suggested movie(s) first.
   117 def suggestions(recs: Map[String, List[String]], 
   117 def suggestions(recs: Map[String, List[String]], 
   118                     mov_name: String) : List[String] = {
   118                     mov_name: String) : List[String] = {
   119   val favs = favourites(recs, mov_name).flatten
   119   val favs = favourites(recs, mov_name).flatten
   120   val favs_counted = favs.groupBy(identity).mapValues(_.size).toList
   120   val favs_counted = favs.groupBy(identity).view.mapValues(_.size).toList
   121   val favs_sorted = favs_counted.sortBy(_._2).reverse
   121   val favs_sorted = favs_counted.sortBy(_._2).reverse
   122   favs_sorted.map(_._1)
   122   favs_sorted.map(_._1)
   123 }
   123 }
   124 
   124 
   125 // test cases
   125 // test cases