9
9
namespace Microsoft . ML . Runtime . Data
10
10
{
11
11
/// <summary>
12
- /// This contains information about a column in an IDataView. It is essentially a convenience
13
- /// cache containing the name, column index, and column type for the column.
12
+ /// This contains information about a column in an <see cref="IDataView"/>. It is essentially a convenience cache
13
+ /// containing the name, column index, and column type for the column. The intended usage is that users of <see cref="RoleMappedSchema"/>
14
+ /// to get the column index and type associated with
14
15
/// </summary>
15
16
public sealed class ColumnInfo
16
17
{
@@ -71,12 +72,20 @@ public static ColumnInfo CreateFromIndex(ISchema schema, int index)
71
72
}
72
73
73
74
/// <summary>
74
- /// Encapsulates an ISchema plus column role mapping information. It has convenience fields for
75
- /// several common column roles, but can hold an arbitrary set of column infos. The convenience
76
- /// fields are non-null iff there is a unique column with the corresponding role. When there are
77
- /// no such columns or more than one such column, the field is null. The Has, HasUnique, and
78
- /// HasMultiple methods provide some cardinality information.
79
- /// Note that all columns assigned roles are guaranteed to be non-hidden in this schema.
75
+ /// Encapsulates an <see cref="ISchema"/> plus column role mapping information. The purpose of role mappings is to
76
+ /// provide information on what the intended usage is for. That is: while a given data view may have a column named
77
+ /// "Features", by itself that is insufficient: the trainer must be fed a role mapping that says that the role
78
+ /// mapping for features is filled by that "Features" column. This allows things like columns not named "Features"
79
+ /// to actually fill that role (as opposed to insisting on a hard coding, or having every trainer have to be
80
+ /// individually configured). Also, by being a one-to-many mapping, it is a way for learners that can consume
81
+ /// multiple features columns to consume that information.
82
+ ///
83
+ /// This class has convenience fields for several common column roles (se.g., <see cref="Feature"/>, <see
84
+ /// cref="Label"/>), but can hold an arbitrary set of column infos. The convenience fields are non-null iff there is
85
+ /// a unique column with the corresponding role. When there are no such columns or more than one such column, the
86
+ /// field is null. The <see cref="Has"/>, <see cref="HasUnique"/>, and <see cref="HasMultiple"/> methods provide
87
+ /// some cardinality information. Note that all columns assigned roles are guaranteed to be non-hidden in this
88
+ /// schema.
80
89
/// </summary>
81
90
public sealed class RoleMappedSchema
82
91
{
@@ -85,18 +94,16 @@ public sealed class RoleMappedSchema
85
94
private const string GroupString = "Group" ;
86
95
private const string WeightString = "Weight" ;
87
96
private const string NameString = "Name" ;
88
- private const string IdString = "Id" ;
89
97
private const string FeatureContributionsString = "FeatureContributions" ;
90
98
91
99
public struct ColumnRole
92
100
{
93
- public static ColumnRole Feature { get { return new ColumnRole ( FeatureString ) ; } }
94
- public static ColumnRole Label { get { return new ColumnRole ( LabelString ) ; } }
95
- public static ColumnRole Group { get { return new ColumnRole ( GroupString ) ; } }
96
- public static ColumnRole Weight { get { return new ColumnRole ( WeightString ) ; } }
97
- public static ColumnRole Name { get { return new ColumnRole ( NameString ) ; } }
98
- public static ColumnRole Id { get { return new ColumnRole ( IdString ) ; } }
99
- public static ColumnRole FeatureContributions { get { return new ColumnRole ( FeatureContributionsString ) ; } }
101
+ public static ColumnRole Feature => FeatureString ;
102
+ public static ColumnRole Label => LabelString ;
103
+ public static ColumnRole Group => GroupString ;
104
+ public static ColumnRole Weight => WeightString ;
105
+ public static ColumnRole Name => NameString ;
106
+ public static ColumnRole FeatureContributions => FeatureContributionsString ;
100
107
101
108
public readonly string Value ;
102
109
@@ -152,11 +159,6 @@ public static KeyValuePair<ColumnRole, string> CreatePair(ColumnRole role, strin
152
159
/// </summary>
153
160
public readonly ColumnInfo Name ;
154
161
155
- /// <summary>
156
- /// The Id column, when there is exactly one (null otherwise).
157
- /// </summary>
158
- public readonly ColumnInfo Id ;
159
-
160
162
// Maps from role to the associated column infos.
161
163
private readonly Dictionary < string , IReadOnlyList < ColumnInfo > > _map ;
162
164
@@ -194,9 +196,6 @@ private RoleMappedSchema(ISchema schema, Dictionary<string, IReadOnlyList<Column
194
196
case NameString :
195
197
Name = cols [ 0 ] ;
196
198
break ;
197
- case IdString :
198
- Id = cols [ 0 ] ;
199
- break ;
200
199
}
201
200
}
202
201
}
@@ -224,8 +223,8 @@ private static void Add(Dictionary<string, List<ColumnInfo>> map, ColumnRole rol
224
223
225
224
private static Dictionary < string , List < ColumnInfo > > MapFromNames ( ISchema schema , IEnumerable < KeyValuePair < ColumnRole , string > > roles )
226
225
{
227
- Contracts . AssertValue ( schema , "schema" ) ;
228
- Contracts . AssertValue ( roles , "roles" ) ;
226
+ Contracts . AssertValue ( schema ) ;
227
+ Contracts . AssertValue ( roles ) ;
229
228
230
229
var map = new Dictionary < string , List < ColumnInfo > > ( ) ;
231
230
foreach ( var kvp in roles )
@@ -241,8 +240,8 @@ private static Dictionary<string, List<ColumnInfo>> MapFromNames(ISchema schema,
241
240
242
241
private static Dictionary < string , List < ColumnInfo > > MapFromNamesOpt ( ISchema schema , IEnumerable < KeyValuePair < ColumnRole , string > > roles )
243
242
{
244
- Contracts . AssertValue ( schema , "schema" ) ;
245
- Contracts . AssertValue ( roles , "roles" ) ;
243
+ Contracts . AssertValue ( schema ) ;
244
+ Contracts . AssertValue ( roles ) ;
246
245
247
246
var map = new Dictionary < string , List < ColumnInfo > > ( ) ;
248
247
foreach ( var kvp in roles )
@@ -334,6 +333,13 @@ public IEnumerable<KeyValuePair<ColumnRole, string>> GetColumnRoleNames(ColumnRo
334
333
}
335
334
}
336
335
336
+ /// <summary>
337
+ /// Returns the <see cref="ColumnInfo"/> corresponding to <paramref name="role"/> if there is
338
+ /// exactly one such mapping, and otherwise throws an exception.
339
+ /// </summary>
340
+ /// <param name="role">The role to look up</param>
341
+ /// <returns>The info corresponding to that role, assuming there was only one column
342
+ /// mapped to that</returns>
337
343
public ColumnInfo GetUniqueColumn ( ColumnRole role )
338
344
{
339
345
var infos = GetColumns ( role ) ;
@@ -398,9 +404,9 @@ public static RoleMappedSchema CreateOpt(ISchema schema, IEnumerable<KeyValuePai
398
404
}
399
405
400
406
/// <summary>
401
- /// Encapsulates an IDataView plus a corresponding RoleMappedSchema. Note that the schema of the
402
- /// RoleMappedSchema is guaranteed to be the same schema of the IDataView, that is,
403
- /// Data.Schema == Schema .Schema.
407
+ /// Encapsulates an <see cref=" IDataView"/> plus a corresponding <see cref=" RoleMappedSchema"/>.
408
+ /// Note that the schema of <see cref="RoleMappedSchema.Schema"/> of <see cref="Schema"/> is
409
+ /// guaranteed to equal the the <see cref="ISchematized .Schema"/> of <see cref="Data"/> .
404
410
/// </summary>
405
411
public sealed class RoleMappedData
406
412
{
0 commit comments