Exemplo n.º 1
0
 /// <summary>
 /// Create a point from a sparse set of (x,y) pairs where the x is the MovieId minus one (to make it zero-based) and the
 /// y is the Rating.
 /// </summary>
 /// <param name="dimensions">Total number of dimensions, including those which are missing a value, hence have
 /// no corresponding pair (MovieId,Rating).</param>
 /// <returns>A new HyperContrastedPoint or SparsePoint, whose UniqueId is the ReviewerId.</returns>
 public UnsignedPoint ToPoint(int dimensions)
 {
     if (Point == null)
     {
         var useHyperContrastedPoints = true;
         if (useHyperContrastedPoints)
         {
             Point = new HyperContrastedPoint(
                 MovieIds.Select(movieId => movieId - 1).ToList(),
                 Ratings.Select(rating => (uint)rating).ToList(),
                 dimensions,
                 new[] { 0U, 6U },
                 ReviewerId
                 );
         }
         else
         {
             Point = new SparsePoint(
                 MovieIds.Select(movieId => movieId - 1).ToList(),
                 Ratings.Select(rating => (uint)rating).ToList(),
                 dimensions,
                 0U,
                 ReviewerId
                 );
         }
     }
     return(Point);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Get the rating (1 to 5) given by this reviewer for the given movie, if known, or null.
        /// </summary>
        /// <param name="movieId">Movie whose rating is sought.</param>
        /// <returns>A one to five rating, or null, if this reviewer has not reviewed the movie.</returns>
        public int?Review(int movieId)
        {
            var position = MovieIds.BinarySearch(movieId);

            if (position >= 0)
            {
                return(Ratings[position]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Add a new review and maintain the MovieIds in sorted order.
 /// </summary>
 /// <param name="movieId">Movie that weas reviewed.
 /// If this reviewer already has a review for the movie, replace it with the new rating.
 /// </param>
 /// <param name="rating">Rating of the movie, from one to five.</param>
 public void Add(int movieId, uint rating)
 {
     if (Count == 0 || MovieIds.Last() < movieId)
     {
         MovieIds.Add(movieId);
         Ratings.Add((byte)rating);
     }
     else
     {
         var position = MovieIds.BinarySearch(movieId);
         if (position >= 0)
         {
             Ratings[position] = (byte)rating;
         }
         else
         {
             // It is not possible for the position to be after the end of the array,
             // because we already tested for the case where the movieId is larger than the last value.
             position = ~position;
             MovieIds.Insert(position, movieId);
             Ratings.Insert(position, (byte)rating);
         }
     }
 }