--- a/main_testing2/danube_test6.scala Sat Nov 28 15:58:36 2020 +0000
+++ b/main_testing2/danube_test6.scala Mon Nov 30 00:06:15 2020 +0000
@@ -3,20 +3,29 @@
// first test
+def urban_groupById(ratings: List[(String, String)],
+ m: Map[String, List[String]]) : Map[String, List[String]] = ratings match {
+ case Nil => m
+ case (id, mov) :: rest => {
+ val old_ratings = m.getOrElse (id, Nil)
+ val new_ratings = m + (id -> (mov :: old_ratings))
+ urban_groupById(rest, new_ratings)
+ }
+}
-def urban_groupById(ratings: List[(String, String)]) =
- ratings.groupBy(_._1).view.mapValues(_.map(_._2)).toMap
+//def urban_groupById(ratings: List[(String, String)]) =
+// ratings.groupBy(_._1).view.mapValues(_.map(_._2)).toMap
def urban_get_csv_file(name: String) : List[String] = {
import io.Source
import scala.util._
- val csv = Source.fromFile(name)
+ val csv = Source.fromFile(name)("ISO-8859-1")
csv.mkString.split("\n").toList.drop(1)
}
def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
for (cols <- lines.map(_.split(",").toList);
- if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))
+ if (cols(2).toInt >= 4)) yield (cols(0), cols(1))
}
def urban_process_movies(lines: List[String]) : List[(String, String)] = {
@@ -24,10 +33,10 @@
}
-val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
-val urban_movie_names = process_movies(urban_get_csv_file("movies.csv")).toMap
+val urban_good_ratings = urban_process_ratings(urban_get_csv_file("ratings.csv"))
+val urban_movie_names = urban_process_movies(urban_get_csv_file("movies.csv")).toMap
-val urban_ratings_map = urban_groupById(urban_good_ratings)
+val urban_ratings_map = urban_groupById(urban_good_ratings, Map())
assert((for (n <- List("1", "2", "3", "4", "5")) yield {
recommendations(urban_ratings_map, urban_movie_names, n).length