2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
- using System ;
6
5
using System . Collections . Generic ;
7
6
using System . CommandLine ;
8
7
using System . CommandLine . Builder ;
9
8
using System . CommandLine . Invocation ;
10
9
using System . IO ;
11
- using System . Linq ;
12
- using Microsoft . ML . Auto ;
13
10
14
11
namespace Microsoft . ML . CLI . Commands
15
12
{
@@ -19,40 +16,40 @@ internal static System.CommandLine.Command New(ICommandHandler handler)
19
16
{
20
17
var newCommand = new System . CommandLine . Command ( "new" , "Create a new .NET project using ML.NET to train and run a model" , handler : handler )
21
18
{
22
- Dataset ( ) ,
23
- ValidationDataset ( ) ,
24
- TestDataset ( ) ,
25
- MlTask ( ) ,
26
- LabelName ( ) ,
27
- MaxExplorationTime ( ) ,
28
- LabelColumnIndex ( ) ,
29
- Verbosity ( ) ,
30
- Name ( ) ,
31
- OutputPath ( ) ,
32
- HasHeader ( ) ,
33
- Cache ( ) ,
34
- IgnoreColumns ( )
19
+ Dataset ( ) ,
20
+ ValidationDataset ( ) ,
21
+ TestDataset ( ) ,
22
+ MlTask ( ) ,
23
+ LabelName ( ) ,
24
+ MaxExplorationTime ( ) ,
25
+ LabelColumnIndex ( ) ,
26
+ Verbosity ( ) ,
27
+ Name ( ) ,
28
+ OutputPath ( ) ,
29
+ HasHeader ( ) ,
30
+ Cache ( ) ,
31
+ IgnoreColumns ( ) ,
35
32
} ;
36
33
37
34
newCommand . Argument . AddValidator ( ( sym ) =>
38
35
{
39
- if ( sym . Children [ "--dataset" ] == null )
36
+ if ( ! sym . Children . Contains ( "--dataset" ) )
40
37
{
41
38
return "Option required : --dataset" ;
42
39
}
43
- if ( sym . Children [ "--ml-task" ] == null )
40
+ if ( ! sym . Children . Contains ( "--ml-task" ) )
44
41
{
45
42
return "Option required : --ml-task" ;
46
43
}
47
- if ( sym . Children [ "--label-column-name" ] == null && sym . Children [ "--label-column-index" ] == null )
44
+ if ( ! sym . Children . Contains ( "--label-column-name" ) && ! sym . Children . Contains ( "--label-column-index" ) )
48
45
{
49
46
return "Option required : --label-column-name or --label-column-index" ;
50
47
}
51
- if ( sym . Children [ "--label-column-name" ] != null && sym . Children [ "--label-column-index" ] != null )
48
+ if ( sym . Children . Contains ( "--label-column-name" ) && sym . Children . Contains ( "--label-column-index" ) )
52
49
{
53
50
return "The following options are mutually exclusive please provide only one : --label-column-name, --label-column-index" ;
54
51
}
55
- if ( sym . Children [ "--label-column-index" ] != null && sym . Children [ "--ignore-columns" ] != null )
52
+ if ( sym . Children . Contains ( "--label-column-index" ) && sym . Children [ "--ignore-columns" ] . Arguments . Count > 0 )
56
53
{
57
54
return "Currently we don't support specifying --ignore-columns in conjunction with --label-column-index" ;
58
55
}
@@ -63,56 +60,56 @@ internal static System.CommandLine.Command New(ICommandHandler handler)
63
60
return newCommand ;
64
61
65
62
Option Dataset ( ) =>
66
- new Option ( "--dataset" , "File path to either a single dataset or a training dataset for train/test split approaches." ,
67
- new Argument < FileInfo > ( ) . ExistingOnly ( ) ) ;
63
+ new Option ( "--dataset" , "File path to either a single dataset or a training dataset for train/test split approaches." ,
64
+ new Argument < FileInfo > ( ) . ExistingOnly ( ) ) ;
68
65
69
66
Option ValidationDataset ( ) =>
70
- new Option ( "--validation-dataset" , "File path for the validation dataset in train/validation/test split approaches." ,
71
- new Argument < FileInfo > ( defaultValue : default ( FileInfo ) ) . ExistingOnly ( ) ) ;
67
+ new Option ( "--validation-dataset" , "File path for the validation dataset in train/validation/test split approaches." ,
68
+ new Argument < FileInfo > ( defaultValue : default ( FileInfo ) ) . ExistingOnly ( ) ) ;
72
69
73
70
Option TestDataset ( ) =>
74
- new Option ( "--test-dataset" , "File path for the test dataset in train/test approaches." ,
75
- new Argument < FileInfo > ( defaultValue : default ( FileInfo ) ) . ExistingOnly ( ) ) ;
71
+ new Option ( "--test-dataset" , "File path for the test dataset in train/test approaches." ,
72
+ new Argument < FileInfo > ( defaultValue : default ( FileInfo ) ) . ExistingOnly ( ) ) ;
76
73
77
74
Option MlTask ( ) =>
78
- new Option ( "--ml-task" , "Type of ML task to perform. Current supported tasks: regression and binary-classification" ,
79
- new Argument < string > ( ) . FromAmong ( GetMlTaskSuggestions ( ) ) ) ;
75
+ new Option ( "--ml-task" , "Type of ML task to perform. Current supported tasks: regression and binary-classification" ,
76
+ new Argument < string > ( ) . FromAmong ( GetMlTaskSuggestions ( ) ) ) ;
80
77
81
78
Option LabelName ( ) =>
82
- new Option ( "--label-column-name" , "Name of the label (target) column to predict." ,
83
- new Argument < string > ( ) ) ;
79
+ new Option ( "--label-column-name" , "Name of the label (target) column to predict." ,
80
+ new Argument < string > ( ) ) ;
84
81
85
82
Option LabelColumnIndex ( ) =>
86
- new Option ( "--label-column-index" , "Index of the label (target) column to predict." ,
87
- new Argument < uint > ( ) ) ;
83
+ new Option ( "--label-column-index" , "Index of the label (target) column to predict." ,
84
+ new Argument < uint > ( ) ) ;
88
85
89
86
Option MaxExplorationTime ( ) =>
90
- new Option ( "--max-exploration-time" , "Maximum time in seconds for exploring models with best configuration." ,
91
- new Argument < uint > ( defaultValue : 10 ) ) ;
87
+ new Option ( "--max-exploration-time" , "Maximum time in seconds for exploring models with best configuration." ,
88
+ new Argument < uint > ( defaultValue : 10 ) ) ;
92
89
93
90
Option Verbosity ( ) =>
94
- new Option ( new List < string > ( ) { "--verbosity" } , "Output verbosity choices: q[uiet], m[inimal] (by default) and diag[nostic]" ,
95
- new Argument < string > ( defaultValue : "m" ) . FromAmong ( GetVerbositySuggestions ( ) ) ) ;
91
+ new Option ( new List < string > ( ) { "--verbosity" } , "Output verbosity choices: q[uiet], m[inimal] (by default) and diag[nostic]" ,
92
+ new Argument < string > ( defaultValue : "m" ) . FromAmong ( GetVerbositySuggestions ( ) ) ) ;
96
93
97
94
Option Name ( ) =>
98
- new Option ( new List < string > ( ) { "--name" } , "Name for the output project or solution to create. " ,
99
- new Argument < string > ( ) ) ;
95
+ new Option ( new List < string > ( ) { "--name" } , "Name for the output project or solution to create. " ,
96
+ new Argument < string > ( ) ) ;
100
97
101
98
Option OutputPath ( ) =>
102
- new Option ( new List < string > ( ) { "--output-path" } , "Location folder to place the generated output. The default is the current directory." ,
103
- new Argument < DirectoryInfo > ( defaultValue : new DirectoryInfo ( "." ) ) ) ;
99
+ new Option ( new List < string > ( ) { "--output-path" } , "Location folder to place the generated output. The default is the current directory." ,
100
+ new Argument < DirectoryInfo > ( defaultValue : new DirectoryInfo ( "." ) ) ) ;
104
101
105
102
Option HasHeader ( ) =>
106
- new Option ( new List < string > ( ) { "--has-header" } , "Specify true/false depending if the dataset file(s) have a header row." ,
107
- new Argument < bool > ( defaultValue : true ) ) ;
103
+ new Option ( new List < string > ( ) { "--has-header" } , "Specify true/false depending if the dataset file(s) have a header row." ,
104
+ new Argument < bool > ( defaultValue : true ) ) ;
108
105
109
106
Option Cache ( ) =>
110
- new Option ( new List < string > ( ) { "--cache" } , "Specify on/off/auto if you want cache to be turned on, off or auto determined." ,
111
- new Argument < string > ( defaultValue : "auto" ) . FromAmong ( GetCacheSuggestions ( ) ) ) ;
107
+ new Option ( new List < string > ( ) { "--cache" } , "Specify on/off/auto if you want cache to be turned on, off or auto determined." ,
108
+ new Argument < string > ( defaultValue : "auto" ) . FromAmong ( GetCacheSuggestions ( ) ) ) ;
112
109
113
110
Option IgnoreColumns ( ) =>
114
- new Option ( new List < string > ( ) { "--ignore-columns" } , "Specify the columns that needs to be ignored in the given dataset." ,
115
- new Argument < List < string > > ( ) ) ;
111
+ new Option ( new List < string > ( ) { "--ignore-columns" } , "Specify the columns that needs to be ignored in the given dataset." ,
112
+ new Argument < List < string > > ( defaultValue : new List < string > ( ) ) ) ;
116
113
117
114
}
118
115
0 commit comments