main_testing2/danube.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 28 Nov 2020 15:37:30 +0000
changeset 376 6cc36d0ef79e
parent 347 4de31fdc0d67
child 379 5616b45d656f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     1
// Core Part about Movie Recommendations 
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
// at Danube.co.uk
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
//===========================================
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
import io.Source
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
import scala.util._
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
     8
object CW7b { // for purposes of generating a jar
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
     9
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
// (1) Implement the function get_csv_url which takes an url-string
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
//     as argument and requests the corresponding file. The two urls
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
//     of interest are ratings_url and movies_url, which correspond 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
//     to CSV-files.
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    14
//     The function should ReTurn the CSV file appropriately broken
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
//     up into lines, and the first line should be dropped (that is without
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    16
//     the header of the CSV file). The result is a list of strings (lines
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
//     in the file).
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
def get_csv_url(url: String) : List[String] = {
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    20
  val csv = Source.fromURL(url)("ISO-8859-1")
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    21
  csv.mkString.split("\n").toList.drop(1)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
val ratings_url = """https://nms.kcl.ac.uk/christian.urban/ratings.csv"""
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
val movies_url = """https://nms.kcl.ac.uk/christian.urban/movies.csv"""
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    27
// test cases
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    28
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    29
//val ratings = get_csv_url(ratings_url)
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    30
//val movies = get_csv_url(movies_url)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
//ratings.length  // 87313
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
//movies.length   // 9742
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    35
// (2) Implement two functions that process the CSV files. The ratings
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
//     function filters out all ratings below 4 and ReTurns a list of 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
//     (userID, movieID) pairs. The movies function just ReTurns a list 
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    38
//     of (movieId, title) pairs.
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
def process_ratings(lines: List[String]) : List[(String, String)] = {
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    42
  for (cols <- lines.map(_.split(",").toList); 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    43
       if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))  
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
def process_movies(lines: List[String]) : List[(String, String)] = {
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    47
  for (cols <- lines.map(_.split(",").toList)) yield (cols(0), cols(1))  
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    50
// test cases
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    52
//val good_ratings = process_ratings(ratings)
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    53
//val movie_names = process_movies(movies)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
//good_ratings.length   //48580
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
//movie_names.length    // 9742
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    58
//==============================================
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    59
// Do not change anything below, unless you want 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    60
// to submit the file for the advanced part 3!
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    61
//==============================================
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    62
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    63
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    64
// (3) Implement a grouping function that calulates a map
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    65
//     containing the userIds and all the corresponding recommendations 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    66
//     (list of movieIds). This  should be implemented in a tail
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    67
//     recursive fashion, using a map m as accumulator. This map
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    68
//     is set to Map() at the beginning of the claculation.
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    69
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    70
def groupById(ratings: List[(String, String)], 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    71
              m: Map[String, List[String]]) : Map[String, List[String]] = ratings match {
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    72
  case Nil => m
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    73
  case (id, mov) :: rest => {
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    74
    val old_ratings = m.getOrElse (id, Nil)
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    75
    val new_ratings = m + (id -> (mov :: old_ratings))
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    76
    groupById(rest, new_ratings)
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    77
  }
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    78
}
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    79
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    80
//
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    81
//val ls = List(("1", "a"), ("2", "a"), ("1", "c"), ("2", "a"), ("1", "c"))
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    82
//
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    83
//val m = groupById(ls, Map())
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    84
//
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    85
//m.getOrElse("1", Nil).count(_ == "c") // => 2
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    86
//m.getOrElse("1", Nil).count(_ == "a") // => 1
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    87
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    88
// test cases
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    89
//val ratings_map = groupById(good_ratings, Map())
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    90
//groupById(good_ratings, Map()).get("214")
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    91
//groupById(good_ratings, Map()).toList.minBy(_._2.length)
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    92
//val movies_map = movie_names.toMap
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    93
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    94
//ratings_map.get("414").get.map(movies_map.get(_)) // most prolific recommender with 1227 positive ratings
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    95
//ratings_map.get("474").get.map(movies_map.get(_)) // second-most prolific recommender with 787 positive ratings
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
    96
//ratings_map.get("214").get.map(movies_map.get(_)) // least prolific recommender with only 1 positive rating
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   100
//(4) Implement a function that takes a ratings map and a movie_name as argument.
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   101
// The function calculates all suggestions containing
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   102
// the movie mov in its recommendations. It ReTurns a list of all these
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   103
// recommendations (each of them is a list and needs to have mov deleted, 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   104
// otherwise it might happen we recommend the same movie).
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   106
def favourites(m: Map[String, List[String]], mov: String) : List[List[String]] = 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   107
  (for (id <- m.keys.toList;
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   108
        if m(id).contains(mov)) yield m(id).filter(_ != mov))
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   112
// test cases
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
// movie ID "912" -> Casablanca (1942)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
//          "858" -> Godfather
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
//          "260" -> Star Wars: Episode IV - A New Hope (1977)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
//favourites(ratings_map, "912").length  // => 80
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
// That means there are 80 users that recommend the movie with ID 912.
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
// Of these 80  users, 55 gave a good rating to movie 858 and
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
// 52 a good rating to movies 260, 318, 593.
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   124
// (5) Implement a suggestions function which takes a rating
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   125
// map and a movie_name as arguments. It calculates all the recommended
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   126
// movies sorted according to the most frequently suggested movie(s) first.
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
   127
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   128
// needed in Scala 2.13.
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   129
 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   130
def mapValues[S, T, R](m: Map[S, T], f: T => R) =
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   131
  m.map { case (x, y) => (x, f(y)) }
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
   132
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
def suggestions(recs: Map[String, List[String]], 
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   134
                    mov_name: String) : List[String] = {
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   135
  val favs = favourites(recs, mov_name).flatten
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   136
  val favs_counted = mapValues(favs.groupBy(identity), (v:List[String]) => v.size).toList
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   137
  val favs_sorted = favs_counted.sortBy(_._2).reverse
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   138
  favs_sorted.map(_._1)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   141
// check
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   142
// groupMap is equivalent to groupBy(key).mapValues(_.map(f))
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 249
diff changeset
   143
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   144
// test cases
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
//suggestions(ratings_map, "912")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
//suggestions(ratings_map, "912").length  
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
// => 4110 suggestions with List(858, 260, 318, 593, ...)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
//    being the most frequently suggested movies
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   151
// (6) Implement recommendations functions which generates at most
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   152
// *two* of the most frequently suggested movies. It Returns the 
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   153
// actual movie names, not the movieIDs.
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
def recommendations(recs: Map[String, List[String]],
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   156
                   movs: Map[String, String],
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   157
                   mov_name: String) : List[String] =
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   158
  suggestions(recs, mov_name).take(2).map(movs.get(_).get)                 
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
// testcases
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   162
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
// recommendations(ratings_map, movies_map, "912")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
//   => List(Godfather, Star Wars: Episode IV - A NewHope (1977))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
//recommendations(ratings_map, movies_map, "260")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
//   => List(Star Wars: Episode V - The Empire Strikes Back (1980), 
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
//           Star Wars: Episode VI - Return of the Jedi (1983))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
// recommendations(ratings_map, movies_map, "2")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
//   => List(Lion King, Jurassic Park (1993))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
// recommendations(ratings_map, movies_map, "0")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
//   => Nil
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
// recommendations(ratings_map, movies_map, "1")
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
//   => List(Shawshank Redemption, Forrest Gump (1994))
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
// recommendations(ratings_map, movies_map, "4")
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   180
//   => Nil  (there are three ratings fro this movie in ratings.csv but they are not positive)     
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   183
// If you want to calculate the recomendations for all movies.
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 326
diff changeset
   184
// Will take a few seconds calculation time.
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
//val all = for (name <- movie_names.map(_._1)) yield {
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
//  recommendations(ratings_map, movies_map, name)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
//}
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
// helper functions
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   191
//List().take(2)
211
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
//List(1).take(2)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
//List(1,2).take(2)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
//List(1,2,3).take(2)
092e0879a5ae updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   196
}