From 712ad1622005be9f62ffe60601ce6a443ac6bf77 Mon Sep 17 00:00:00 2001 From: srsaggam <41802116+srsaggam@users.noreply.github.com> Date: Mon, 25 Feb 2019 20:14:50 -0800 Subject: [PATCH] upgrade commandline and renaming (#221) * upgrade commandline and renaming * renaming fields --- .../ConsoleCodeGeneratorTests.cs | 6 +-- src/mlnet.Test/CommandLineTests.cs | 8 ++-- .../CodeGenerator/CSharp/CodeGenerator.cs | 26 ++++++------ ...torOptions.cs => CodeGeneratorSettings.cs} | 2 +- src/mlnet/Commands/New/NewCommandHandler.cs | 40 +++++++++---------- ...ommandOptions.cs => NewCommandSettings.cs} | 2 +- src/mlnet/Program.cs | 2 +- src/mlnet/mlnet.csproj | 2 +- 8 files changed, 44 insertions(+), 44 deletions(-) rename src/mlnet/CodeGenerator/CSharp/{CodeGeneratorOptions.cs => CodeGeneratorSettings.cs} (91%) rename src/mlnet/Commands/New/{NewCommandOptions.cs => NewCommandSettings.cs} (95%) diff --git a/src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.cs b/src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.cs index c2580fcb5f5..0ac31074356 100644 --- a/src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.cs +++ b/src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.cs @@ -28,7 +28,7 @@ public void GeneratedTrainCodeTest() (Pipeline pipeline, ColumnInferenceResults columnInference) = GetMockedPipelineAndInference(); - var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorOptions() + var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorSettings() { MlTask = TaskKind.BinaryClassification, OutputBaseDir = null, @@ -51,7 +51,7 @@ public void GeneratedProjectCodeTest() (Pipeline pipeline, ColumnInferenceResults columnInference) = GetMockedPipelineAndInference(); - var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorOptions() + var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorSettings() { MlTask = TaskKind.BinaryClassification, OutputBaseDir = null, @@ -74,7 +74,7 @@ public void GeneratedHelperCodeTest() (Pipeline pipeline, ColumnInferenceResults columnInference) = GetMockedPipelineAndInference(); - var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorOptions() + var consoleCodeGen = new CodeGenerator(pipeline, columnInference, new CodeGeneratorSettings() { MlTask = TaskKind.BinaryClassification, OutputBaseDir = null, diff --git a/src/mlnet.Test/CommandLineTests.cs b/src/mlnet.Test/CommandLineTests.cs index 6ed8a622d4f..4019887fde1 100644 --- a/src/mlnet.Test/CommandLineTests.cs +++ b/src/mlnet.Test/CommandLineTests.cs @@ -20,7 +20,7 @@ public void TestMinimumCommandLineArgs() bool parsingSuccessful = false; // Create handler outside so that commandline and the handler is decoupled and testable. - var handler = CommandHandler.Create( + var handler = CommandHandler.Create( (opt) => { parsingSuccessful = true; @@ -48,7 +48,7 @@ public void TestCommandLineArgsFailTest() bool parsingSuccessful = false; // Create handler outside so that commandline and the handler is decoupled and testable. - var handler = CommandHandler.Create( + var handler = CommandHandler.Create( (opt) => { parsingSuccessful = true; @@ -100,7 +100,7 @@ public void TestCommandLineArgsValuesTest() var falseString = "false"; // Create handler outside so that commandline and the handler is decoupled and testable. - var handler = CommandHandler.Create( + var handler = CommandHandler.Create( (opt) => { parsingSuccessful = true; @@ -141,7 +141,7 @@ public void TestCommandLineArgsMutuallyExclusiveArgsTest() var labelName = "Label"; // Create handler outside so that commandline and the handler is decoupled and testable. - var handler = CommandHandler.Create( + var handler = CommandHandler.Create( (opt) => { parsingSuccessful = true; diff --git a/src/mlnet/CodeGenerator/CSharp/CodeGenerator.cs b/src/mlnet/CodeGenerator/CSharp/CodeGenerator.cs index 016560bf11e..74bb8274b5c 100644 --- a/src/mlnet/CodeGenerator/CSharp/CodeGenerator.cs +++ b/src/mlnet/CodeGenerator/CSharp/CodeGenerator.cs @@ -20,14 +20,14 @@ namespace Microsoft.ML.CLI.CodeGenerator.CSharp internal class CodeGenerator : IProjectGenerator { private readonly Pipeline pipeline; - private readonly CodeGeneratorOptions options; + private readonly CodeGeneratorSettings settings; private readonly ColumnInferenceResults columnInferenceResult; - internal CodeGenerator(Pipeline pipeline, ColumnInferenceResults columnInferenceResult, CodeGeneratorOptions options) + internal CodeGenerator(Pipeline pipeline, ColumnInferenceResults columnInferenceResult, CodeGeneratorSettings settings) { this.pipeline = pipeline; this.columnInferenceResult = columnInferenceResult; - this.options = options; + this.settings = settings; } public void GenerateOutput() @@ -51,7 +51,7 @@ public void GenerateOutput() var classLabels = this.GenerateClassLabels(); // Get Namespace - var namespaceValue = Utils.Normalize(options.OutputName); + var namespaceValue = Utils.Normalize(settings.OutputName); // Generate code for training and scoring var trainFileContent = GenerateTrainCode(usings, trainer, transforms, columns, classLabels, namespaceValue); @@ -70,13 +70,13 @@ public void GenerateOutput() internal void WriteOutputToFiles(string trainScoreCode, string projectSourceCode, string consoleHelperCode) { - if (!Directory.Exists(options.OutputBaseDir)) + if (!Directory.Exists(settings.OutputBaseDir)) { - Directory.CreateDirectory(options.OutputBaseDir); + Directory.CreateDirectory(settings.OutputBaseDir); } - File.WriteAllText($"{options.OutputBaseDir}/Program.cs", trainScoreCode); - File.WriteAllText($"{options.OutputBaseDir}/{options.OutputName}.csproj", projectSourceCode); - File.WriteAllText($"{options.OutputBaseDir}/ConsoleHelper.cs", consoleHelperCode); + File.WriteAllText($"{settings.OutputBaseDir}/Program.cs", trainScoreCode); + File.WriteAllText($"{settings.OutputBaseDir}/{settings.OutputName}.csproj", projectSourceCode); + File.WriteAllText($"{settings.OutputBaseDir}/ConsoleHelper.cs", consoleHelperCode); } internal static string GenerateConsoleHelper(string namespaceValue) @@ -105,11 +105,11 @@ internal string GenerateTrainCode(string usings, string trainer, List tr Trainer = trainer, ClassLabels = classLabels, GeneratedUsings = usings, - Path = options.TrainDataset.FullName, - TestPath = options.TestDataset?.FullName, - TaskType = options.MlTask.ToString(), + Path = settings.TrainDataset.FullName, + TestPath = settings.TestDataset?.FullName, + TaskType = settings.MlTask.ToString(), Namespace = namespaceValue, - LabelName = options.LabelName + LabelName = settings.LabelName }; return trainingAndScoringCodeGen.TransformText(); diff --git a/src/mlnet/CodeGenerator/CSharp/CodeGeneratorOptions.cs b/src/mlnet/CodeGenerator/CSharp/CodeGeneratorSettings.cs similarity index 91% rename from src/mlnet/CodeGenerator/CSharp/CodeGeneratorOptions.cs rename to src/mlnet/CodeGenerator/CSharp/CodeGeneratorSettings.cs index a75c4e465b5..8b5751de4ac 100644 --- a/src/mlnet/CodeGenerator/CSharp/CodeGeneratorOptions.cs +++ b/src/mlnet/CodeGenerator/CSharp/CodeGeneratorSettings.cs @@ -3,7 +3,7 @@ namespace Microsoft.ML.CLI.CodeGenerator.CSharp { - internal class CodeGeneratorOptions + internal class CodeGeneratorSettings { public string LabelName { get; internal set; } internal string OutputName { get; set; } diff --git a/src/mlnet/Commands/New/NewCommandHandler.cs b/src/mlnet/Commands/New/NewCommandHandler.cs index e490c559720..4ab32b6d4bf 100644 --- a/src/mlnet/Commands/New/NewCommandHandler.cs +++ b/src/mlnet/Commands/New/NewCommandHandler.cs @@ -15,14 +15,14 @@ namespace Microsoft.ML.CLI.Commands.New { internal class NewCommand : ICommand { - private NewCommandOptions options; + private NewCommandSettings settings; private static Logger logger = LogManager.GetCurrentClassLogger(); private TaskKind taskKind; - internal NewCommand(NewCommandOptions options) + internal NewCommand(NewCommandSettings settings) { - this.options = options; - this.taskKind = Utils.GetTaskKind(options.MlTask); + this.settings = settings; + this.taskKind = Utils.GetTaskKind(settings.MlTask); } public void Execute() @@ -54,7 +54,7 @@ public void Execute() // Explore the models (Pipeline, ITransformer) result = default; - Console.WriteLine($"{Strings.ExplorePipeline}: {options.MlTask}"); + Console.WriteLine($"{Strings.ExplorePipeline}: {settings.MlTask}"); try { result = ExploreModels(context, trainData, validationData, sanitized_Label_Name); @@ -75,7 +75,7 @@ public void Execute() // Save the model logger.Log(LogLevel.Info, Strings.SavingBestModel); - Utils.SaveModel(model, options.OutputPath.FullName, $"model.zip", context); + Utils.SaveModel(model, settings.OutputPath.FullName, $"model.zip", context); // Generate the Project GenerateProject(columnInference, pipeline, sanitized_Label_Name); @@ -86,14 +86,14 @@ internal ColumnInferenceResults InferColumns(MLContext context) //Check what overload method of InferColumns needs to be called. logger.Log(LogLevel.Info, Strings.InferColumns); ColumnInferenceResults columnInference = null; - var dataset = options.Dataset.FullName; - if (options.LabelColumnName != null) + var dataset = settings.Dataset.FullName; + if (settings.LabelColumnName != null) { - columnInference = context.AutoInference().InferColumns(dataset, options.LabelColumnName, groupColumns: false); + columnInference = context.AutoInference().InferColumns(dataset, settings.LabelColumnName, groupColumns: false); } else { - columnInference = context.AutoInference().InferColumns(dataset, options.LabelColumnIndex, hasHeader: options.HasHeader, groupColumns: false); + columnInference = context.AutoInference().InferColumns(dataset, settings.LabelColumnIndex, hasHeader: settings.HasHeader, groupColumns: false); } return columnInference; @@ -102,17 +102,17 @@ internal ColumnInferenceResults InferColumns(MLContext context) internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline pipeline, string labelName) { //Generate code - logger.Log(LogLevel.Info, $"{Strings.GenerateProject} : {options.OutputPath.FullName}"); + logger.Log(LogLevel.Info, $"{Strings.GenerateProject} : {settings.OutputPath.FullName}"); var codeGenerator = new CodeGenerator.CSharp.CodeGenerator( pipeline, columnInference, - new CodeGeneratorOptions() + new CodeGeneratorSettings() { - TrainDataset = options.Dataset, + TrainDataset = settings.Dataset, MlTask = taskKind, - TestDataset = options.TestDataset, - OutputName = options.Name, - OutputBaseDir = options.OutputPath.FullName, + TestDataset = settings.TestDataset, + OutputName = settings.Name, + OutputBaseDir = settings.OutputPath.FullName, LabelName = labelName }); codeGenerator.GenerateOutput(); @@ -130,7 +130,7 @@ internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline p var result = context.AutoInference() .CreateBinaryClassificationExperiment(new BinaryExperimentSettings() { - MaxInferenceTimeInSeconds = options.MaxExplorationTime, + MaxInferenceTimeInSeconds = settings.MaxExplorationTime, ProgressHandler = progressReporter }) .Execute(trainData, validationData, new ColumnInformation() { LabelColumn = labelName }); @@ -146,7 +146,7 @@ internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline p var result = context.AutoInference() .CreateRegressionExperiment(new RegressionExperimentSettings() { - MaxInferenceTimeInSeconds = options.MaxExplorationTime, + MaxInferenceTimeInSeconds = settings.MaxExplorationTime, ProgressHandler = progressReporter }).Execute(trainData, validationData, new ColumnInformation() { LabelColumn = labelName }); logger.Log(LogLevel.Info, Strings.RetrieveBestPipeline); @@ -170,8 +170,8 @@ internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline p var textLoader = context.Data.CreateTextLoader(textLoaderArgs); logger.Log(LogLevel.Info, Strings.LoadData); - var trainData = textLoader.Read(options.Dataset.FullName); - var validationData = options.ValidationDataset == null ? null : textLoader.Read(options.ValidationDataset.FullName); + var trainData = textLoader.Read(settings.Dataset.FullName); + var validationData = settings.ValidationDataset == null ? null : textLoader.Read(settings.ValidationDataset.FullName); return (trainData, validationData); } diff --git a/src/mlnet/Commands/New/NewCommandOptions.cs b/src/mlnet/Commands/New/NewCommandSettings.cs similarity index 95% rename from src/mlnet/Commands/New/NewCommandOptions.cs rename to src/mlnet/Commands/New/NewCommandSettings.cs index c8fdc96b7d0..ddf0499049d 100644 --- a/src/mlnet/Commands/New/NewCommandOptions.cs +++ b/src/mlnet/Commands/New/NewCommandSettings.cs @@ -6,7 +6,7 @@ namespace Microsoft.ML.CLI.Data { - public class NewCommandOptions + public class NewCommandSettings { public string Name { get; set; } diff --git a/src/mlnet/Program.cs b/src/mlnet/Program.cs index 417569aa542..efcdcf5bbe7 100644 --- a/src/mlnet/Program.cs +++ b/src/mlnet/Program.cs @@ -19,7 +19,7 @@ class Program public static void Main(string[] args) { // Create handler outside so that commandline and the handler is decoupled and testable. - var handler = CommandHandler.Create( + var handler = CommandHandler.Create( (options) => { // Map the verbosity to internal levels diff --git a/src/mlnet/mlnet.csproj b/src/mlnet/mlnet.csproj index 767384afb45..ec05984639b 100644 --- a/src/mlnet/mlnet.csproj +++ b/src/mlnet/mlnet.csproj @@ -13,7 +13,7 @@ - +