15
15
using Microsoft . ML . Model ;
16
16
using Microsoft . ML . Model . Onnx ;
17
17
using Microsoft . ML . Model . Pfa ;
18
+ using Microsoft . ML . Transforms ;
18
19
using Newtonsoft . Json . Linq ;
19
20
20
- [ assembly: LoadableClass ( ColumnConcatenatingTransformer . Summary , typeof ( IDataTransform ) , typeof ( ColumnConcatenatingTransformer ) , typeof ( ColumnConcatenatingTransformer . TaggedArguments ) , typeof ( SignatureDataTransform ) ,
21
+ [ assembly: LoadableClass ( ColumnConcatenatingTransformer . Summary , typeof ( IDataTransform ) , typeof ( ColumnConcatenatingTransformer ) , typeof ( ColumnConcatenatingTransformer . TaggedOptions ) , typeof ( SignatureDataTransform ) ,
21
22
ColumnConcatenatingTransformer . UserName , ColumnConcatenatingTransformer . LoadName , "ConcatTransform" , DocName = "transform/ConcatTransform.md" ) ]
22
23
23
24
[ assembly: LoadableClass ( ColumnConcatenatingTransformer . Summary , typeof ( IDataTransform ) , typeof ( ColumnConcatenatingTransformer ) , null , typeof ( SignatureLoadDataTransform ) ,
@@ -33,6 +34,10 @@ namespace Microsoft.ML.Data
33
34
{
34
35
using PfaType = PfaUtils . Type ;
35
36
37
+ /// <summary>
38
+ /// Concatenates columns in an <see cref="IDataView"/> into one single column. Please see <see cref="ColumnConcatenatingEstimator"/> for
39
+ /// constructing <see cref="ColumnConcatenatingTransformer"/>.
40
+ /// </summary>
36
41
public sealed class ColumnConcatenatingTransformer : RowToRowTransformerBase
37
42
{
38
43
internal const string Summary = "Concatenates one or more columns of the same item type." ;
@@ -42,7 +47,7 @@ public sealed class ColumnConcatenatingTransformer : RowToRowTransformerBase
42
47
internal const string LoaderSignature = "ConcatTransform" ;
43
48
internal const string LoaderSignatureOld = "ConcatFunction" ;
44
49
45
- public sealed class Column : ManyToOneColumn
50
+ internal sealed class Column : ManyToOneColumn
46
51
{
47
52
internal static Column Parse ( string str )
48
53
{
@@ -60,7 +65,8 @@ internal bool TryUnparse(StringBuilder sb)
60
65
}
61
66
}
62
67
63
- public sealed class TaggedColumn
68
+ [ BestFriend ]
69
+ internal sealed class TaggedColumn
64
70
{
65
71
[ Argument ( ArgumentType . AtMostOnce , HelpText = "Name of the new column" , ShortName = "name" ) ]
66
72
public string Name ;
@@ -99,13 +105,13 @@ internal bool TryUnparse(StringBuilder sb)
99
105
}
100
106
}
101
107
102
- public sealed class Arguments : TransformInputBase
108
+ internal sealed class Options : TransformInputBase
103
109
{
104
- public Arguments ( )
110
+ public Options ( )
105
111
{
106
112
}
107
113
108
- public Arguments ( string name , params string [ ] source )
114
+ public Options ( string name , params string [ ] source )
109
115
{
110
116
Columns = new [ ] { new Column ( )
111
117
{
@@ -119,14 +125,16 @@ public Arguments(string name, params string[] source)
119
125
public Column [ ] Columns ;
120
126
}
121
127
122
- public sealed class TaggedArguments
128
+ [ BestFriend ]
129
+ internal sealed class TaggedOptions
123
130
{
124
131
[ Argument ( ArgumentType . Multiple , HelpText = "New column definition(s) (optional form: name:srcs)" ,
125
132
Name = "Column" , ShortName = "col" , SortOrder = 1 ) ]
126
133
public TaggedColumn [ ] Columns ;
127
134
}
128
135
129
- public sealed class ColumnInfo
136
+ [ BestFriend ]
137
+ internal sealed class ColumnInfo
130
138
{
131
139
public readonly string Name ;
132
140
private readonly ( string name , string alias ) [ ] _sources ;
@@ -212,22 +220,26 @@ internal ColumnInfo(ModelLoadContext ctx)
212
220
213
221
private readonly ColumnInfo [ ] _columns ;
214
222
215
- public IReadOnlyCollection < ColumnInfo > Columns => _columns . AsReadOnly ( ) ;
223
+ /// <summary>
224
+ /// The names of the output and input column pairs for the transformation.
225
+ /// </summary>
226
+ public IReadOnlyCollection < ( string outputColumnName , string [ ] inputColumnNames ) > Columns
227
+ => _columns . Select ( col => ( outputColumnName : col . Name , inputColumnNames : col . Sources . Select ( source => source . name ) . ToArray ( ) ) ) . ToArray ( ) . AsReadOnly ( ) ;
216
228
217
229
/// <summary>
218
230
/// Concatename columns in <paramref name="inputColumnNames"/> into one column <paramref name="outputColumnName"/>.
219
231
/// Original columns are also preserved.
220
232
/// The column types must match, and the output column type is always a vector.
221
233
/// </summary>
222
- public ColumnConcatenatingTransformer ( IHostEnvironment env , string outputColumnName , params string [ ] inputColumnNames )
234
+ internal ColumnConcatenatingTransformer ( IHostEnvironment env , string outputColumnName , params string [ ] inputColumnNames )
223
235
: this ( env , new ColumnInfo ( outputColumnName , inputColumnNames ) )
224
236
{
225
237
}
226
238
227
239
/// <summary>
228
240
/// Concatenates multiple groups of columns, each group is denoted by one of <paramref name="columns"/>.
229
241
/// </summary>
230
- public ColumnConcatenatingTransformer ( IHostEnvironment env , params ColumnInfo [ ] columns ) :
242
+ internal ColumnConcatenatingTransformer ( IHostEnvironment env , params ColumnInfo [ ] columns ) :
231
243
base ( Contracts . CheckRef ( env , nameof ( env ) ) . Register ( nameof ( ColumnConcatenatingTransformer ) ) )
232
244
{
233
245
Contracts . CheckValue ( columns , nameof ( columns ) ) ;
@@ -357,17 +369,17 @@ private ColumnInfo[] LoadLegacy(ModelLoadContext ctx)
357
369
///<summary>
358
370
/// Factory method for SignatureDataTransform.
359
371
/// </summary>
360
- internal static IDataTransform Create ( IHostEnvironment env , Arguments args , IDataView input )
372
+ internal static IDataTransform Create ( IHostEnvironment env , Options options , IDataView input )
361
373
{
362
374
Contracts . CheckValue ( env , nameof ( env ) ) ;
363
- env . CheckValue ( args , nameof ( args ) ) ;
375
+ env . CheckValue ( options , nameof ( options ) ) ;
364
376
env . CheckValue ( input , nameof ( input ) ) ;
365
- env . CheckUserArg ( Utils . Size ( args . Columns ) > 0 , nameof ( args . Columns ) ) ;
377
+ env . CheckUserArg ( Utils . Size ( options . Columns ) > 0 , nameof ( options . Columns ) ) ;
366
378
367
- for ( int i = 0 ; i < args . Columns . Length ; i ++ )
368
- env . CheckUserArg ( Utils . Size ( args . Columns [ i ] . Source ) > 0 , nameof ( args . Columns ) ) ;
379
+ for ( int i = 0 ; i < options . Columns . Length ; i ++ )
380
+ env . CheckUserArg ( Utils . Size ( options . Columns [ i ] . Source ) > 0 , nameof ( options . Columns ) ) ;
369
381
370
- var cols = args . Columns
382
+ var cols = options . Columns
371
383
. Select ( c => new ColumnInfo ( c . Name , c . Source ) )
372
384
. ToArray ( ) ;
373
385
var transformer = new ColumnConcatenatingTransformer ( env , cols ) ;
@@ -377,17 +389,17 @@ internal static IDataTransform Create(IHostEnvironment env, Arguments args, IDat
377
389
/// Factory method corresponding to SignatureDataTransform.
378
390
/// </summary>
379
391
[ BestFriend ]
380
- internal static IDataTransform Create ( IHostEnvironment env , TaggedArguments args , IDataView input )
392
+ internal static IDataTransform Create ( IHostEnvironment env , TaggedOptions options , IDataView input )
381
393
{
382
394
Contracts . CheckValue ( env , nameof ( env ) ) ;
383
- env . CheckValue ( args , nameof ( args ) ) ;
395
+ env . CheckValue ( options , nameof ( options ) ) ;
384
396
env . CheckValue ( input , nameof ( input ) ) ;
385
- env . CheckUserArg ( Utils . Size ( args . Columns ) > 0 , nameof ( args . Columns ) ) ;
397
+ env . CheckUserArg ( Utils . Size ( options . Columns ) > 0 , nameof ( options . Columns ) ) ;
386
398
387
- for ( int i = 0 ; i < args . Columns . Length ; i ++ )
388
- env . CheckUserArg ( Utils . Size ( args . Columns [ i ] . Source ) > 0 , nameof ( args . Columns ) ) ;
399
+ for ( int i = 0 ; i < options . Columns . Length ; i ++ )
400
+ env . CheckUserArg ( Utils . Size ( options . Columns [ i ] . Source ) > 0 , nameof ( options . Columns ) ) ;
389
401
390
- var cols = args . Columns
402
+ var cols = options . Columns
391
403
. Select ( c => new ColumnInfo ( c . Name , c . Source . Select ( kvp => ( kvp . Value , kvp . Key != "" ? kvp . Key : null ) ) ) )
392
404
. ToArray ( ) ;
393
405
var transformer = new ColumnConcatenatingTransformer ( env , cols ) ;
0 commit comments