コード例 #1
0
ファイル: UserItem.cs プロジェクト: WisonHuang/WrapRec
 public UserItem(User user, Item item)
     : this()
 {
     User = user;
     Item = item;
 }
コード例 #2
0
ファイル: UserItem.cs プロジェクト: WisonHuang/WrapRec
 public UserItem(string userId, string itemId)
     : this()
 {
     User = new User(userId);
     Item = new Item(itemId);
 }
コード例 #3
0
 public PositiveFeedback(User user, Item item)
     : base(user, item)
 {
 }
コード例 #4
0
ファイル: ItemRating.cs プロジェクト: WisonHuang/WrapRec
 public ItemRating(User user, Item item, float rating)
     : base(user, item)
 {
     Rating = rating;
     Domain = CrossDomainDataContainer.GetDefualtDomain();
 }
コード例 #5
0
        private string BuildUserCrossDomainFeatureVector(User user)
        {
            string extendedVector = "";

            Func<ItemRating, bool> checkActivation = r => r.Domain.IsActive == true; //r.IsActive == true;

            var domainRatings = user.Ratings.Where(checkActivation).GroupBy(r => r.Domain.Id);
            int userAuxDomains = user.Ratings.Select(r => r.Domain.Id).Distinct().Where(d => d != TargetDomain.Id).Count();

            int perDomainRatings;
            if (userAuxDomains > 0)
                perDomainRatings = (int)Math.Ceiling((double)NumAuxRatings / userAuxDomains);
            else
                perDomainRatings = 0;

            var avgUserRating = user.Ratings.Average(r => r.Rating);

            int take = perDomainRatings;
            int remain = NumAuxRatings;

            foreach (var d in domainRatings)
            {
                if (d.Key != TargetDomain.Id)
                {
                    int ratingCount = d.Count();
                    string domainExtendedVector = "";

                    var ratings = d.OrderByDescending(r => r.Item.Ratings.Count).Take(take);

                    if (ratings.Count() > 0)
                    {
                        domainExtendedVector = ratings
                            .Select(dr => string.Format("{0}:{1:0.0000}", Mapper.ToInternalID(dr.Item.Id), (double)(dr.Rating - avgUserRating) / 4 + 1)) // dr.Rating / ratingCount))
                            .Aggregate((cur, next) => cur + " " + next);
                    }

                    if (!String.IsNullOrEmpty(domainExtendedVector.TrimEnd(' ')))
                        extendedVector += " " + domainExtendedVector;

                    remain = remain - perDomainRatings;
                    if (remain > 0)
                        take = perDomainRatings;
                    else
                        take = 0;
                }
            }

            return extendedVector;
        }
コード例 #6
0
        public ItemRating CreateItemRating(string relationId, double? timestamp, string properties, string linkedEntities)
        {
            var ir = new ItemRating();
            ir.Id = relationId;
            ir.Timestamp = timestamp;

            var jProperties = JObject.Parse(properties);

            // add general properties
            jProperties.Properties().ToList().ForEach(p => ir.AddProperty(p.Name, p.Value.ToString()));

            // try to extract rating from properties
            try
            {
                ir.Rating = float.Parse(jProperties["rating"].ToString());
            }
            catch (Exception)
            {
                throw new Exception("Can not find / parse rating in the relation.");
            }

            // parse linked entities
            var jLinkedEntities = JObject.Parse(linkedEntities);

            // user
            string user = jLinkedEntities["subject"].ToString();

            if (!user.Contains("user"))
                throw new Exception("Expect subject of type user in the linked entities.");

            string userId = user.Substring(user.IndexOf(':') + 1);

            User u;

            if (!Users.TryGetValue(userId, out u))
            {
                Console.WriteLine(string.Format("User with id {0} is not defined in the entities file.", userId));
                u = new User(userId);
            }

            u.Ratings.Add(ir);

            // item
            string item = jLinkedEntities["object"].ToString();

            if (!item.Contains("movie") && !item.Contains("item"))
                throw new Exception("Expect object of type movie or item in the linked entities.");

            string itemId = item.Substring(item.IndexOf(':') + 1);

            Item i;

            if (!Items.TryGetValue(itemId, out i))
            {
                Console.WriteLine(string.Format("Item with id {0} is not defined in the entities file.", itemId));
                i = new Item(itemId);
            }

            i.Ratings.Add(ir);

            ir.User = u;
            ir.Item = i;

            return ir;
        }
コード例 #7
0
        public User CreateUser(string userId, double? timestamp, string properties)
        {
            var u = new User(userId);

            u.Timestamp = timestamp;

            var jObject = JObject.Parse(properties);
            jObject.Properties().ToList().ForEach(p => u.AddProperty(p.Name, p.Value.ToString()));

            return u;
        }