- Hands-On Machine Learning with ML.NET
- Jarred Capellman
- 170字
- 2021-06-24 16:43:30
The Program class
Those of you who have created console applications should be familiar with the Program class and the Main method within. We will follow this structure for other console-based applications throughout the remainder of the book. The following code block contains the program class from which the application will begin execution:
using System;
using chapter02.ML;
namespace chapter02
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine($"Invalid arguments passed in, exiting.{Environment.NewLine}" + $"{Environment.NewLine}Usage: {Environment.NewLine}" +
$"predict <sentence of text to predict against>{Environment.NewLine}" +
$"or {Environment.NewLine}" +
$"train <path to training data file>{Environment.NewLine}");
return;
}
switch (args[0])
{
case "predict":
new Predictor().Predict(args[1]);
break;
case "train":
new Trainer().Train(args[1]);
break;
default:
Console.WriteLine($"{args[0]} is an invalid option");
break;
}
}
}
}
This constitutes a fairly straightforward method implementation for those familiar with parsing command-line arguments. A simple two-argument approach is used as the help text indicates.
When executing a more complex command-line application that takes in several arguments (optional and required), Microsoft has provided a simple-to-use NuGet package, which is available here: https://github.com/dotnet/command-line-api
推薦閱讀
- JavaScript前端開發模塊化教程
- Docker技術入門與實戰(第3版)
- Bootstrap Essentials
- Learning Laravel 4 Application Development
- 數據結構(C語言)
- 深入RabbitMQ
- C# 8.0核心技術指南(原書第8版)
- RabbitMQ Essentials
- The Professional ScrumMaster’s Handbook
- Android Studio Cookbook
- Python Deep Learning
- Photoshop智能手機APP界面設計
- 人人都能開發RPA機器人:UiPath從入門到實戰
- Microsoft Dynamics GP 2013 Cookbook
- Processing開發實戰