Ejemplo n.º 1
0
        public void TestFull()
        {
            var ratings = new StaticFloatRatings(2);

            Assert.AreEqual(0, ratings.Count);
            ratings.Add(1, 4, 0.3);
            Assert.AreEqual(1, ratings.Count);
            ratings.Add(1, 8, 0.2);
            Assert.AreEqual(2, ratings.Count);
            ratings.Add(2, 4, 0.2);
        }
Ejemplo n.º 2
0
        [Test()] public void TestMaxUserIDMaxItemID()
        {
            var ratings = new StaticFloatRatings(7);

            ratings.Add(1, 4, 0.3);
            ratings.Add(1, 8, 0.2);
            ratings.Add(2, 4, 0.2);
            ratings.Add(2, 2, 0.6);
            ratings.Add(2, 5, 0.4);
            ratings.Add(3, 7, 0.2);
            ratings.Add(6, 3, 0.3);

            Assert.AreEqual(6, ratings.MaxUserID);
            Assert.AreEqual(8, ratings.MaxItemID);
        }
Ejemplo n.º 3
0
        public void TestRemoveItem()
        {
            var ratings = new StaticFloatRatings(7);

            ratings.Add(1, 4, 0.3);
            ratings.Add(1, 8, 0.2);
            ratings.Add(2, 4, 0.2);
            ratings.Add(2, 2, 0.6);
            ratings.Add(2, 5, 0.4);
            ratings.Add(3, 4, 0.2);
            ratings.Add(3, 3, 0.3);

            Assert.AreEqual(7, ratings.Count);
            ratings.RemoveItem(4);
        }
Ejemplo n.º 4
0
        public void TestRemoveAt()
        {
            var ratings = new StaticFloatRatings(8);

            ratings.Add(1, 4, 0.3);
            ratings.Add(1, 8, 0.2);
            ratings.Add(2, 4, 0.2);
            ratings.Add(2, 2, 0.6);
            ratings.Add(2, 5, 0.4);
            ratings.Add(3, 7, 0.2);
            ratings.Add(3, 3, 0.3);
            ratings.Add(6, 3, 0.3);

            Assert.AreEqual(8, ratings.Count);
            ratings.RemoveAt(ratings.GetIndex(2, 5));
        }
Ejemplo n.º 5
0
        /// <summary>Read in static rating data from a TextReader</summary>
        /// <param name="reader">the <see cref="TextReader"/> to read from</param>
        /// <param name="size">the number of ratings in the file</param>
        /// <param name="user_mapping">mapping object for user IDs</param>
        /// <param name="item_mapping">mapping object for item IDs</param>
        /// <param name="rating_type">the data type to be used for storing the ratings</param>
        /// <returns>the rating data</returns>
        static public IRatings Read(TextReader reader, int size,
                                    IEntityMapping user_mapping, IEntityMapping item_mapping,
                                    RatingType rating_type)
        {
            IRatings ratings;

            if (rating_type == RatingType.BYTE)
            {
                ratings = new StaticByteRatings(size);
            }
            else if (rating_type == RatingType.FLOAT)
            {
                ratings = new StaticFloatRatings(size);
            }
            else
            {
                ratings = new StaticRatings(size);
            }

            var    split_chars = new char[] { '\t', ' ', ',' };
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }

                string[] tokens = line.Split(split_chars);

                if (tokens.Length < 3)
                {
                    throw new IOException("Expected at least three columns: " + line);
                }

                int    user_id = user_mapping.ToInternalID(int.Parse(tokens[0]));
                int    item_id = item_mapping.ToInternalID(int.Parse(tokens[1]));
                double rating  = double.Parse(tokens[2], CultureInfo.InvariantCulture);

                ratings.Add(user_id, item_id, rating);
            }
            return(ratings);
        }
Ejemplo n.º 6
0
        [Test()] public void TestAddRating()
        {
            var ratings = new StaticFloatRatings(7);

            ratings.Add(1, 4, 0.3f);
            Assert.AreEqual(1, ratings.Count);
            ratings.Add(1, 8, 0.2f);
            Assert.AreEqual(2, ratings.Count);
            ratings.Add(2, 4, 0.2f);
            ratings.Add(2, 2, 0.6f);
            ratings.Add(2, 5, 0.4f);
            ratings.Add(3, 7, 0.2f);
            ratings.Add(6, 3, 0.3f);

            Assert.AreEqual(0.4f, ratings.Get(2, 5));
            Assert.AreEqual(0.3f, ratings.Get(1, 4));
            Assert.AreEqual(0.3f, ratings.Get(6, 3));
            Assert.AreEqual(7, ratings.Count);
        }
Ejemplo n.º 7
0
        [Test()] public void TestGet()
        {
            var ratings = new StaticFloatRatings(8);

            ratings.Add(1, 4, 0.3f);
            ratings.Add(1, 8, 0.2f);
            ratings.Add(2, 4, 0.2f);
            ratings.Add(2, 2, 0.6f);
            ratings.Add(2, 5, 0.4f);
            ratings.Add(3, 4, 0.2f);
            ratings.Add(3, 3, 0.3f);
            ratings.Add(6, 3, 0.3f);

            // test Get
            Assert.AreEqual(0.2f, ratings.Get(2, 4));
            Assert.AreEqual(0.3f, ratings.Get(3, 3));
            Assert.AreEqual(0.3f, ratings.Get(6, 3));

            // test index[,]
            Assert.AreEqual(0.3f, ratings[1, 4]);
            Assert.AreEqual(0.2f, ratings[1, 8]);
            Assert.AreEqual(0.6f, ratings[2, 2]);
        }