The purpose of this repository is to provide a way for people to generate random "placeholder text" -- with a Markov Chain.
https://www.craigoates.net/Software/project/12
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.9 KiB
90 lines
3.9 KiB
using Console.Waterworks; |
|
using Console.Waterworks.Attributes; |
|
using System; |
|
using static WetPancake.Pancake; |
|
using static System.Environment; |
|
using System.Diagnostics; |
|
using System.Threading.Tasks; |
|
using Microsoft.FSharp.Control; |
|
using Microsoft.FSharp.Core; |
|
using System.Threading; |
|
|
|
namespace WetPancakeCLI |
|
{ |
|
public static class ConsoleCommands |
|
{ |
|
// Pass these in when running an FSharpAsync task. |
|
// Examples are within the command-methods. |
|
static FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None; |
|
static FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None; |
|
|
|
[ListCommand] |
|
[Description("Prints a test message to the console.")] |
|
[Parameters("None")] |
|
[Usage("> Test")] |
|
public static string Test() => "SUCCESS: Console.Waterworks is wired into Wet Pancake CLI."; |
|
|
|
[ListCommand] |
|
[Description("Lists out the commands this program offers.")] |
|
[Parameters("None")] |
|
[Usage("> Help")] |
|
public static string Help() => new CW_Liaison().RequestHelpDocumentation("WetPancakeCLI"); |
|
|
|
[ListCommand] |
|
[Description("Exits out of the program.")] |
|
[Parameters("None")] |
|
[Usage("> Exit")] |
|
public static void Exit() => Environment.Exit(ExitCode); |
|
|
|
[ListCommand] |
|
[Description("Generates random text, the number of sentences generated is randomly determined.")] |
|
[Parameters("None")] |
|
[Usage("> GenerateRandomText")] |
|
public static string GenerateRandomText() |
|
{ |
|
string result = String.Empty; |
|
try { return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result; } |
|
catch (Exception e) |
|
{ |
|
Debug.WriteLine(e.Message); |
|
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command..."); |
|
return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result; |
|
} |
|
} |
|
|
|
[ListCommand] |
|
[Description("Generates text using the gibberish level and number of sentences specified by the user. Gibberish level must be greater the 1.")] |
|
[Parameters("gibberish level: int, sentences: int")] |
|
[Usage("> GenerateText 5 10")] |
|
public static string GenerateText(int gibberishLevel, int sentences) |
|
{ |
|
if (gibberishLevel < 2) return "Please enter a gibberish level greater than 1."; |
|
try { return RequestText(gibberishLevel, sentences); } |
|
catch (Exception e) |
|
{ |
|
Debug.WriteLine(e.Message); |
|
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command..."); |
|
return RequestText(gibberishLevel, sentences); |
|
} |
|
} |
|
|
|
// YOU ARE WORKING IN HERE... (0.5-P1) |
|
[ListCommand] |
|
[Description("Loads the specified .txt file and generates text based on it using the gibberish level and number of sentences specified by the user. Gibberish level must be greater the 1.")] |
|
[Parameters("gibberish level: int, sentences: int, file path: string")] |
|
[Usage("> RequestTextFromFile 3 6 C:/yourfile.txt")] |
|
public static string GenerateTextFromFile(int gibberishLevel, int sentences, string filePath) |
|
{ |
|
// Could do with checking if the file type is .txt... |
|
if (gibberishLevel < 2) return "Please enter a gibberish level greater than 1."; |
|
try |
|
{ return RequestTextFromFile(gibberishLevel, sentences, filePath); } |
|
catch (Exception e) |
|
{ |
|
Debug.WriteLine(e.Message); |
|
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command..."); |
|
return RequestTextFromFile(gibberishLevel, sentences, filePath); |
|
} |
|
} |
|
} |
|
}
|
|
|