diff -r b17a98b0c52f -r e48ea8300b2d main_solution2/danube.scala --- a/main_solution2/danube.scala Sat Nov 06 00:06:39 2021 +0000 +++ b/main_solution2/danube.scala Mon Nov 08 00:17:50 2021 +0000 @@ -3,7 +3,7 @@ //======================================== -object CW7b { // for purposes of generating a jar +object M2 { // for purposes of generating a jar import io.Source import scala.util._ @@ -57,11 +57,6 @@ //good_ratings.length //48580 //movie_names.length // 9742 -//============================================== -// Do not change anything below, unless you want -// to submit the file for the advanced part 3! -//============================================== - // (3) Implement a grouping function that calulates a map // containing the userIds and all the corresponding recommendations @@ -162,35 +157,5 @@ // recommendations(ratings_map, movies_map, "4") // => Nil (there are three ratings for this movie in ratings.csv but they are not positive) -// (7) Calculate the recommendations for all movies according to -// what the recommendations function in (6) produces (this -// can take a few seconds). Put all recommendations into a list -// (of strings) and count how often the strings occur in -// this list. This produces a list of string-int pairs, -// where the first component is the movie name and the second -// is the number of how many times they were recommended. -// Sort all the pairs according to the number -// of times they were recommended (most recommended movie name -// first). - -def occurrences(xs: List[String]): List[(String, Int)] = - for (x <- xs.distinct) yield (x, xs.count(_ == x)) - -def most_recommended(recs: Map[String, List[String]], - movs: Map[String, String]) : List[(String, Int)] = { - val all = (for (name <- movs.toList.map(_._1)) yield { - recommendations(recs, movs, name) - }).flatten - val occs = occurrences(all) - occs.sortBy(_._2).reverse -} - - -//most_recommended(ratings_map, movies_map).take(3) -// => -// List((Matrix,698), -// (Star Wars: Episode IV - A New Hope (1977),402), -// (Jerry Maguire (1996),382)) - }