Skip to content

Commit 8463bae

Browse files
authored
upgrade commandline and renaming (dotnet#221)
* upgrade commandline and renaming * renaming fields
1 parent b629d78 commit 8463bae

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void GeneratedTrainCodeTest()
2828
(Pipeline pipeline,
2929
ColumnInferenceResults columnInference) = GetMockedPipelineAndInference();
3030

31-
var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorOptions()
31+
var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorSettings()
3232
{
3333
MlTask = TaskKind.BinaryClassification,
3434
OutputBaseDir = null,
@@ -51,7 +51,7 @@ public void GeneratedProjectCodeTest()
5151
(Pipeline pipeline,
5252
ColumnInferenceResults columnInference) = GetMockedPipelineAndInference();
5353

54-
var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorOptions()
54+
var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorSettings()
5555
{
5656
MlTask = TaskKind.BinaryClassification,
5757
OutputBaseDir = null,
@@ -74,7 +74,7 @@ public void GeneratedHelperCodeTest()
7474
(Pipeline pipeline,
7575
ColumnInferenceResults columnInference) = GetMockedPipelineAndInference();
7676

77-
var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorOptions()
77+
var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorSettings()
7878
{
7979
MlTask = TaskKind.BinaryClassification,
8080
OutputBaseDir = null,

src/mlnet.Test/CommandLineTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void TestMinimumCommandLineArgs()
2020
bool parsingSuccessful = false;
2121

2222
// Create handler outside so that commandline and the handler is decoupled and testable.
23-
var handler = CommandHandler.Create<NewCommandOptions>(
23+
var handler = CommandHandler.Create<NewCommandSettings>(
2424
(opt) =>
2525
{
2626
parsingSuccessful = true;
@@ -48,7 +48,7 @@ public void TestCommandLineArgsFailTest()
4848
bool parsingSuccessful = false;
4949

5050
// Create handler outside so that commandline and the handler is decoupled and testable.
51-
var handler = CommandHandler.Create<NewCommandOptions>(
51+
var handler = CommandHandler.Create<NewCommandSettings>(
5252
(opt) =>
5353
{
5454
parsingSuccessful = true;
@@ -100,7 +100,7 @@ public void TestCommandLineArgsValuesTest()
100100
var falseString = "false";
101101

102102
// Create handler outside so that commandline and the handler is decoupled and testable.
103-
var handler = CommandHandler.Create<NewCommandOptions>(
103+
var handler = CommandHandler.Create<NewCommandSettings>(
104104
(opt) =>
105105
{
106106
parsingSuccessful = true;
@@ -141,7 +141,7 @@ public void TestCommandLineArgsMutuallyExclusiveArgsTest()
141141
var labelName = "Label";
142142

143143
// Create handler outside so that commandline and the handler is decoupled and testable.
144-
var handler = CommandHandler.Create<NewCommandOptions>(
144+
var handler = CommandHandler.Create<NewCommandSettings>(
145145
(opt) =>
146146
{
147147
parsingSuccessful = true;

src/mlnet/CodeGenerator/CSharp/CodeGenerator.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ namespace Microsoft.ML.CLI.CodeGenerator.CSharp
2020
internal class CodeGenerator : IProjectGenerator
2121
{
2222
private readonly Pipeline pipeline;
23-
private readonly CodeGeneratorOptions options;
23+
private readonly CodeGeneratorSettings settings;
2424
private readonly ColumnInferenceResults columnInferenceResult;
2525

26-
internal CodeGenerator(Pipeline pipeline, ColumnInferenceResults columnInferenceResult, CodeGeneratorOptions options)
26+
internal CodeGenerator(Pipeline pipeline, ColumnInferenceResults columnInferenceResult, CodeGeneratorSettings settings)
2727
{
2828
this.pipeline = pipeline;
2929
this.columnInferenceResult = columnInferenceResult;
30-
this.options = options;
30+
this.settings = settings;
3131
}
3232

3333
public void GenerateOutput()
@@ -51,7 +51,7 @@ public void GenerateOutput()
5151
var classLabels = this.GenerateClassLabels();
5252

5353
// Get Namespace
54-
var namespaceValue = Utils.Normalize(options.OutputName);
54+
var namespaceValue = Utils.Normalize(settings.OutputName);
5555

5656
// Generate code for training and scoring
5757
var trainFileContent = GenerateTrainCode(usings, trainer, transforms, columns, classLabels, namespaceValue);
@@ -70,13 +70,13 @@ public void GenerateOutput()
7070

7171
internal void WriteOutputToFiles(string trainScoreCode, string projectSourceCode, string consoleHelperCode)
7272
{
73-
if (!Directory.Exists(options.OutputBaseDir))
73+
if (!Directory.Exists(settings.OutputBaseDir))
7474
{
75-
Directory.CreateDirectory(options.OutputBaseDir);
75+
Directory.CreateDirectory(settings.OutputBaseDir);
7676
}
77-
File.WriteAllText($"{options.OutputBaseDir}/Program.cs", trainScoreCode);
78-
File.WriteAllText($"{options.OutputBaseDir}/{options.OutputName}.csproj", projectSourceCode);
79-
File.WriteAllText($"{options.OutputBaseDir}/ConsoleHelper.cs", consoleHelperCode);
77+
File.WriteAllText($"{settings.OutputBaseDir}/Program.cs", trainScoreCode);
78+
File.WriteAllText($"{settings.OutputBaseDir}/{settings.OutputName}.csproj", projectSourceCode);
79+
File.WriteAllText($"{settings.OutputBaseDir}/ConsoleHelper.cs", consoleHelperCode);
8080
}
8181

8282
internal static string GenerateConsoleHelper(string namespaceValue)
@@ -105,11 +105,11 @@ internal string GenerateTrainCode(string usings, string trainer, List<string> tr
105105
Trainer = trainer,
106106
ClassLabels = classLabels,
107107
GeneratedUsings = usings,
108-
Path = options.TrainDataset.FullName,
109-
TestPath = options.TestDataset?.FullName,
110-
TaskType = options.MlTask.ToString(),
108+
Path = settings.TrainDataset.FullName,
109+
TestPath = settings.TestDataset?.FullName,
110+
TaskType = settings.MlTask.ToString(),
111111
Namespace = namespaceValue,
112-
LabelName = options.LabelName
112+
LabelName = settings.LabelName
113113
};
114114

115115
return trainingAndScoringCodeGen.TransformText();

src/mlnet/CodeGenerator/CSharp/CodeGeneratorOptions.cs renamed to src/mlnet/CodeGenerator/CSharp/CodeGeneratorSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.ML.CLI.CodeGenerator.CSharp
55
{
6-
internal class CodeGeneratorOptions
6+
internal class CodeGeneratorSettings
77
{
88
public string LabelName { get; internal set; }
99
internal string OutputName { get; set; }

src/mlnet/Commands/New/NewCommandHandler.cs

+20-20
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ namespace Microsoft.ML.CLI.Commands.New
1515
{
1616
internal class NewCommand : ICommand
1717
{
18-
private NewCommandOptions options;
18+
private NewCommandSettings settings;
1919
private static Logger logger = LogManager.GetCurrentClassLogger();
2020
private TaskKind taskKind;
2121

22-
internal NewCommand(NewCommandOptions options)
22+
internal NewCommand(NewCommandSettings settings)
2323
{
24-
this.options = options;
25-
this.taskKind = Utils.GetTaskKind(options.MlTask);
24+
this.settings = settings;
25+
this.taskKind = Utils.GetTaskKind(settings.MlTask);
2626
}
2727

2828
public void Execute()
@@ -54,7 +54,7 @@ public void Execute()
5454

5555
// Explore the models
5656
(Pipeline, ITransformer) result = default;
57-
Console.WriteLine($"{Strings.ExplorePipeline}: {options.MlTask}");
57+
Console.WriteLine($"{Strings.ExplorePipeline}: {settings.MlTask}");
5858
try
5959
{
6060
result = ExploreModels(context, trainData, validationData, sanitized_Label_Name);
@@ -75,7 +75,7 @@ public void Execute()
7575

7676
// Save the model
7777
logger.Log(LogLevel.Info, Strings.SavingBestModel);
78-
Utils.SaveModel(model, options.OutputPath.FullName, $"model.zip", context);
78+
Utils.SaveModel(model, settings.OutputPath.FullName, $"model.zip", context);
7979

8080
// Generate the Project
8181
GenerateProject(columnInference, pipeline, sanitized_Label_Name);
@@ -86,14 +86,14 @@ internal ColumnInferenceResults InferColumns(MLContext context)
8686
//Check what overload method of InferColumns needs to be called.
8787
logger.Log(LogLevel.Info, Strings.InferColumns);
8888
ColumnInferenceResults columnInference = null;
89-
var dataset = options.Dataset.FullName;
90-
if (options.LabelColumnName != null)
89+
var dataset = settings.Dataset.FullName;
90+
if (settings.LabelColumnName != null)
9191
{
92-
columnInference = context.AutoInference().InferColumns(dataset, options.LabelColumnName, groupColumns: false);
92+
columnInference = context.AutoInference().InferColumns(dataset, settings.LabelColumnName, groupColumns: false);
9393
}
9494
else
9595
{
96-
columnInference = context.AutoInference().InferColumns(dataset, options.LabelColumnIndex, hasHeader: options.HasHeader, groupColumns: false);
96+
columnInference = context.AutoInference().InferColumns(dataset, settings.LabelColumnIndex, hasHeader: settings.HasHeader, groupColumns: false);
9797
}
9898

9999
return columnInference;
@@ -102,17 +102,17 @@ internal ColumnInferenceResults InferColumns(MLContext context)
102102
internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline pipeline, string labelName)
103103
{
104104
//Generate code
105-
logger.Log(LogLevel.Info, $"{Strings.GenerateProject} : {options.OutputPath.FullName}");
105+
logger.Log(LogLevel.Info, $"{Strings.GenerateProject} : {settings.OutputPath.FullName}");
106106
var codeGenerator = new CodeGenerator.CSharp.CodeGenerator(
107107
pipeline,
108108
columnInference,
109-
new CodeGeneratorOptions()
109+
new CodeGeneratorSettings()
110110
{
111-
TrainDataset = options.Dataset,
111+
TrainDataset = settings.Dataset,
112112
MlTask = taskKind,
113-
TestDataset = options.TestDataset,
114-
OutputName = options.Name,
115-
OutputBaseDir = options.OutputPath.FullName,
113+
TestDataset = settings.TestDataset,
114+
OutputName = settings.Name,
115+
OutputBaseDir = settings.OutputPath.FullName,
116116
LabelName = labelName
117117
});
118118
codeGenerator.GenerateOutput();
@@ -130,7 +130,7 @@ internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline p
130130
var result = context.AutoInference()
131131
.CreateBinaryClassificationExperiment(new BinaryExperimentSettings()
132132
{
133-
MaxInferenceTimeInSeconds = options.MaxExplorationTime,
133+
MaxInferenceTimeInSeconds = settings.MaxExplorationTime,
134134
ProgressHandler = progressReporter
135135
})
136136
.Execute(trainData, validationData, new ColumnInformation() { LabelColumn = labelName });
@@ -146,7 +146,7 @@ internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline p
146146
var result = context.AutoInference()
147147
.CreateRegressionExperiment(new RegressionExperimentSettings()
148148
{
149-
MaxInferenceTimeInSeconds = options.MaxExplorationTime,
149+
MaxInferenceTimeInSeconds = settings.MaxExplorationTime,
150150
ProgressHandler = progressReporter
151151
}).Execute(trainData, validationData, new ColumnInformation() { LabelColumn = labelName });
152152
logger.Log(LogLevel.Info, Strings.RetrieveBestPipeline);
@@ -170,8 +170,8 @@ internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline p
170170
var textLoader = context.Data.CreateTextLoader(textLoaderArgs);
171171

172172
logger.Log(LogLevel.Info, Strings.LoadData);
173-
var trainData = textLoader.Read(options.Dataset.FullName);
174-
var validationData = options.ValidationDataset == null ? null : textLoader.Read(options.ValidationDataset.FullName);
173+
var trainData = textLoader.Read(settings.Dataset.FullName);
174+
var validationData = settings.ValidationDataset == null ? null : textLoader.Read(settings.ValidationDataset.FullName);
175175

176176
return (trainData, validationData);
177177
}

src/mlnet/Commands/New/NewCommandOptions.cs renamed to src/mlnet/Commands/New/NewCommandSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.ML.CLI.Data
88
{
9-
public class NewCommandOptions
9+
public class NewCommandSettings
1010
{
1111
public string Name { get; set; }
1212

src/mlnet/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Program
1919
public static void Main(string[] args)
2020
{
2121
// Create handler outside so that commandline and the handler is decoupled and testable.
22-
var handler = CommandHandler.Create<NewCommandOptions>(
22+
var handler = CommandHandler.Create<NewCommandSettings>(
2323
(options) =>
2424
{
2525
// Map the verbosity to internal levels

src/mlnet/mlnet.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />
1515
<PackageReference Include="NLog" Version="4.5.11" />
16-
<PackageReference Include="System.CommandLine.Experimental" Version="0.1.0-alpha-63820-01" />
16+
<PackageReference Include="System.CommandLine.Experimental" Version="0.1.0-alpha-63825-02" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

0 commit comments

Comments
 (0)