public virtual SvmNode[] GetSvmNode(ItemRating rating)
        {
            var svmNode = new SvmNode[2] {
                new SvmNode(Mapper.ToInternalID(rating.User.Id), 1),
                new SvmNode(Mapper.ToInternalID(rating.Item.Id + rating.Domain.Id), 1)
            };

            return(svmNode);
        }
        public override string GetLibFmFeatureVector(ItemRating rating)
        {
            string baseVector = base.GetLibFmFeatureVector(rating);

            string conns = rating.User.GetProperty("Connections");

            if (string.IsNullOrEmpty(conns))
                return baseVector;

            string extension = UseConnectionStrength ? GetImplicitConnectionsVector(conns) : GetExplicitConnectionsVector(conns);

            return baseVector + " " + extension;
        }
示例#3
0
        public override string GetLibFmFeatureVector(ItemRating rating)
        {
            string baseVector = base.GetLibFmFeatureVector(rating);

            string conns = rating.User.GetProperty("Connections");

            if (string.IsNullOrEmpty(conns))
            {
                return(baseVector);
            }

            string extension = UseConnectionStrength ? GetImplicitConnectionsVector(conns) : GetExplicitConnectionsVector(conns);

            return(baseVector + " " + extension);
        }
        public override string GetLibFmFeatureVector(ItemRating rating)
        {
            // format:
            // rating uid:1 iid: 1 ai1: 0.5 ai2: 0.3 bi1: 0.1 bi2: 0.7

            string baseFeatVector     = base.GetLibFmFeatureVector(rating);
            string userExtendedVector = "";

            if (!_userCrossDomainFeatureVector.TryGetValue(rating.User.Id, out userExtendedVector))
            {
                userExtendedVector = BuildUserCrossDomainFeatureVector(rating.User);
                _userCrossDomainFeatureVector.Add(rating.User.Id, userExtendedVector);
            }

            return(baseFeatVector + userExtendedVector);
        }
        public override string GetLibFmFeatureVector(ItemRating rating)
        {
            // format:
            // rating uid:1 iid: 1 ai1: 0.5 ai2: 0.3 bi1: 0.1 bi2: 0.7

            string baseFeatVector = base.GetLibFmFeatureVector(rating);
            string userExtendedVector = "";

            if (!_userCrossDomainFeatureVector.TryGetValue(rating.User.Id, out userExtendedVector))
            {
                userExtendedVector = BuildUserCrossDomainFeatureVector(rating.User);
                _userCrossDomainFeatureVector.Add(rating.User.Id, userExtendedVector);
            }

            return baseFeatVector + userExtendedVector;
        }
        public override LibSvm.SvmNode[] GetSvmNode(ItemRating rating)
        {
            int followersCount = _container.Tweets[rating].FollowersCount;
            double followersFeature = followersCount > 1000 ? 1.0 : (double)followersCount / 1000;

            int friendsCount = _container.Tweets[rating].FriendsCount;
            double friendsFeature = friendsCount > 1000 ? 1.0 : (double)friendsCount / 1000;

            var svmNode = new SvmNode[6] {
                //new SvmNode(Mapper.ToInternalID("RetweetCount"), _container.Tweets[rating].RetweetCount),
                new SvmNode(Mapper.ToInternalID("Rating"), rating.Rating),
                new SvmNode(Mapper.ToInternalID("FollowersCount"),  followersFeature),
                new SvmNode(Mapper.ToInternalID("FriendsCount"),  friendsFeature),
                new SvmNode(Mapper.ToInternalID(rating.User.Id), 1),
                new SvmNode(Mapper.ToInternalID(rating.Item.Id + rating.Domain.Id), 1),
                new SvmNode(Mapper.ToInternalID(_container.Tweets[rating].MovieUrl), 1),
            };

            return svmNode;
        }
示例#7
0
 public virtual string GetLibFmFeatureVector(ItemRating rating)
 {
     return(string.Format("{0} {1}:1 {2}:1", rating.Rating, Mapper.ToInternalID(rating.User.Id), Mapper.ToInternalID(rating.Item.Id)));
 }
        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;
        }
示例#9
0
 public virtual string GetLibFmFeatureVector(ItemRating rating)
 {
     return string.Format("{0} {1}:1 {2}:1", rating.Rating, Mapper.ToInternalID(rating.User.Id), Mapper.ToInternalID(rating.Item.Id));
 }