本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}