예제 #1
0
        public double rec_Degree; // 该项目所对应的推荐度

        // 排序算法
        public int CompareTo(object other)
        {
            RecItemid_Degree otherTemperature = other as RecItemid_Degree;

            if (this.rec_Degree == otherTemperature.rec_Degree)
            {
                return(0);
            }
            if (this.rec_Degree < otherTemperature.rec_Degree)
            {
                return(1);
            }
            return(-1);
        }
예제 #2
0
        /// <summary>
        /// 根据用户支持的关联规则得到依据推荐度排序的推荐项目
        /// </summary>
        /// <param name="Supp_AssRules">用户所支持的关联规则集合</param>
        /// <param name="userid">用户id</param>
        /// <returns>推荐项目id&推荐度</returns>
        public static RecItemid_Degree[] getRecItems(AssociationRule[] Supp_AssRules, int userid)
        {
            // 每个项目的推荐度
            RecItemid_Degree[] temp_recDegree = new RecItemid_Degree[sourceUsers[userid].Ratings.Length];
            int count_non_zero = 1;

            for (int ItemID = 1; ItemID < sourceUsers[userid].Ratings.Length; ItemID++)
            {
                temp_recDegree[ItemID]             = new RecItemid_Degree();
                temp_recDegree[ItemID].recItems_id = ItemID;
                temp_recDegree[ItemID].rec_Degree  = 0;  // 项目推荐度初始为零

                // 循环扫描关联规则集,积累项目推荐度
                for (int count_AR = 0; count_AR < Supp_AssRules.Length; count_AR++)
                {
                    if (Supp_AssRules[count_AR]._itemid_2 == ItemID)
                    {
                        temp_recDegree[ItemID].rec_Degree += Supp_AssRules[count_AR].Reco_degrees;
                    }
                }
                if (temp_recDegree[ItemID].rec_Degree != 0)
                {
                    count_non_zero++;
                }
            }
            // 依据推荐度排序
            Array.Sort(temp_recDegree);
            recItems = new RecItemid_Degree[count_non_zero];

            // 得到推荐度不为零的项,返回之
            for (int count_rd = 1; count_rd < recItems.Length; count_rd++)
            {
                recItems[count_rd] = temp_recDegree[count_rd];
            }

            return(recItems);
        }
        /// <summary>
        /// 根据用户支持的关联规则得到依据推荐度排序的推荐项目
        /// </summary>
        /// <param name="Supp_AssRules">用户所支持的关联规则集合</param>
        /// <param name="userid">用户id</param>
        /// <returns>推荐项目id&推荐度</returns>
        public static RecItemid_Degree[] getRecItems(AssociationRule[] Supp_AssRules, int userid)
        {
            // 每个项目的推荐度
            RecItemid_Degree[] temp_recDegree = new RecItemid_Degree[sourceUsers[userid].Ratings.Length];
            int count_non_zero = 1;

            for (int ItemID = 1; ItemID < sourceUsers[userid].Ratings.Length; ItemID++)
            {
                temp_recDegree[ItemID] = new RecItemid_Degree();
                temp_recDegree[ItemID].recItems_id = ItemID;
                temp_recDegree[ItemID].rec_Degree = 0;   // 项目推荐度初始为零

                // 循环扫描关联规则集,积累项目推荐度
                for (int count_AR = 0; count_AR < Supp_AssRules.Length; count_AR++)
                {
                    if (Supp_AssRules[count_AR]._itemid_2 == ItemID)
                    {
                        temp_recDegree[ItemID].rec_Degree += Supp_AssRules[count_AR].Reco_degrees;
                    }
                }
                if(temp_recDegree[ItemID].rec_Degree != 0)
                {
                    count_non_zero++;
                }
            }
            // 依据推荐度排序
            Array.Sort(temp_recDegree);
            recItems = new RecItemid_Degree[count_non_zero];

            // 得到推荐度不为零的项,返回之
            for (int count_rd = 1; count_rd < recItems.Length; count_rd ++ )
            {
                recItems[count_rd] = temp_recDegree[count_rd];

            }

            return recItems;
        }