当前位置: 首页>>代码示例>>C#>>正文


C# IEntityMapping.ToInternalID方法代码示例

本文整理汇总了C#中IEntityMapping.ToInternalID方法的典型用法代码示例。如果您正苦于以下问题:C# IEntityMapping.ToInternalID方法的具体用法?C# IEntityMapping.ToInternalID怎么用?C# IEntityMapping.ToInternalID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEntityMapping的用法示例。


在下文中一共展示了IEntityMapping.ToInternalID方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

        /// <summary>Read binary relation data from file</summary>
        /// <remarks>
        /// The expected (sparse) line format is:
        /// ENTITY_ID whitespace ENTITY_ID
        /// for the relations that hold.
        /// </remarks>
        /// <param name="reader">a StreamReader to be read from</param>
        /// <param name="mapping">the mapping object for the given entity type</param>
        /// <returns>the relation data</returns>
        public static SparseBooleanMatrix Read(StreamReader reader, IEntityMapping mapping)
        {
            var matrix = new SparseBooleanMatrix();

            char[] split_chars = new char[]{ '\t', ' ' };
            string line;

            while (!reader.EndOfStream)
            {
               	line = reader.ReadLine();

                // ignore empty lines
                if (line.Length == 0)
                    continue;

                string[] tokens = line.Split(split_chars);

                if (tokens.Length != 2)
                    throw new IOException("Expected exactly two columns: " + line);

                int entity1_id = mapping.ToInternalID(int.Parse(tokens[0]));
                int entity2_id = mapping.ToInternalID(int.Parse(tokens[1]));

               	matrix[entity1_id, entity2_id] = true;
            }

            return matrix;
        }
开发者ID:zenogantner,项目名称:MML-KDD,代码行数:37,代码来源:RelationData.cs

示例2: Read

        /// <summary>Read in implicit feedback data from a TextReader</summary>
        /// <param name="reader">the TextReader to be read from</param>
        /// <param name="user_mapping">user <see cref="IEntityMapping"/> object</param>
        /// <param name="item_mapping">item <see cref="IEntityMapping"/> object</param>
        /// <returns>a <see cref="IPosOnlyFeedback"/> object with the user-wise collaborative data</returns>
        public static IPosOnlyFeedback Read(TextReader reader, IEntityMapping user_mapping, IEntityMapping item_mapping)
        {
            var feedback = new PosOnlyFeedback<SparseBooleanMatrix>();

            var split_chars = new char[]{ '\t', ' ', ',' };
            string line;

            while ( (line = reader.ReadLine()) != null )
            {
                if (line.Trim().Length == 0)
                    continue;

                string[] tokens = line.Split(split_chars);

                if (tokens.Length < 2)
                    throw new IOException("Expected at least two columns: " + line);

                int user_id = user_mapping.ToInternalID(int.Parse(tokens[0]));
                int item_id = item_mapping.ToInternalID(int.Parse(tokens[1]));

               	feedback.Add(user_id, item_id);
            }

            return feedback;
        }
开发者ID:zenogantner,项目名称:MML-KDD,代码行数:30,代码来源:ItemRecommendation.cs

示例3: Read

        /// <summary>Read in rating data from a TextReader</summary>
        /// <param name="reader">the <see cref="TextReader"/> to read from</param>
        /// <param name="user_mapping">mapping object for user IDs</param>
        /// <param name="item_mapping">mapping object for item IDs</param>
        /// <returns>the rating data</returns>
        public static IRatings Read(TextReader reader,	IEntityMapping user_mapping, IEntityMapping item_mapping)
        {
            var ratings = new Ratings();

            var split_chars = new char[]{ '\t', ' ', ',' };
            string line;

            while ( (line = reader.ReadLine()) != null )
            {
                if (line.Length == 0)
                    continue;

                string[] tokens = line.Split(split_chars);

                if (tokens.Length < 3)
                    throw new IOException("Expected at least three columns: " + line);

                int user_id = user_mapping.ToInternalID(int.Parse(tokens[0]));
                int item_id = item_mapping.ToInternalID(int.Parse(tokens[1]));
                double rating = double.Parse(tokens[2], CultureInfo.InvariantCulture);

                ratings.Add(user_id, item_id, rating);
            }
            return ratings;
        }
开发者ID:zenogantner,项目名称:MML-KDD,代码行数:30,代码来源:RatingPrediction.cs

示例4: Read

        /// <summary>Read binary attribute data from a StreamReader</summary>
        /// <remarks>
        /// The expected (sparse) line format is:
        /// ENTITY_ID tab/space/comma ATTRIBUTE_ID
        /// for the relations that hold.
        /// </remarks>
        /// <param name="reader">a StreamReader to be read from</param>
        /// <param name="mapping">the mapping object for the given entity type</param>
        /// <returns>the attribute data</returns>
        public static SparseBooleanMatrix Read(StreamReader reader, IEntityMapping mapping)
        {
            var matrix = new SparseBooleanMatrix();

            string line;
            while ((line = reader.ReadLine()) != null)
            {
                // ignore empty lines
                if (line.Length == 0)
                    continue;

                string[] tokens = line.Split(Constants.SPLIT_CHARS);

                if (tokens.Length != 2)
                    throw new FormatException("Expected exactly 2 columns: " + line);

                int entity_id = mapping.ToInternalID(tokens[0]);
                int attr_id   = int.Parse(tokens[1]);

                matrix[entity_id, attr_id] = true;
            }

            return matrix;
        }
开发者ID:kinyue,项目名称:MyMediaLite,代码行数:33,代码来源:AttributeData.cs

示例5: Read

        /// <summary>Read in rating data from an IDataReader, e.g. a database via DbDataReader</summary>
        /// <param name="reader">the <see cref="IDataReader"/> to read from</param>
        /// <param name="user_mapping">mapping object for user IDs</param>
        /// <param name="item_mapping">mapping object for item IDs</param>
        /// <returns>the rating data</returns>
        public static IRatings Read(IDataReader reader, IEntityMapping user_mapping, IEntityMapping item_mapping)
        {
            var ratings = new Ratings();

            if (reader.FieldCount < 3)
                throw new FormatException("Expected at least 3 columns.");

            Func<string> get_user_id = reader.GetStringGetter(0);
            Func<string> get_item_id = reader.GetStringGetter(1);
            Func<float>  get_rating  = reader.GetFloatGetter(2);

            while (reader.Read())
            {
                int user_id = user_mapping.ToInternalID(get_user_id());
                int item_id = item_mapping.ToInternalID(get_item_id());
                float rating = get_rating();

                ratings.Add(user_id, item_id, rating);
            }
            return ratings;
        }
开发者ID:kinyue,项目名称:MyMediaLite,代码行数:26,代码来源:RatingData.cs

示例6: Read

        /// <summary>Read in implicit feedback data from an IDataReader, e.g. a database via DbDataReader</summary>
        /// <param name="reader">the IDataReader to be read from</param>
        /// <param name="user_mapping">user <see cref="IEntityMapping"/> object</param>
        /// <param name="item_mapping">item <see cref="IEntityMapping"/> object</param>
        /// <returns>a <see cref="IPosOnlyFeedback"/> object with the user-wise collaborative data</returns>
        public static IPosOnlyFeedback Read(IDataReader reader, IEntityMapping user_mapping, IEntityMapping item_mapping)
        {
            var feedback = new PosOnlyFeedback<SparseBooleanMatrix>();

            if (reader.FieldCount < 2)
                throw new FormatException("Expected at least 2 columns.");

            Func<string> get_user_id = reader.GetStringGetter(0);
            Func<string> get_item_id = reader.GetStringGetter(1);

            while (reader.Read())
            {
                int user_id = user_mapping.ToInternalID(get_user_id());
                int item_id = item_mapping.ToInternalID(get_item_id());

                feedback.Add(user_id, item_id);
            }

            return feedback;
        }
开发者ID:kinyue,项目名称:MyMediaLite,代码行数:25,代码来源:ItemData.cs


注:本文中的IEntityMapping.ToInternalID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。