equal
deleted
inserted
replaced
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 |
9 |
9 |
10 // (1) Implement the function get_csv_url which takes an url-string |
10 // (1) Implement the function get_csv_url which takes an url-string |
11 // as argument and requests the corresponding file. The two urls |
11 // as argument and requests the corresponding file. The two urls |
12 // of interest are ratings_url and movies_url, which correspond |
12 // of interest are ratings_url and movies_url, which correspond |
13 // to CSV-files. |
13 // to CSV-files. |
116 // map and a movie_name as arguments. It calculates all the recommended |
116 // map and a movie_name as arguments. It calculates all the recommended |
117 // movies sorted according to the most frequently suggested movie(s) first. |
117 // movies sorted according to the most frequently suggested movie(s) first. |
118 def suggestions(recs: Map[String, List[String]], |
118 def suggestions(recs: Map[String, List[String]], |
119 mov_name: String) : List[String] = { |
119 mov_name: String) : List[String] = { |
120 val favs = favourites(recs, mov_name).flatten |
120 val favs = favourites(recs, mov_name).flatten |
121 val favs_counted = favs.groupBy(identity).mapValues(_.size).toList |
121 val favs_counted = favs.groupBy(identity).view.mapValues(_.size).toList |
122 val favs_sorted = favs_counted.sortBy(_._2).reverse |
122 val favs_sorted = favs_counted.sortBy(_._2).reverse |
123 favs_sorted.map(_._1) |
123 favs_sorted.map(_._1) |
124 } |
124 } |
125 |
125 |
126 // test cases |
126 // test cases |
168 //val all = for (name <- movie_names.map(_._1)) yield { |
168 //val all = for (name <- movie_names.map(_._1)) yield { |
169 // recommendations(ratings_map, movies_map, name) |
169 // recommendations(ratings_map, movies_map, name) |
170 //} |
170 //} |
171 |
171 |
172 // helper functions |
172 // helper functions |
173 //List().take(2 |
173 //List().take(2) |
174 //List(1).take(2) |
174 //List(1).take(2) |
175 //List(1,2).take(2) |
175 //List(1,2).take(2) |
176 //List(1,2,3).take(2) |
176 //List(1,2,3).take(2) |
177 |
177 |
178 //} |
178 } |
179 |
179 |
180 |
180 |