Browse Source

Added validation checks to RequestText (in lib.).

The checks in the console program still remain.
master
Craig Oates 6 years ago
parent
commit
3e8e830d6f
  1. 8
      WetPancake/DataProcessing.fs
  2. 22
      WetPancake/ProductServices.fs
  3. 3
      WetPancakeCLI/ConsoleCommands.cs

8
WetPancake/DataProcessing.fs

@ -8,6 +8,14 @@
let ConcatToString words = String.concat " " words
let GibberishLevelIsValid gibberishLevel =
if gibberishLevel > 1 && gibberishLevel < 21 then true
else false
let SentencesIsValid sentences =
if sentences >= 1 then true
else false
let SortIntoGroups groupSize text =
SplitText @"\s+" text // Splits text where there is a space.
|> Seq.windowed groupSize

22
WetPancake/ProductServices.fs

@ -9,6 +9,7 @@ module Pancake =
open DataProcessing
open DataStructuring
open DataServices
open System
let RequestRandomTextAsync() =
async {
@ -22,12 +23,21 @@ module Pancake =
let RequestTextAsync (gibberishLevel: int) (sentences: int) =
async {
let data =
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap
return GenerateMarkovText sentences data
try
if GibberishLevelIsValid gibberishLevel then
if SentencesIsValid sentences then
let data =
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap
return GenerateMarkovText sentences data
else return raise (ArgumentException("Invalid argument. Must be greater than 0.", "sentences"))
else
return raise (ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel"))
with
| :? ArgumentException as ex->
return ex.Message
}
let RequestTextFromFileAsync (gibberishLevel: int) (sentences: int) (filePath: string) =

3
WetPancakeCLI/ConsoleCommands.cs

@ -68,8 +68,7 @@ namespace WetPancakeCLI
catch (Exception e)
{
Debug.WriteLine(e.Message);
WriteLine("[WARNING] Unable to complete last request. Re-executing command...");
return FSharpAsync.StartAsTask(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
return e.Message;
}
}

Loading…
Cancel
Save