示例#1
0
        /// <summary>List all recommenders in a given namespace</summary>
        /// <param name="prefix">a string representing the namespace</param>
        /// <returns>an array of strings containing the recommender descriptions</returns>
        public static IList <string> ListRecommenders(this string prefix)
        {
            var result = new List <string>();

            foreach (Type type in Utils.GetTypes(prefix))
            {
                if (!type.IsAbstract && !type.IsInterface && !type.IsEnum && !type.IsGenericType && type.GetInterface("IRecommender") != null)
                {
                    IRecommender recommender = prefix.Equals("MyMediaLite.RatingPrediction") ? (IRecommender)type.CreateRatingPredictor() : (IRecommender)type.CreateItemRecommender();

                    string description = recommender.ToString();
                    string needs       = recommender.Needs();
                    if (needs.Length > 0)
                    {
                        description += "\n       needs " + needs;
                    }
                    string supports = recommender.Supports();
                    if (supports.Length > 0)
                    {
                        description += "\n       supports " + supports;
                    }
                    result.Add(description);
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>List all recommenders in a given namespace</summary>
        /// <param name="prefix">a string representing the namespace</param>
        /// <returns>an array of strings containing the recommender descriptions</returns>
        public static string[] List(string prefix)
        {
            var result = new List <string>();

            foreach (Type type in Utils.GetTypesInNamespace(prefix))
            {
                if (!type.IsAbstract && !type.IsInterface && !type.IsEnum && !type.IsGenericType && type.GetInterface("IRecommender") != null)
                {
                    IRecommender recommender = prefix.Equals("MyMediaLite.RatingPrediction") ? (IRecommender)Recommender.CreateRatingPredictor(type) : (IRecommender)Recommender.CreateItemRecommender(type);

                    string description = recommender.ToString();
                    string needs       = Recommender.Needs(recommender);
                    if (needs.Length > 0)
                    {
                        description += " (needs " + needs + ")";
                    }
                    result.Add(description);
                }
            }

            return(result.ToArray());
        }