本文整理汇总了C#中IEntityMapping类的典型用法代码示例。如果您正苦于以下问题:C# IEntityMapping类的具体用法?C# IEntityMapping怎么用?C# IEntityMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IEntityMapping类属于命名空间,在下文中一共展示了IEntityMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
/// <summary>Read in static rating data from a file</summary>
/// <param name="filename">the name of the file to read from</param>
/// <param name="user_mapping">mapping object for user IDs</param>
/// <param name="item_mapping">mapping object for item IDs</param>
/// <param name="rating_type">the data type to be used for storing the ratings</param>
/// <param name="ignore_first_line">if true, ignore the first line</param>
/// <returns>the rating data</returns>
public static IRatings Read(
string filename,
IEntityMapping user_mapping = null, IEntityMapping item_mapping = null,
RatingType rating_type = RatingType.FLOAT,
bool ignore_first_line = false)
{
string binary_filename = filename + ".bin.StaticRatings";
if (FileSerializer.Should(user_mapping, item_mapping) && File.Exists(binary_filename))
return (IRatings) FileSerializer.Deserialize(binary_filename);
int size = 0;
using ( var reader = new StreamReader(filename) )
while (reader.ReadLine() != null)
size++;
if (ignore_first_line)
size--;
return Wrap.FormatException<IRatings>(filename, delegate() {
using ( var reader = new StreamReader(filename) )
{
var ratings = (StaticRatings) Read(reader, size, user_mapping, item_mapping, rating_type);
if (FileSerializer.Should(user_mapping, item_mapping) && FileSerializer.CanWrite(binary_filename))
ratings.Serialize(binary_filename);
return ratings;
}
});
}
示例2: 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 ITimedRatings Read(TextReader reader, IEntityMapping user_mapping = null, IEntityMapping item_mapping = null)
{
if (user_mapping == null)
user_mapping = new IdentityMapping();
if (item_mapping == null)
item_mapping = new IdentityMapping();
var ratings = new TimedRatings();
string[] separators = { "::" };
string line;
while ((line = reader.ReadLine()) != null)
{
string[] tokens = line.Split(separators, StringSplitOptions.None);
if (tokens.Length < 4)
throw new FormatException(string.Format("Expected at least 4 columns: {0}", line));
int user_id = user_mapping.ToInternalID(tokens[0]);
int item_id = item_mapping.ToInternalID(tokens[1]);
float rating = float.Parse(tokens[2], CultureInfo.InvariantCulture);
long seconds = uint.Parse(tokens[3]);
var time = new DateTime(seconds * 10000000L).AddYears(1969);
var offset = TimeZone.CurrentTimeZone.GetUtcOffset(time);
time -= offset;
ratings.Add(user_id, item_id, rating, time);
}
return ratings;
}
示例3: 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;
}
示例4: Read
/// <summary>Read binary attribute data from a file</summary>
/// <remarks>
/// The expected (sparse) line format is:
/// ENTITY_ID tab/space/comma ATTRIBUTE_ID
/// for the relations that hold.
/// </remarks>
/// <param name="filename">the name of the file 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(string filename, IEntityMapping mapping)
{
return Wrap.FormatException<SparseBooleanMatrix>(filename, delegate() {
using ( var reader = new StreamReader(filename) )
return Read(reader, mapping);
});
}
示例5: 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;
}
示例6: Read
/// <summary>Read in rating data which will be interpreted as implicit feedback data from a TextReader</summary>
/// <param name="reader">the TextReader to be read from</param>
/// <param name="rating_threshold">the minimum rating value needed to be accepted as positive feedback</param>
/// <param name="user_mapping">user <see cref="IEntityMapping"/> object</param>
/// <param name="item_mapping">item <see cref="IEntityMapping"/> object</param>
/// <param name="ignore_first_line">if true, ignore the first line</param>
/// <returns>a <see cref="IPosOnlyFeedback"/> object with the user-wise collaborative data</returns>
public static IPosOnlyFeedback Read(TextReader reader, float rating_threshold, IEntityMapping user_mapping = null, IEntityMapping item_mapping = null, bool ignore_first_line = false)
{
if (user_mapping == null)
user_mapping = new IdentityMapping();
if (item_mapping == null)
item_mapping = new IdentityMapping();
if (ignore_first_line)
reader.ReadLine();
var feedback = new PosOnlyFeedback<SparseBooleanMatrix>();
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Trim().Length == 0)
continue;
string[] tokens = line.Split(Constants.SPLIT_CHARS);
if (tokens.Length < 3)
throw new FormatException("Expected at least 3 columns: " + line);
int user_id = user_mapping.ToInternalID(tokens[0]);
int item_id = item_mapping.ToInternalID(tokens[1]);
float rating = float.Parse(tokens[2], CultureInfo.InvariantCulture);
if (rating >= rating_threshold)
feedback.Add(user_id, item_id);
}
return feedback;
}
示例7: Read
/// <summary>Read in static rating data from a TextReader</summary>
/// <param name="reader">the <see cref="TextReader"/> to read from</param>
/// <param name="size">the number of ratings in the file</param>
/// <param name="user_mapping">mapping object for user IDs</param>
/// <param name="item_mapping">mapping object for item IDs</param>
/// <param name="rating_type">the data type to be used for storing the ratings</param>
/// <returns>the rating data</returns>
public static IRatings Read(TextReader reader, int size,
IEntityMapping user_mapping, IEntityMapping item_mapping,
RatingType rating_type)
{
IRatings ratings;
if (rating_type == RatingType.BYTE)
ratings = new StaticByteRatings(size);
else if (rating_type == RatingType.FLOAT)
ratings = new StaticFloatRatings(size);
else
ratings = new StaticRatings(size);
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;
}
示例8: 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>
/// <param name="ignore_first_line">if true, ignore the first line</param>
/// <returns>the rating data</returns>
public static IRatings Read(TextReader reader, IEntityMapping user_mapping = null, IEntityMapping item_mapping = null, bool ignore_first_line = false)
{
if (user_mapping == null)
user_mapping = new IdentityMapping();
if (item_mapping == null)
item_mapping = new IdentityMapping();
if (ignore_first_line)
reader.ReadLine();
var ratings = new Ratings();
string line;
while ( (line = reader.ReadLine()) != null )
{
if (line.Length == 0)
continue;
string[] tokens = line.Split(Constants.SPLIT_CHARS);
if (tokens.Length < 3)
throw new FormatException("Expected at least 3 columns: " + line);
int user_id = user_mapping.ToInternalID(tokens[0]);
int item_id = item_mapping.ToInternalID(tokens[1]);
float rating = float.Parse(tokens[2], CultureInfo.InvariantCulture);
ratings.Add(user_id, item_id, rating);
}
return ratings;
}
示例9: MemberMapping
public MemberMapping(MemberInfo memberInfo, MemberAttribute memberAttribute, IEntityMapping entityMapping)
{
this.entity = entityMapping;
this.memberInfo = memberInfo;
this.memberAttribute = memberAttribute;
this.memberType = memberInfo.GetMemberType();
if (memberAttribute is ColumnAttribute)
{
this.InitializeColumnAttributeMapping((ColumnAttribute)memberAttribute);
}
else if (memberAttribute is AssociationAttribute)
{
var isEnumerableType = memberType != typeof(string) &&
memberType != typeof(byte[]) &&
typeof(IEnumerable).IsAssignableFrom(memberType);
this.isRelationship = true;
this.InitializeAssociationAttributeMapping((AssociationAttribute)memberAttribute, isEnumerableType);
}
}
示例10: BuildEntityExpression
public virtual Expression BuildEntityExpression(IEntityMapping mapping, IList<EntityAssignment> assignments)
{
NewExpression newExpression;
// handle cases where members are not directly assignable
EntityAssignment[] readonlyMembers = assignments.Where(b => b.MemberMapping != null)
.Where(b => (b.MemberMapping as MemberMapping).setter == null)
.ToArray();
ConstructorInfo[] cons = mapping.EntityType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
bool hasNoArgConstructor = cons.Any(c => c.GetParameters().Length == 0);
if (readonlyMembers.Length > 0 || !hasNoArgConstructor)
{
var consThatApply = cons
.Select(c => this.BindConstructor(c, readonlyMembers))
.Where(cbr => cbr != null && cbr.Remaining.Length == 0)
.ToList();
if (consThatApply.Count == 0)
throw new InvalidOperationException(string.Format(Res.ConstructTypeInvalid, mapping.EntityType));
// just use the first one... (Note: need better algorithm. :-)
if (readonlyMembers.Length == assignments.Count)
return consThatApply[0].Expression;
var r = this.BindConstructor(consThatApply[0].Expression.Constructor, assignments);
newExpression = r.Expression;
assignments = r.Remaining;
}
else
newExpression = Expression.New(mapping.EntityType);
Expression result;
if (assignments.Count > 0)
{
if (mapping.EntityType.IsInterface)
assignments = this.MapAssignments(assignments, mapping.EntityType).ToList();
var memberBindings = new List<MemberBinding>();
foreach (var a in assignments)
{
try
{
memberBindings.Add(Expression.Bind(a.Member, a.Expression));
}
catch
{
throw;
}
}
result = Expression.MemberInit(newExpression, memberBindings.ToArray());
}
else
result = newExpression;
if (mapping.EntityType != mapping.EntityType)
result = Expression.Convert(result, mapping.EntityType);
return result;
}
示例11: SelectGraph
public Uri SelectGraph(EntityId entityId, IEntityMapping entityMapping, IPropertyMapping predicate)
{
EntityId nonBlankId = entityId;
if (nonBlankId is BlankId)
{
nonBlankId = ((BlankId)nonBlankId).RootEntityId;
}
return new Uri(System.Text.RegularExpressions.Regex.Replace((nonBlankId != null ? nonBlankId.Uri.AbsoluteUri : ((BlankId)entityId).Graph.AbsoluteUri), "((?<!data.)magi)", "data.magi"));
}
示例12: Visit
/// <summary>
/// Sets the currently processed enitty type
/// and updates inheritance cache
/// </summary>
public void Visit(IEntityMapping entityMapping)
{
if (!_classMappings.ContainsKey(entityMapping.EntityType))
{
_classMappings.Add(entityMapping.EntityType, new List<IClassMapping>());
}
AddAsChildOfParentTypes(entityMapping.EntityType);
_currentClasses = _classMappings[entityMapping.EntityType];
}
示例13: WritePredictions
/// <summary>Write item predictions (scores) to a file</summary>
/// <param name="recommender">the <see cref="IRecommender"/> to use for making the predictions</param>
/// <param name="train">a user-wise <see cref="IPosOnlyFeedback"/> containing the items already observed</param>
/// <param name="candidate_items">list of candidate items</param>
/// <param name="num_predictions">number of items to return per user, -1 if there should be no limit</param>
/// <param name="filename">the name of the file to write to</param>
/// <param name="users">a list of users to make recommendations for</param>
/// <param name="user_mapping">an <see cref="IEntityMapping"/> object for the user IDs</param>
/// <param name="item_mapping">an <see cref="IEntityMapping"/> object for the item IDs</param>
public static void WritePredictions(
this IRecommender recommender,
IPosOnlyFeedback train,
System.Collections.Generic.IList<int> candidate_items,
int num_predictions,
string filename,
System.Collections.Generic.IList<int> users = null,
IEntityMapping user_mapping = null, IEntityMapping item_mapping = null)
{
using (var writer = new StreamWriter(filename))
WritePredictions(recommender, train, candidate_items, num_predictions, writer, users, user_mapping, item_mapping);
}
示例14: BuildSchemaScript
protected override string[] BuildSchemaScript(IEntityMapping[] mappings)
{
return new string[]{
mappings
.Where(p => p.Schema.HasValue()
&& p.Schema.Trim().ToUpper() != "DBO"
&& p.Schema.Trim().ToUpper() != "[DBO]")
.Select(p => p.Schema.Trim().ToLower())
.Distinct()
.Select(p => string.Format("{0} CREATE SCHEMA {1}{0} ", Environment.NewLine, p))
.ToCSV(";")
};
}
示例15: WritePredictions
/// <summary>Rate a given set of instances and write it to a file</summary>
/// <param name="recommender">rating predictor</param>
/// <param name="ratings">test cases</param>
/// <param name="user_mapping">an <see cref="EntityMapping"/> object for the user IDs</param>
/// <param name="item_mapping">an <see cref="EntityMapping"/> object for the item IDs</param>
/// <param name="line_format">a format string specifying the line format; {0} is the user ID, {1} the item ID, {2} the rating</param>
/// <param name="filename">the name of the file to write the predictions to</param>
public static void WritePredictions(
IRatingPredictor recommender,
IRatings ratings,
IEntityMapping user_mapping, IEntityMapping item_mapping,
string line_format,
string filename)
{
if (filename.Equals("-"))
WritePredictions(recommender, ratings, user_mapping, item_mapping, line_format, Console.Out);
else
using ( var writer = new StreamWriter(filename) )
WritePredictions(recommender, ratings, user_mapping, item_mapping, line_format, writer);
}