コード例 #1
0
        public virtual string GetLibFmFeatureVector(Feedback feedback)
        {
            string featVector;

            if (feedback is Rating)
            {
                featVector = ((Rating)feedback).Value + " " + GetLibFmFeatureVector(feedback.User.Id, feedback.Item.Id);
            }
            else
            {
                featVector = (feedback.FeedbackType == FeedbackType.Positive ? "1 " : "-1 ") + GetLibFmFeatureVector(feedback.User.Id, feedback.Item.Id);
            }

            _numValues += 2;

            var feedbackAttrs = feedback.Attributes.Values.Where(a => FeedbackAttributes.Contains("all") || FeedbackAttributes.Contains(a.Name));
            var itemAttrs     = feedback.Item.Attributes.Values.Where(a => ItemAttributes.Contains("all") || ItemAttributes.Contains(a.Name));
            var userAttrs     = feedback.User.Attributes.Values.Where(a => UserAttributes.Contains("all") || UserAttributes.Contains(a.Name));

            foreach (var attr in feedbackAttrs.Union(userAttrs).Union(itemAttrs))
            {
                var feat = TranslateAttribute(attr);
                if (feat != null)
                {
                    featVector += string.Format(" {0}:{1}", feat.Item1, feat.Item2);
                    _numValues++;
                }
            }

            return(featVector);
        }
コード例 #2
0
        public virtual ItemAttribute GetValue(ItemAttributes list, ItemAttribute ia)
        {
            ItemAttributes list2 = new ItemAttributes(ia.Cxt, ia.TableName, ia.ItemID, ia.AttributeID);

            foreach (ListItem li in Items)
            {
                bool contains = list2.Contains(ia.AttributeID, li.Value);

                if (li.Selected && !contains) // selected but no in db
                {
                    ItemAttribute.AddToList(list, ia.ItemID, ia.AttributeID, li.Value);
                }
                else if (!li.Selected && contains) // not selected but in db
                {
                    ItemAttribute iax = list2.Get(ia.AttributeID, li.Value);

                    list.DataTable.ImportRow(iax.DataRow);

                    DataRow row = list.DataTable.Rows[list.DataTable.Rows.Count - 1];

                    row.AcceptChanges();

                    row.Delete(); // mark deleted
                }
            }

            return null;
        }