Skip to content

Commit

Permalink
upgrade commandline and renaming (dotnet#221)
Browse files Browse the repository at this point in the history
* upgrade commandline and renaming

* renaming fields
  • Loading branch information
srsaggam authored and Dmitry-A committed Aug 22, 2019
1 parent 4e15684 commit 712ad16
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/mlnet.Test/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NewCommandOptions>(
var handler = CommandHandler.Create<NewCommandSettings>(
(opt) =>
{
parsingSuccessful = true;
Expand Down Expand Up @@ -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<NewCommandOptions>(
var handler = CommandHandler.Create<NewCommandSettings>(
(opt) =>
{
parsingSuccessful = true;
Expand Down Expand Up @@ -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<NewCommandOptions>(
var handler = CommandHandler.Create<NewCommandSettings>(
(opt) =>
{
parsingSuccessful = true;
Expand Down Expand Up @@ -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<NewCommandOptions>(
var handler = CommandHandler.Create<NewCommandSettings>(
(opt) =>
{
parsingSuccessful = true;
Expand Down
26 changes: 13 additions & 13 deletions src/mlnet/CodeGenerator/CSharp/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -105,11 +105,11 @@ internal string GenerateTrainCode(string usings, string trainer, List<string> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
40 changes: 20 additions & 20 deletions src/mlnet/Commands/New/NewCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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 });
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.ML.CLI.Data
{
public class NewCommandOptions
public class NewCommandSettings
{
public string Name { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/mlnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NewCommandOptions>(
var handler = CommandHandler.Create<NewCommandSettings>(
(options) =>
{
// Map the verbosity to internal levels
Expand Down
2 changes: 1 addition & 1 deletion src/mlnet/mlnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />
<PackageReference Include="NLog" Version="4.5.11" />
<PackageReference Include="System.CommandLine.Experimental" Version="0.1.0-alpha-63820-01" />
<PackageReference Include="System.CommandLine.Experimental" Version="0.1.0-alpha-63825-02" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 712ad16

Please sign in to comment.