Browse Source

Merge pull request #13 from CraigOates/0.7-p1

0.7 p1
master
Craig Oates 6 years ago committed by GitHub
parent
commit
f1d222b363
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      TestCentre/Helpers.fs
  2. 17
      TestCentre/InputGeneration.fs
  3. 180
      TestCentre/PropertyTests.fs
  4. 1
      TestCentre/TestCentre.fsproj
  5. 2
      TestCentre/TextFiles/desktop-clock-info.txt
  6. 197
      TestCentre/UnitTests.fs
  7. 1
      WetPancake/AssemblyInfo.fs
  8. 4
      WetPancake/DataCleaning.fs
  9. 8
      WetPancake/DataProcessing.fs
  10. 66
      WetPancake/DataServices.fs
  11. 205
      WetPancake/ProductServices.fs
  12. 68
      WetPancake/Script.fsx
  13. 130
      WetPancakeCLI/ConsoleCommands.cs
  14. 18
      WetPancakeCLI/Properties/AssemblyInfo.cs
  15. 51
      WetPancakeCLI/WetPancakeCLI.csproj
  16. BIN
      WetPancakeCLI/logo.ico
  17. BIN
      WetPancakeCLI/wet-pancake.ico

28
TestCentre/Helpers.fs

@ -0,0 +1,28 @@
module Helpers
open System.Text.RegularExpressions
open System
// The main aim of these functions is to reduce code in the unit and property tests.
// You will most-likely find them in the "contents" tests (for unit and property).
let CountSentences text =
let count =
Regex.Split(text, @"(?<=[\.\!\?]\s)")
|> Array.length
count
let EndsAsIntended (text: string) =
match text.Chars (text.Length - 1) with
| '.' -> true
| '!' -> true
| '?' -> true
| _ -> false
let RandomBool () =
let x = Random().Next(100)
match x with
| x when x % 2 <> 0 -> false
| x when x % 2 = 0 -> true
| _ -> failwith "Unable to generate a random bool."

17
TestCentre/InputGeneration.fs

@ -2,6 +2,7 @@
open System
open TestingConstants
open Helpers
let ValidGibberishLevelInput () =
let testInputs = [|2 .. 20|]
@ -20,4 +21,18 @@
let ValidFileInput () =
let testInputs = [|ConsoleWaterworks; DesktopClock; TestPost; WordGenerator|]
let index = Random().Next(0, testInputs.Length)
testInputs.[index]
testInputs.[index]
(* Note: Code-Smell for "Defaults"
==================================================================================================================
DefaultTestSentence & DefaultSentenceCount should be used in tandem.
Treat is as a code-smell in the (unit and property) tests when they are not.
The main use for these expressions should be the "clean" functions.
If you change the DefaultTestSentence, remember to change the random-range for DefaultSentencsCount.
*)
[<Literal>]
let DefaultTestSentence = "This is a sentence. And, so is this. This shouldn't be here! How about this? No!"
let private testSentCount = CountSentences DefaultTestSentence
let DefaultSentenceCount () = Random().Next(1, testSentCount)

180
TestCentre/PropertyTests.fs

@ -6,9 +6,14 @@
open WetPancake
open TestingConstants
open System.Diagnostics
open System
open Helpers
open InputGeneration
(* Note: Do the null tests need to remain?
===============================================================================================================
These tests do not test anything beyond the unit tests.
Considering deleting the null tests...
===============================================================================================================
module ``Null Tests`` =
[<Property>]
@ -83,109 +88,182 @@
|> Async.RunSynchronously
let results = Assert.NotNull (test())
Check.Quick results
*)
module ``Contents Test`` =
[<Property>]
let ``RequestRandomText returns a string which contains a full stop`` () =
let ``CleanResult returns a string which ends with the correct end-token`` () =
let test () =
Pancake.RequestRandomTextAsync ()
Pancake.CleanResultAsync (DefaultSentenceCount()) DefaultTestSentence
|> Async.RunSynchronously
let results = Assert.Contains(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestText returns a string which contains a full stop`` () =
let ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (DefaultSentenceCount())
let test () =
Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
Pancake.CleanResultAsync desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously
let results = Assert.Contains(".", test())
Check.Quick results
|> CountSentences
let results () = Assert.Equal(desiredSentencesCount , test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which contains a full stop when using console-waterworks-announcement`` () =
let ``RequestAllTemplateFiles does not return an empty list`` () =
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
Pancake.RequestAllTemplateFilesAsync ()
|> Async.RunSynchronously
let results = Assert.Contains(".", test())
Check.Quick results
let results () = Assert.NotEmpty (test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which contains a full stop when using desktop-clock-info`` () =
let ``RequestCleanText returns a string which ends with the correct end-token`` () =
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) 4
|> Async.RunSynchronously
let results = Assert.Contains(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which contains a full stop when using test-post`` () =
let ``RequestCleanText returns intended number of sentences`` () =
let desiredSentencesCount = (ValidSentencesInput())
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) desiredSentencesCount
|> Async.RunSynchronously
let results = Assert.Contains(".", test())
Check.Quick results
|> CountSentences
let results () = Assert.Equal(desiredSentencesCount, test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which contains a full stop when using word-generator`` () =
let ``RequestCleanTextFromFile returns a string which ends with the correct end-token when using console-waterworks-announcement`` () =
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
let results = Assert.Contains(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestCleanTextFromFile returns a string which ends with the correct end-token when using desktop-clock-info`` () =
let test () =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestCleanTextFromFile returns a string which ends with the correct end-token when using test-post`` () =
let test () =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestCleanTextFromFile returns a string which ends with the correct end-token when using word-generator`` () =
let test () =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestCleanTextFromFile returns intended number of strings when using console-waterworks-announcement`` () =
let desiredSentencesCount = (ValidSentencesInput())
let test () =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount ConsoleWaterworks
|> Async.RunSynchronously
|> CountSentences
let results () = Assert.Equal(desiredSentencesCount, test())
Check.Quick (results())
[<Property>]
let ``RequestCleanTextFromFile returns intended number of strings when using desktop-clock-info`` () =
let desiredSentencesCount = (ValidSentencesInput())
let test () =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount DesktopClock
|> Async.RunSynchronously
|> CountSentences
let results () = Assert.Equal(desiredSentencesCount, test())
Check.Quick (results())
[<Property>]
let ``RequestRandomText returns a string which ends with a full stop`` () =
let ``RequestCleanTextFromFile returns intended number of strings when using test-post`` () =
let desiredSentencesCount = (ValidSentencesInput())
let test () =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount TestPost
|> Async.RunSynchronously
|> CountSentences
let results () = Assert.Equal(desiredSentencesCount, test())
Check.Quick (results())
[<Property>]
let ``RequestCleanTextFromFile returns intended number of strings when using word-generator`` () =
let desiredSentencesCount = (ValidSentencesInput())
let test () =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount WordGenerator
|> Async.RunSynchronously
|> CountSentences
let results () = Assert.Equal(desiredSentencesCount, test())
Check.Quick (results())
[<Property>]
let ``RequestRandomText returns a string which ends with the correct end-token`` () =
let test () =
Pancake.RequestRandomTextAsync ()
|> Async.RunSynchronously
let results = Assert.EndsWith(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestTest returns a string which ends with a full stop`` () =
let ``RequestText returns a string which ends with the correct end-token`` () =
let test () =
Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
|> Async.RunSynchronously
let results = Assert.EndsWith(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which ends with a full stop when using console-waterwork-announcement`` () =
let ``RequestTextFromFile returns a string which ends with with the correct end-token when using console-waterwork-announcement`` () =
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
let results = Assert.EndsWith(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which ends with a full stop when using desktop-clock-info`` () =
let ``RequestTextFromFile returns a string which ends with with the correct end-token when using desktop-clock-info`` () =
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
let results = Assert.EndsWith(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which ends with a full stop when using test-post`` () =
let ``RequestTextFromFile returns a string which ends with with the correct end-token when using test-post`` () =
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
let results = Assert.EndsWith(".", test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())
[<Property>]
let ``RequestTextFromFile returns a string which ends with a full stop when using word-generator`` () =
let ``RequestTextFromFile returns a string which ends withwith the correct end-token when using word-generator`` () =
let test () =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
let results = Assert.EndsWith(".", test())
Check.Quick results
[<Property>]
let ``RequestAllTemplateFiles does not return an empty list`` () =
let test () =
Pancake.RequestAllTemplateFilesAsync ()
|> Async.RunSynchronously
let results = Assert.NotEmpty (test())
Check.Quick results
|> EndsAsIntended
let results () = Assert.True(test())
Check.Quick (results())

1
TestCentre/TestCentre.fsproj

@ -56,6 +56,7 @@
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Helpers.fs" />
<Compile Include="TestingConstants.fs" />
<Compile Include="InputGeneration.fs" />
<Compile Include="UnitTests.fs" />

2
TestCentre/TextFiles/desktop-clock-info.txt

@ -14,4 +14,4 @@ It sits there and does what I need it to do.
Anything else seems like overkill and I do not find myself wanting it to do something extra.
Therefore, if you want something adding to it, I recommend you fork it.
Desktop Clock is available on GitHub. Feel free to check it out, download it or fork it.
Desktop Clock is available on GitHub. Feel free to check it out, download it or fork it.

197
TestCentre/UnitTests.fs

@ -3,8 +3,10 @@
open Xunit
open WetPancake
open TestingConstants
open System
open System.IO
open InputGeneration
open Helpers
module ``File Access Tests`` =
@ -34,6 +36,46 @@
module ``Null Tests`` =
[<Fact>]
let ``CleanResult does not return a null`` () =
let text = "This is a sentence. And, so is this. This shouldn't be here! How about this? No!"
let result = Pancake.CleanResultAsync (Random().Next(1, 6)) text
Assert.NotNull result
[<Fact>]
let ``RequestAllTemplateFiles does not generate a null`` () =
let result = Pancake.RequestAllTemplateFilesAsync ()
Assert.NotNull result
[<Fact>]
let ``RequestCleanText does not return a null`` () =
let result = Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using console-waterworks-announcement`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using desktop-clock-info`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using test-post`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
Assert.NotNull result
[<Fact>]
let ``RequestCleanTextFromFile does not return a null when using word-generator`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
Assert.NotNull result
[<Fact>]
let ``RequestRandomText does not return a null`` () =
let result = Pancake.RequestRandomTextAsync ()
@ -46,118 +88,183 @@
[<Fact>]
let ``RequestTextFromFile does not return a null when using desktop-clock-info`` () =
let result = Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using console-waterworks-announcement`` () =
let result = Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using word-generator`` () =
let result = Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
Assert.NotNull result
[<Fact>]
let ``RequestTestFromFile does not generate a null when using test-post`` () =
let result = Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
Assert.NotNull result
module ``Contents Tests`` =
[<Fact>]
let ``RequestAllTemplateFiles does not generate a null`` () =
let result = Pancake.RequestAllTemplateFilesAsync ()
Assert.NotNull result
let ``CleanResult returns a string which ends with the correct end-token`` () =
let result =
Pancake.CleanResultAsync (DefaultSentenceCount()) DefaultTestSentence
|> Async.RunSynchronously
|> EndsAsIntended
Assert.True(result)
module ``Contents Tests`` =
[<Fact>]
let ``CleanResult returns intended number of sentences`` () =
let desiredSentencesCount = (DefaultSentenceCount())
let result =
Pancake.CleanResultAsync desiredSentencesCount DefaultTestSentence
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestRandomText returns a string which contains a full stop`` () =
let ``RequestAllTemplateFiles does not return an empty list`` () =
let result =
Pancake.RequestRandomTextAsync ()
Pancake.RequestAllTemplateFilesAsync ()
|> Async.RunSynchronously
Assert.Contains(".", result)
Assert.NotEmpty result
[<Fact>]
let ``RequestText returns a string which contains a full stop`` () =
let ``RequestCleanText returns a string which ends with the correct end-token`` () =
let result =
Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
|> Async.RunSynchronously
Assert.Contains(".", result)
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using console-waterworks-announcement`` () =
let ``RequestCleanText returns intended number of sentences`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
Pancake.RequestCleanTextAsync (ValidGibberishLevelInput()) desiredSentencesCount
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using console-waterworks-announcement`` () =
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
Assert.Contains(".", result)
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using desktop-clock-info`` () =
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using desktop-clock-info`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
Assert.Contains(".", result)
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using test-post`` () =
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using test-post`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
Assert.Contains(".", result)
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestTextFromFile returns a string which contains a full stop when using word-generator`` () =
let ``RequestCleanTextFromFile returns a string which end with the correct end-token when using word-generator`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
Assert.Contains(".", result)
|> EndsAsIntended
Assert.True result
[<Fact>]
let ``RequestRandomText returns a string which ends with a full stop`` () =
let ``RequestCleanTextFromFile returns intended number of sentences when using console-waterworks-announcement`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount ConsoleWaterworks
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestCleanTextFromFile returns intended number of sentences when using desktop-clock-info`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount DesktopClock
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestCleanTextFromFile returns intended number of sentences when using test-post`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount TestPost
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestCleanTextFromFile returns intended number of sentences when using word-generator`` () =
let desiredSentencesCount = (ValidSentencesInput())
let result =
Pancake.RequestCleanTextFromFileAsync (ValidGibberishLevelInput()) desiredSentencesCount WordGenerator
|> Async.RunSynchronously
|> CountSentences
Assert.Equal(desiredSentencesCount, result)
[<Fact>]
let ``RequestRandomText returns a string which ends with the correct end-token`` () =
let result =
Pancake.RequestRandomTextAsync ()
|> Async.RunSynchronously
Assert.EndsWith(".", result)
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestText returns a string which ends with a full stop`` () =
let ``RequestText returns a string which ends with the correct end-token`` () =
let result =
Pancake.RequestTextAsync (ValidGibberishLevelInput()) (ValidSentencesInput())
|> Async.RunSynchronously
Assert.EndsWith(".", result)
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a string which ends with a full stop when using console-waterworks-announcement`` () =
let ``RequestTextFromFile returns a string which ends with the correct end-token when using console-waterworks-announcement`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) ConsoleWaterworks
|> Async.RunSynchronously
Assert.EndsWith(".", result)
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with a full stop when using desktop-clock-info`` () =
let ``RequestTextFromFile returns a sting which ends with the correct end-token when using desktop-clock-info`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) DesktopClock
|> Async.RunSynchronously
Assert.EndsWith(".", result)
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with a full stop when using test-post`` () =
let ``RequestTextFromFile returns a sting which ends with the correct end-token when using test-post`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) TestPost
|> Async.RunSynchronously
Assert.EndsWith(".", result)
|> EndsAsIntended
Assert.True(result)
[<Fact>]
let ``RequestTextFromFile returns a sting which ends with a full stop when using word-generator`` () =
let ``RequestTextFromFile returns a sting which ends with the correct end-token when using word-generator`` () =
let result =
Pancake.RequestTextFromFileAsync (ValidGibberishLevelInput()) (ValidSentencesInput()) WordGenerator
|> Async.RunSynchronously
Assert.EndsWith(".", result)
[<Fact>]
let ``RequestAllTemplateFiles does not return an empty list`` () =
let result =
Pancake.RequestAllTemplateFilesAsync ()
|> Async.RunSynchronously
Assert.NotEmpty result
|> EndsAsIntended
Assert.True(result)

1
WetPancake/AssemblyInfo.fs

@ -1,7 +1,6 @@
namespace WetPancake.AssemblyInfo
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
// General Information about an assembly is controlled through the following

4
WetPancake/DataCleaning.fs

@ -4,4 +4,6 @@
let ReplaceArtifact pattern text = Regex.Replace(text, pattern, " ")
let SplitText pattern text = Regex.Split(text, pattern)
let SplitText pattern text = Regex.Split(text, pattern)
let TrimEnd charArray (text: string) = text.TrimEnd charArray

8
WetPancake/DataProcessing.fs

@ -12,21 +12,21 @@
let GibberishLevelIsValid gibberishLevel =
match gibberishLevel with
| gibberishLevel when gibberishLevel < 2 || gibberishLevel > 20 ->
raise (new ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel"))
invalidArg "gibberishLevel" "Invalid argument. Must be between 2 and 20 (inclusive)."
| _ -> ignore
let SentencesIsValid sentences =
match sentences with
| sentences when sentences < 1 ->
raise (ArgumentException("Invalid argument. Must be greater than 0.", "sentences"))
invalidArg "sentences" "Invalid argument. Must be greater than 0."
| _ -> ignore
let FilePathIsValid filePath =
match filePath with
| filePath when Path.GetExtension filePath <> ".txt" ->
raise (ArgumentException("Invalid argument. File must be a .txt file.","filePath"))
invalidArg "filePath" "Invalid argument. File must be a .txt file."
| filePath when not (File.Exists filePath) ->
raise (ArgumentException("Invalid argument. File must include a valid file path.","filePath"))
raise (FileNotFoundException("Unable to find the file at the location specified."))
| _ -> ignore
let SortIntoGroups groupSize text =

66
WetPancake/DataServices.fs

@ -15,7 +15,7 @@
let rec GenerateMarkovChain (map: Map<string, string List>) (state:string) chain =
if map.ContainsKey state then
let nextChoice = map.[state] |> PickRandomItem
if MatchText @"$\." nextChoice then nextChoice :: chain
if MatchText @"(\.|\?|\!)$" nextChoice then nextChoice :: chain
else
let currentWords =
state
@ -24,20 +24,45 @@
|> ConcatToString
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain)
else
let fallbackChoice = (PickRandomItem map).Key
String.Format("{0}.", fallbackChoice) :: chain
let fallbackChoice = (PickRandomItem map).Key
(String.Format("{0}.", fallbackChoice)) :: chain
let GenerateMarkovSentence map start =
GenerateMarkovChain map start [start]
|> List.rev
|> ConcatToString
(* Thread.Sleep is needed for a new random number to generate.
Without it, the same sentence tends to repeat itself.
When debugging (I.E. the observer effect),
enough time passes for a new random number to generate --
(* Note: Thread.Sleep (Random Number Generation)
==================================================================================================================
Thread.Sleep is needed to yield better random numbers. Without it, the same random number tends to be used.
When debugging (I.E. the observer effect?), enough time passes for a new random number to generate --
meaning a new seed or "start word" for each sentence.
This isn't ideal but needed so please be careful when attempting to remove this line. *)
This isn't ideal but be careful when attempting to remove this line.
Note: Extra Sentence Generation
==================================================================================================================
You might notice, from time to time, the for-loop produces one more sentence than specified.
This happens when the starting point (startWords) contains a 'full sentence' within it.
Example:
--------
(Refer to code for in-depth breakdown of data types/structures.)
1. 'Separate Starts Words' from 'map'.
[
(1)["This is a sentence." ["word 1"; "word 2"; Etc.]]
(2)["This is another" ["word 1"; "word 2"; Etc.]]
(3)["No full sentence" ["word 1"; "word 2"; Etc.]]
]
2. In this case, if (1) is selected, we already have a full sentence before we have entered the for-loop.
3. Because the code has not entered the for-loop yet, the 'sentence count' is still at 0.
4. When the code enters the loop, the 'start words' are used to generate the 'FIRST' sentence of the loop.
5. The 'start words' are then appended on to the sentence to complete the generated sentence.
6. Now we have two sentences but the loop has not completed it cycle, so it creates, what is now, an extra one.
As this NuGet package is about generating random text, this should not be a problem for the most part.
With that said, when this happens, it is an incorrect result -- from the end-users point-of-view.
So, to get a more accurate result, pass the result of this function through to the RemoveArtifactSentences function.
*)
let GenerateMarkovText noOfSentences map =
let startWords = fst(SeperateStartWords map)
let result =
@ -46,4 +71,27 @@
Thread.Sleep(100)
yield GenerateMarkovSentence map (PickRandomItem startWords).Key
}
result |> ConcatToString
result |> ConcatToString
(* Note: RemoveArtifactSentences Breakdown
==================================================================================================================
This function receives a string and an int as its parameters.
The text being the string and the int being the total of intended sentences.
When using the GenerateMarkovText function, it can sometimes produce an unexpected extra sentence.
(See the GenerateMarkovText-comment above for further details.)
For the most part, the outcome of this "mishap" is fine (this is a random word generator, not a space rocket).
With that said, run the generated text through this function if you want "clean" results.
It will mean it will take longer to process the results but it does reduce the chance of incorrect output.
("Incorrect" from the end-users point-of-view.)
The ReplaceArtifact function counteracts the effects of the text splitting.
SplitText splits the text and adds a space at the split.
This leads to the text having double-spaces when concatenated back together.
*)
let RemoveArtefactSentences noOfSentences text =
text
|> SplitText @"(?<=[\.\!\?]\s)"
|> Array.take noOfSentences
|> ConcatToString
|> ReplaceArtifact " "
|> TrimEnd [|' '|]

205
WetPancake/ProductServices.fs

@ -1,7 +1,7 @@
namespace WetPancake
open System.Linq.Expressions
/// This module contains all the public functions in the Wet Pancake NuGet package.
/// It enables you to generate random text.
module Pancake =
open SystemServices
@ -10,7 +10,42 @@ module Pancake =
open DataStructuring
open DataServices
open System
open System.IO
/// <summary>
/// Checks to see if the string matches the desired sentence count and removes any over that limit.
/// This function is ascynchronous.
/// </summary>
/// <param name="noOfSentences">
/// The number of sentences the cleaned string should have.
/// </param>
/// <param name="text">
/// The string to clean.
/// </param>
/// <remarks>
/// This function's aim is to trim or remove excess sentences.
/// If the string has less sentences than the number requested, it will not change.
/// </remarks>
let CleanResultAsync noOfSentences text =
async {
try
let cleanText =
text
|> RemoveArtefactSentences noOfSentences
return cleanText
with
| :? InvalidOperationException -> return text
}
/// <summary>
/// An asynchronous function which generates random text.
/// </summary>
/// <returns>
/// A string of randomly generated text.
/// </returns>
/// <remarks>
/// This function will produce a maximum of 10 sentences with each function call.
/// </remarks>
let RequestRandomTextAsync() =
async {
let data =
@ -21,6 +56,31 @@ module Pancake =
return GenerateMarkovText (PickRandomNumber 2 10) data
}
/// <summary>
/// An asynchronous function which generates random text.
/// It uses the built-in template (.txt) files as a reference and the parameters specified by the caller.
/// </summary>
/// <param name="gibberishLevel">
/// Specifies how coherent the generated text is.
/// Min. value = 2. Max. value = 20.
/// The lower the value the more gibberish it will produce.
/// </param>
/// <param name="sentences">
/// Specifies the number of sentences to generate.
/// </param>
/// <returns>
/// A string of randomly generated text.
/// </returns>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "gibberishLevel" is not between 2 and 20.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "sentences" count is less than 1.
/// </exception>
/// <remarks>
/// The higher the “gibberishLevel” and the “sentences” count is the longer it will take to complete the task.
/// Try to make the most of the asynchronous nature of the function as possible.
///</remarks>
let RequestTextAsync (gibberishLevel: int) (sentences: int) =
async {
try
@ -33,10 +93,48 @@ module Pancake =
|> GenerateMap
return GenerateMarkovText sentences data
with
| :? ArgumentException as ex ->
return ex.Message
| :? ArgumentException as ex -> return ex.Message
}
/// <summary>
/// An asynchronous function which generates text.
/// It generates the text by using the (.txt) file passed in by the caller (as the reference)
/// It, also, uses the parameters specified by the caller.
/// </summary>
/// <param name="gibberishLevel">
/// Specifies how coherent the generated text is.
/// Min. value = 2. Max. value = 20.
/// The lower the value the more gibberish it will produce.
/// </param>
/// <param name="sentences">
/// Specifies the number of sentences to generate.
/// </param>
/// <param name="filePath">
/// The path of the (.txt) file the function will use as the reference text.
/// </param>
/// <returns>
/// A string of randomly generated text.
/// </returns>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "gibberishLevel" is not between 2 and 20.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "sentences" count is less than 1.
/// </exception>
/// <exception cref="System.FileNotFoundException">
/// Thrown when the (.txt) file cannot be found.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the specified file is not a plain-text (.txt) file.
/// </exception>
/// <remarks>
/// The higher the “gibberishLevel” and the “sentences” count is the longer it will take to complete the task.
/// This, also, applies to the (.txt) file passed into the function.
/// The bigger it is, the longer it will take to read.
/// Try to make the most of the asynchronous nature of the function as possible.
/// Also, the function does not know what is in the (.txt) file until it reads it.
/// Defensive coding should be applied here.
/// </remarks>
let RequestTextFromFileAsync (gibberishLevel: int) (sentences: int) (filePath: string) =
async {
try
@ -50,14 +148,109 @@ module Pancake =
|> GenerateMap
return GenerateMarkovText sentences data
with
| :? ArgumentException as ex ->
return ex.Message
| :? ArgumentException as ex -> return ex.Message
| :? FileNotFoundException as ex -> return ex.Message
}
/// <summary>
/// Finds every available template (.txt) file in Wet Pancake and forms a list of their file paths.
/// </summary>
/// <returns>
/// A list of every template (.txt) file path.
/// </returns>
/// <remarks>
/// You can use the information provided by this function alongside the "RequestTextFromFileAsync” function.
/// This allows you to generate text using one of the built-in template (.txt) files.
/// </remarks>
let RequestAllTemplateFilesAsync () =
async {
let files =
ListSampleFiles
|> Array.toList
return files
}
/// <summary>
/// An asynchronous function which generates random text.
/// It uses the built-in template (.txt) files as a reference and the parameters specified by the user.
/// It, also, goes through a "cleaning" process which removes any excess sentences.
/// </summary>
/// <param name="gibberishLevel">
/// Specifies how coherent the generated text is.
/// Min. value = 2. Max. value = 20.
/// The lower the value the more gibberish it will produce.</param>
/// <param name="sentences">
/// Specifies the number of sentences to generate.
/// </param>
/// <returns>
/// A string of randomly generated text.
/// </returns>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "gibberishLevel" is not between 2 and 20.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "sentences" count is less than 1.
/// </exception>
/// <remarks>
/// This function produces more accurate results than the equivalent RequestTextAsync.
/// Although, it does take loner to complete.
/// If you can tolerate the odd extra sentences and prefer speed, use RequestextAsync.
/// If not, use this.
/// </remarks>
let RequestCleanTextAsync (gibberishLevel: int) (sentences: int) =
async {
let! text = RequestTextAsync gibberishLevel sentences
let! cleanText = CleanResultAsync sentences text
return cleanText
}
/// <summary>
/// An asynchronous function which generates text.
/// It generates the text by using the (.txt) file passed in by the caller (as the reference)
/// It, also, uses the parameters specified by the caller.
/// On top of that, it goes through a "cleaning" process which removes any excess sentences.
/// </summary>
/// <param name="gibberishLevel">
/// Specifies how coherent the generated text is.
/// Min. value = 2. Max. value = 20.
/// The lower the value the more gibberish it will produce.
/// </param>
/// <param name="sentences">
/// Specifies the number of sentences to generate.
/// </param>
/// <param name="filePath">
/// The path of the (.txt) file the function will use as the reference text.
/// </param>
/// <returns>
/// A string of randomly generated text.
/// </returns>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "gibberishLevel" is not between 2 and 20.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the "sentences" count is less than 1.
/// </exception>
/// <exception cref="System.FileNotFoundException">
/// Thrown when the (.txt) file cannot be found.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when the specified file is not a plain-text (.txt) file.
/// </exception>
/// <remarks>
/// The higher the “gibberishLevel” and the “sentences” count is the longer it will take to complete the task.
/// This, also, applies to the (.txt) file passed into the function.
/// The bigger it is, the longer it will take to read.
/// Try to make the most of the asynchronous nature of the function as possible.
/// Also, the function does not know what is in the (.txt) file until it reads it.
/// Defensive coding should be applied here.
/// This function produces more accurate results than it RequestTextFromFileAsync equivalent.
/// Although, it does take loner to complete.
/// If you can tolerate the odd extra sentences and prefer speed, use RequestextAsync.
/// If not, use this.
/// </remarks>
let RequestCleanTextFromFileAsync (gibberishLevel: int) (sentences: int) (filePath: string) =
async {
let! text = RequestTextFromFileAsync gibberishLevel sentences filePath
let! cleanText = CleanResultAsync sentences text
return cleanText
}

68
WetPancake/Script.fsx

@ -17,6 +17,7 @@ open DataStructuring
open DataServices
open WetPancake
open System
open System.IO
// Template Files
[<Literal>]
@ -107,10 +108,12 @@ let dp_filePathIsValidException =
let invalidFileType = "C:/notvalid/test.doc"
// Template file paths by the open & load declarations
try
FilePathIsValid TestPost // enter filepath here
FilePathIsValid ConsoleWaterworks // enter filepath here
|> ignore
"No exception thrown"
with :? ArgumentException as ex -> ex.Message
with
| :? ArgumentException as ex -> ex.Message
| :? FileNotFoundException as ex -> ex.Message
// Data Structuring
let ds_map = Map.empty
@ -151,16 +154,34 @@ let dss_text =
let dss_startwords = SeperateStartWords dss_text
let dss_sentences = GenerateMarkovText 2 dss_text
printfn "Text: %A" dss_sentences
let dss_sentences2 = "This is a sentence. And, so is this. This shouldn't be here! How about this? No!"
let dss_clean =
dss_sentences2
|> RemoveArtefactSentences 6 // Change the no. of sentences to test.
printfn "CLEANED TEXT: %s" dss_clean
// Product Services (Pancake)
let ps_files = Pancake.RequestAllTemplateFilesAsync ()
ps_files |> Async.RunSynchronously
(* Basic Text Generation
======================================================================================================================
These functions produce text which does not go through the "cleaning" process.
This means the results here are prone to producing an extra sentence on the (very) odd occassion.
As a general rule, it tends to happen when the gibberish-level is set to one of the higher values.
(High gibberish-level values generates "more" coherent sentences).
It is caused when the start-word is itself a sentence, and the text generation loop has not started.
For more information, see the GenerateMarkovText function in DataServices.fs.
The reason you would use these functions ove the "Clean Text Generation" function below is these are faster to finish.
If you can tolerate the occasional extra bit of text and the functions below are too slow, use these functions.
*)
let ps_result1 = Pancake.RequestRandomTextAsync()
let ps_result2 = Pancake.RequestTextAsync 5 10
let ps_result3 = Pancake.RequestTextFromFileAsync 3 10 DesktopClock
let ps_result4 = Pancake.RequestTextFromFileAsync 3 10 ConsoleWaterworks
let ps_result3 = Pancake.RequestTextFromFileAsync 3 10 ConsoleWaterworks
let ps_result4 = Pancake.RequestTextFromFileAsync 3 10 DesktopClock
let ps_result5 = Pancake.RequestTextFromFileAsync 3 10 WordGenerator
let ps_result6 = Pancake.RequestTextFromFileAsync 3 10 TestPost
let ps_files = Pancake.RequestAllTemplateFilesAsync ()
ps_result1 |> Async.RunSynchronously
ps_result2 |> Async.RunSynchronously
@ -168,4 +189,39 @@ ps_result3 |> Async.RunSynchronously
ps_result4 |> Async.RunSynchronously
ps_result5 |> Async.RunSynchronously
ps_result6 |> Async.RunSynchronously
ps_files |> Async.RunSynchronously
(* This function is made public so users can clean the text manually.
For the most part, this function should not be called.*)
let ps_cleanText =
// ps_result6 // Change this value for one of the above (ps_result1-6)
//|> Async.RunSynchronously
"This is a sentence. And, so is this. This shouldn't be here! How about this? No!"
|> Pancake.CleanResultAsync 6 // This value must not go above the one declared above (ps_resultX)
|> Async.RunSynchronously
printfn "CLEANED TEXT RESULT: %s" ps_cleanText
(* Clean Text Generation
======================================================================================================================
These functions produce text which have gone through the "cleaning" process.
This means the results will go through an extra step and remove any erroneous sentences.
This is unlike the "Basic Text Generation" functions above.
The trade-off here is these "cleaning" functions can be slower to finish executing.
If you need your results to match the number of sentences you requested exactly, you should use these functions.
This, also, applies if you can tolerate the extra processing time.
*)
let ps_cleanResult1 = Pancake.RequestCleanTextAsync 5 10
let ps_cleanResult2 = Pancake.RequestCleanTextFromFileAsync 3 10 ConsoleWaterworks
let ps_cleanResult3 = Pancake.RequestCleanTextFromFileAsync 3 10 DesktopClock
let ps_cleanResult4 = Pancake.RequestCleanTextFromFileAsync 3 10 WordGenerator
let ps_cleanResult5 = Pancake.RequestCleanTextFromFileAsync 3 10 TestPost
ps_cleanResult1 |> Async.RunSynchronously
ps_cleanResult2 |> Async.RunSynchronously
ps_cleanResult3 |> Async.RunSynchronously
ps_cleanResult4 |> Async.RunSynchronously
ps_cleanResult5 |> Async.RunSynchronously
let ps_cleanText2 =
ps_cleanResult1 // Change the number for printing result below (E.G. ps_cleanResult1, ps_cleanResult4...)
|> Async.RunSynchronously
printfn "CLEAN TEXT RESULT: %s" ps_cleanText2

130
WetPancakeCLI/ConsoleCommands.cs

@ -44,7 +44,11 @@ namespace WetPancakeCLI
[Usage("> GenerateRandomText")]
public static string GenerateRandomText()
{
try { return FSharpAsync.StartAsTask(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result; }
try
{
return FSharpAsync.StartAsTask
(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
@ -53,16 +57,26 @@ namespace WetPancakeCLI
}
[ListCommand]
[Description("Generates text using the gibberish level and number of sentences specified by the user. Gibberish level must be between 2 and 20.")]
[Parameters("gibberish level: int, sentences: int")]
[Description("Generates text using the gibberish-level and number of sentences specified by the user.\n" +
"This command does not run the result through the extra \"cleaning\" process like GenerateCleanText.\n" +
"This means this command is faster but it might produce an extra sentence on the odd occasion.\n" +
"Use this if you prefer speed over accuracy.\n" +
"Gibberish-level must be between 2 and 20."
)]
[Parameters("gibberish-level: int, sentences: int")]
[Usage("> GenerateText 5 10")]
public static string GenerateText(int gibberishLevel, int sentences)
{
try
{
if (gibberishLevel < 2 || gibberishLevel > 20) throw new ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel");
if (sentences < 1) throw new ArgumentException("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
if (gibberishLevel < 2 || gibberishLevel > 20)
throw new ArgumentException
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-level");
if (sentences < 1)
throw new ArgumentException
("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask
(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
@ -72,17 +86,28 @@ namespace WetPancakeCLI
}
[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 between 2 and 20.")]
[Parameters("gibberish level: int, sentences: int, file path: string")]
[Description("Loads the specified .txt file and generates text based on it using the gibberish-level and number of sentences specified by the user.\n" +
"This command does not run the result through the extra \"cleaning\" process like GenerateCleanTextFromFile.\n" +
"This means this command is faster but it might produce an extra sentence on the odd occasion.\n" +
"Use this if you prefer speed over accuracy.\n" +
"Gibberish-level must be between 2 and 20.")]
[Parameters("gibberish-level: int, sentences: int, file path: string")]
[Usage("> GenerateTextFromFile 3 6 C:/yourfile.txt")]
public static string GenerateTextFromFile(int gibberishLevel, int sentences, string filePath)
{
try
{
if (gibberishLevel < 2 || gibberishLevel > 20) throw new ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel");
if (sentences < 1) throw new ArgumentException("Invalid argument. Must be greater than 0.", "sentences");
if (Path.GetExtension(filePath) != ".txt") throw new FileLoadException("The file entered is not a plain text (.txt) file.", filePath);
return FSharpAsync.StartAsTask(RequestTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result;
if (gibberishLevel < 2 || gibberishLevel > 20)
throw new ArgumentException
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-level");
if (sentences < 1)
throw new ArgumentException
("Invalid argument. Must be greater than 0.", "sentences");
if (Path.GetExtension(filePath) != ".txt")
throw new FileLoadException
("The file entered is not a plain text (.txt) file.", filePath);
return FSharpAsync.StartAsTask
(RequestTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
@ -113,5 +138,86 @@ namespace WetPancakeCLI
throw;
}
}
[ListCommand]
[Description("Generates text using the gibberish-level and number of sentences specified by the user.\n" +
"The result goes through an extra \"cleaning\" process to remove any artefact sentences.\n" +
"Use this if you cannot tolerate the odd extra sentence.\n" +
"With that said, it does mean it is slower than its GenerateText counterpart.\n" +
"Gibberish-level must be between 2 and 20.")]
[Parameters("gibberish-level: int, sentences: int")]
[Usage("> GenerateCleanText 5 10")]
public static string GenerateCleanText(int gibberishLevel, int sentences)
{
try
{
if (gibberishLevel < 2 || gibberishLevel > 20)
throw new ArgumentException
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-Level");
if (sentences < 1)
throw new ArgumentException
("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask
(RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
throw;
}
}
[ListCommand]
[Description("Loads the specified .txt file and generates text based on it, using the gibberish-level and number of specified by the user.\n" +
"The result goes through an extra \"cleaning\" process to remove any artefact sentences.\n" +
"Use this if you cannot tolerate the odd extra sentence.\n" +
"With that said, it does mean it is slower than its GenerateTextFromFile counterpart.\n" +
"Gibberish-level must be between 2 and 20.")]
[Parameters("gibberish-level: int, sentences: int, file path: string")]
[Usage("> GenerateCleanTextFromFile 3 6 C:/yourfile.txt")]
public static string GenerateCleanTextFromFile(int gibberishLevel, int sentences, string filePath)
{
try
{
if (gibberishLevel < 2 || gibberishLevel > 20)
throw new ArgumentException
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-Level");
if (sentences < 1)
throw new ArgumentException
("Invalid argument. Must be greater than 0.", "sentences");
if (Path.GetExtension(filePath) != ".txt")
throw new FileLoadException
("The file entered is not a plain text (.txt) file.", filePath);
return FSharpAsync.StartAsTask
(RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
throw;
}
}
[ListCommand]
[Description("Checks to see if the string matches the desired sentence count and removes any over that limit.\n" +
"If the string has less sentences than the number requested, it will not change.\n" +
"Sentences must be greater than 0 and text must contain at least 1 \".\" \"?\" \"!\"")]
[Parameters("sentences: int, text: string")]
[Usage("> CleanText 1 \"This is a test sentence. And, this one needs to be removed.\"")]
public static string CleanText(int sentences, string text)
{
try
{
if (sentences < 1)
throw new ArgumentException ("Invalid argument. Must be greater than 0", "sentences");
return FSharpAsync.StartAsTask
(CleanResultAsync(sentences, text), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
throw;
}
}
}
}

18
WetPancakeCLI/Properties/AssemblyInfo.cs

@ -1,15 +1,21 @@
using System.Reflection;
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WetPancakeCLI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Wet Pancake")]
[assembly: AssemblyDescription("Wet Pancake [ALPHA] is a console program for generating text.\n" +
"Visit https://github.com/CraigOates/Wet-Pancake to submit issues and pull requests.\n" +
"The NuGet URL is T.B.A.\n" +
"Type Help into the prompt for a list of available commands.\n" +
"You can generate text using the built-in templates or use you own.\n" +
"Parameter Ranges: [Gibberish Level: 2-20] [Sentence Count: >= 1] [File Type: .txt]")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WetPancakeCLI")]
[assembly: AssemblyCompany("Craig Oates")]
[assembly: AssemblyProduct("Wet Pancake")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -34,3 +40,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("en-GB")]

51
WetPancakeCLI/WetPancakeCLI.csproj

@ -11,6 +11,22 @@
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>C:\Users\craig\Desktop\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -32,7 +48,26 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>wet-pancake.ico</ApplicationIcon>
<ApplicationIcon>logo.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>111115082E0B5588556218B5B2E8FE067A4A3851</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>WetPancakeCLI_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<StartupObject>WetPancakeCLI.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Console.Waterworks, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
@ -67,7 +102,19 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="wet-pancake.ico" />
<Content Include="logo.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

BIN
WetPancakeCLI/logo.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

BIN
WetPancakeCLI/wet-pancake.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB

Loading…
Cancel
Save