Browse Source

Merge pull request #3 from CraigOates/0.3-p1

0.3 p1
master
Craig Oates 6 years ago committed by GitHub
parent
commit
b901355437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      TestCentre/AssemblyInfo.fs
  2. 1
      TestCentre/Script.fsx
  3. 114
      TestCentre/TestCentre.fsproj
  4. 10
      TestCentre/TestingConstants.fs
  5. 21
      TestCentre/TextFiles/console-waterworks-announcement.txt
  6. 14
      TestCentre/TextFiles/desktop-clock-info.txt
  7. 8
      TestCentre/TextFiles/word-generator.txt
  8. 53
      TestCentre/UnitTests.fs
  9. 13
      TestCentre/packages.config
  10. 6
      WetPancake.sln
  11. 2
      WetPancake/DataAccess.fs
  12. 1
      WetPancake/DataCleaning.fs
  13. 9
      WetPancake/DataProcessing.fs
  14. 7
      WetPancake/DataServices.fs
  15. 28
      WetPancake/ProductServices.fs
  16. 17
      WetPancake/Script.fsx
  17. 24
      WetPancake/SystemServices.fs
  18. 8
      WetPancake/TextFiles/word-generator.txt
  19. 3
      WetPancake/WetPancake.fsproj
  20. 2
      WetPancake/packages.config
  21. 36
      WetPancakeCLI/ConsoleCommands.cs
  22. 3
      WetPancakeCLI/WetPancakeCLI.csproj
  23. 1
      WetPancakeCLI/packages.config

41
TestCentre/AssemblyInfo.fs

@ -0,0 +1,41 @@
namespace TestCentre.AssemblyInfo
open System.Reflection
open System.Runtime.CompilerServices
open 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("TestCentre")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("TestCentre")>]
[<assembly: AssemblyCopyright("Copyright © 2018")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyCulture("")>]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[<assembly: Guid("aa30074c-bef2-4f2b-89f4-7069179b3ab7")>]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("1.0.0.0")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]
do
()

1
TestCentre/Script.fsx

@ -0,0 +1 @@
// nothing in here for now.

114
TestCentre/TestCentre.fsproj

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>aa30074c-bef2-4f2b-89f4-7069179b3ab7</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>TestCentre</RootNamespace>
<AssemblyName>TestCentre</AssemblyName>
<UseStandardResourceNames>true</UseStandardResourceNames>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.3.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>TestCentre</Name>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition=" '$(FSharpTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets') ">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition=" '$(FSharpTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets') ">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Content Include="TextFiles\desktop-clock-info.txt" />
<Content Include="TextFiles\console-waterworks-announcement.txt" />
<Content Include="TextFiles\word-generator.txt" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="TestingConstants.fs" />
<Compile Include="UnitTests.fs" />
<None Include="Script.fsx" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>..\packages\FSharp.Core.4.5.0\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple">
<Private>True</Private>
</Reference>
<Reference Include="xunit.abstractions">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert">
<HintPath>..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core">
<HintPath>..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop">
<HintPath>..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WetPancake\WetPancake.fsproj">
<Name>WetPancake</Name>
<Project>{cb878c2d-edba-490b-b6b3-01b57779a28f}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

10
TestCentre/TestingConstants.fs

@ -0,0 +1,10 @@
module TestingConstants
[<Literal>]
let DesktopClock = __SOURCE_DIRECTORY__ + @"\TextFiles\desktop-clock-info.txt"
[<Literal>]
let ConsoleWaterworks = __SOURCE_DIRECTORY__ + @"\TextFiles\console-waterworks-announcement.txt"
[<Literal>]
let WordGenerator = __SOURCE_DIRECTORY__ + @"\TextFiles\word-generator.txt"

21
TestCentre/TextFiles/console-waterworks-announcement.txt

@ -0,0 +1,21 @@
That's right, you've won. Well done and come on down, today is not your lucky day. It's -- in fact -- the best day of your life. How else can you describe the moment you discovered the Console.Waterworks NuGet package? That's right, you can't. So, let's get on with basking in your glory. I can't wait.
First of all, Console.Waterworks is for writing extendable command-based console programs. Gone are the days where you need to parse user input and write error handling code. You now have the ability to write methods which act as commands at run-time. Method parameters are, also, accepted and parsed at run-time. This is brilliant and in need of a demonstration. Are you ready to see something which surpasses the hype and majesty of the sun herself? Well, come on then. It's demo. time.
As you can see in the Gif. above, the method I have written (on the left) maps to a command in the console program at run-time (on the right). There is no parsing of user input or error handling in the code, either. Don't worry, you'll be reading more about that majestic trick-shot in a moment. For now, enjoy the flashing lights. You've earned it.
We both know you're not an idiot. So, when you recognise the brilliance, you know it's one-hundred percent legitimate. This is a fair assessment. And, this next intellectual marvel will elevate your core being to a state of ecstasy. Yes, you're right. I'm about to render you stupid through the sheer splendour of intellectual stimulation. It's going to be so strong, you might consider it a form of infidelity. Let's hope you can keep your wits about you. This is your relationship at risk here, not mine. Come on you little cupcake. Let's demo.
This demo. is the one about the error handling I mentioned earlier. As you can see in the Gif., the method doesn't have any error handling code. But, the console program displays an error message to the user. Yes, you're right. It's brilliant.
This next demo. is where everything changes, though. I hope you've strapped your pants on tight.
In a moment as clear as crystal, what you’re looking at is a self-documenting "help" section. This means you no longer need to write a help guide -- from scratch -- in every console program. You can now add Waterworks custom attributes to the methods you want to declare at run-time. Console.Waterworks will make a note of those attributes and display them like the demo. shows.
Everything above is brilliant and has a place on this Earth and you know this. Like I said before, you're not an idiot. So, the next time you're writing a console program, don't forget to add Console.Waterworks to your solution.
For more information about using Console.Waterworks in your solution, head to the GitHub. Console.Waterworks is available as a .Net and .Net Core NuGet package.
Thank you for your time and I look forward to your words of recommendation about me reach me. And, when I say "reach me", I don't me via you. I mean via other people talking about you and on your behalf.
Thanks again.

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

@ -0,0 +1,14 @@
About Desktop Clock
This is a basic WPF program which displays the data and time so it is readable from a distance. Desktop Clock uses a NuGet package called This allows the program to look like a Windows 10 UWP program. The most notable aspects being the translucent chrome and the highlighting of near-by buttons.
Screenshot 1 Desktop Clock is a WPF program which looks like a UWP program.Publishing Information
If you would like to use, it you will need to build from the source code provided. I did not want to mess around with ClickOnce or any other packaging mechanism.
With it being a WPF program, it can run on Windows 7 and 8 machines.
Future Plans
I do not intend to take this any further. It is a simple program which I have running 247, floating about on the screen. 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.
GitHub
Desktop Clock is  available on GitHub. Feel free to check it out, download it or fork it

8
TestCentre/TextFiles/word-generator.txt

@ -0,0 +1,8 @@
Are you the type of person who hates work? Are you someone who resents the fact you're born into a system not of your choosing? Are your teachers lazy, dismissive and not interested in your education? We're looking at you Mr.Heath... Then you need Word Generator. The app for students with a deadline.
Imagine you're at home and finishing off your English essay for Mr. Dillbank. A teacher who is always drunk and has been struggling to put a sentence together since 2014. He never used to be this way but Maureen had to leave him for Derek, the Head of Music at Barnworth High. He isn't even good looking. He looks like an orange balloon with pigeon droppings for a moustache. Who, in the history of mankind, thought that was a good look? No one! That's who! Screw you Derek! Screw you! You're fooling no one with that hair piece...
...
Sorry... I got a little side-tracked there....
Anyway, where was I...
So, you're finishing your essay and you realise your word count is lower than the expected one. Two-hundred words short, as a matter of fact. This is infuriating because you're supposed to be playing football in twenty minutes. You don't have enough time to add two-hundred words and be ready in time for football. What do you do? You open Word Generator of course. You add the extra words in a few clicks and your already off to football, with time to spare. Your mum only checks the word count these days and Mr. Dillbank hasn't seen straight for years. They think you have done your homework and you get to play football. Everyone is a winner here, apart from you in the long term but that's ok. It's not ok but it feels ok and that's what counts right now.
So, you're sold. You're in and wanting to know more. How does it work? I'm glad you asked. It uses the latest in space-age technology. Word Generator utilises the Markov Chain algorithm. When you boot Word Generator up, feed it a plain text (.txt) file and specify what Markov Value you want to use. Using that information, it spits out text that resembles the original text. This helps hide the deception.
Just in case you're wondering, the Markov Value is a number. For the app it's a number between one and ten. The higher the number the closer the generated text will resemble the original text. For example, a value of one will generate non-sense and ten will spit out like-for-like text. If you're feeling confident, I recommend you turn it up to five and see if teachers like Mr. Dillbank notices.

53
TestCentre/UnitTests.fs

@ -0,0 +1,53 @@
namespace TestCentre
module ``Unit Tests`` =
open Xunit
open WetPancake
open TestingConstants
open System.IO
(*These tests check to see if the .txt files exists in the Test Centre project.
The Wet Pancake library does not expose the file access functions so the .txt
files are mirrored here (in Text Centre)
The mirroring, also, doubles up as sample files to pass into Wet Pancake.*)
[<Fact>]
let ``desktop-clock-info-txt can be found`` () =
let result = File.Exists DesktopClock
Assert.Equal(true, result);
[<Fact>]
let ``console-waterworks-announcements-txt can be found`` () =
let result = File.Exists ConsoleWaterworks
Assert.Equal(true, result);
[<Fact>]
let ``word-generator-txt can be found`` () =
let result = File.Exists WordGenerator
Assert.Equal(true, result);
[<Fact>]
let ``Request Random Text does not generate a null`` () =
let result = Pancake.RequestRandomText
Assert.NotNull result
[<Fact>]
let ``Request Text does not generate a null`` () =
let result = Pancake.RequestText 5 5
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not generate a null for desktop-clock-info-txt`` () =
let result = Pancake.RequestTextFromFile 5 5 DesktopClock
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not generate a null for console-waterworks-announcement-txt`` () =
let result = Pancake.RequestTextFromFile 5 5 ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``Request Text From File does not generate a null for word-generator-txt`` () =
let result = Pancake.RequestTextFromFile 5 5 WordGenerator
Assert.NotNull result

13
TestCentre/packages.config

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Core" version="4.5.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
<package id="xunit" version="2.3.1" targetFramework="net471" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net471" />
<package id="xunit.analyzers" version="0.9.0" targetFramework="net471" />
<package id="xunit.assert" version="2.3.1" targetFramework="net471" />
<package id="xunit.core" version="2.3.1" targetFramework="net471" />
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net471" />
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net471" />
<package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net471" developmentDependency="true" />
</packages>

6
WetPancake.sln

@ -7,6 +7,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "WetPancake", "WetPancake\We
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WetPancakeCLI", "WetPancakeCLI\WetPancakeCLI.csproj", "{87C61362-58D8-4D79-ABF3-F356041F5DEC}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "TestCentre", "TestCentre\TestCentre.fsproj", "{AA30074C-BEF2-4F2B-89F4-7069179B3AB7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +23,10 @@ Global
{87C61362-58D8-4D79-ABF3-F356041F5DEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87C61362-58D8-4D79-ABF3-F356041F5DEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87C61362-58D8-4D79-ABF3-F356041F5DEC}.Release|Any CPU.Build.0 = Release|Any CPU
{AA30074C-BEF2-4F2B-89F4-7069179B3AB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA30074C-BEF2-4F2B-89F4-7069179B3AB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA30074C-BEF2-4F2B-89F4-7069179B3AB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA30074C-BEF2-4F2B-89F4-7069179B3AB7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

2
WetPancake/DataAccess.fs

@ -12,7 +12,7 @@
CreateSampleTextFilesPath
|> FindSampleTextFiles
let SelectRandomSampleFile =
let SelectRandomSampleFile() =
let files = ListSampleFiles
files.[Random().Next(0, files.Length)]

1
WetPancake/DataCleaning.fs

@ -1,6 +1,5 @@
module internal DataCleaning
open System.IO
open System.Text.RegularExpressions
let ReplaceArtifact pattern text = Regex.Replace(text, pattern, " ")

9
WetPancake/DataProcessing.fs

@ -23,4 +23,13 @@
let CombineWords prev next =
[prev; next]
|> List.filter(fun s -> not (String.IsNullOrWhiteSpace s))
|> ConcatToString
let ApplyStandardSetup text =
text
|> ReplaceArtifact "\""
|> ReplaceArtifact "\n\nIn"
|> ReplaceArtifact "\r"
|> ReplaceArtifact "\n"
|> SplitText @"\s+"
|> ConcatToString

7
WetPancake/DataServices.fs

@ -1,16 +1,13 @@
module internal DataServices
open SystemServices
open System
open DataStructuring
open DataProcessing
open DataCleaning
open System.Threading
let PickRandomWord words = PickRandomItem (Random().Next) words
let rec GenerateMarkovChain (map: Map<string, string List>) (state:string) chain =
let nextChoice = map.[state] |> PickRandomWord
let nextChoice = map.[state] |> PickNextWord
if MatchText @"\." nextChoice then nextChoice :: chain
else
let currentWords =
@ -38,6 +35,6 @@
This isn't ideal but needed so please be careful when attempting to
remove this line.*)
Thread.Sleep(100)
yield GenerateMarkovSentence map (PickRandomWord startWords).Key
yield GenerateMarkovSentence map (PickRandomItem startWords).Key
}
result |> ConcatToString

28
WetPancake/ProductServices.fs

@ -2,36 +2,24 @@
module Pancake =
//YOU ARE UP TO HERE.
// NEED TO MOVE STUFF UP A LEVEL.
// CREATE AN OBJECT TO STOP THE STATIC CONTENT.
open SystemServices
open DataAccess
open DataCleaning
open DataProcessing
open DataStructuring
open DataServices
let ApplyStandardSetup text =
text
|> ReplaceArtifact "\""
|> ReplaceArtifact "\n\nIn"
|> ReplaceArtifact "\r"
|> ReplaceArtifact "\n"
|> SplitText @"\s+"
|> ConcatToString
open System
let RequestRandomText() =
let data =
LoadFile SelectRandomSampleFile
|> ApplyStandardSetup
|> SortIntoGroups (PickRandomNumber 10)
|> GenerateMap
GenerateMarkovText (PickRandomNumber 10) data
let data =
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups (PickRandomNumber 2 10)
|> GenerateMap
GenerateMarkovText (PickRandomNumber 2 10) data
let RequestText (gibberishLevel: int) (sentences: int) =
let data =
LoadFile SelectRandomSampleFile
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap

17
WetPancake/Script.fsx

@ -17,19 +17,20 @@ open DataProcessing
open DataStructuring
open DataServices
open WetPancake
open System.Data
// System Services
let ss_number = PickRandomNumber 10
let ss_item =
let items = seq {1 .. 10}
PickRandomItem (Random().Next) items
PickRandomItem items
// Data Access
let da_sampleFilePath = CreateSampleTextFilesPath
let da_sampleTextFiles = FindSampleTextFiles da_sampleFilePath
let da_sampleFiles = ListSampleFiles
let da_randomSampleFile = SelectRandomSampleFile
let da_randomSampleFile = SelectRandomSampleFile()
let da_file = LoadFile da_randomSampleFile
// Data Cleaning
@ -92,6 +93,9 @@ let ds_text2 = [
[|"this"; "is"; "the"; "second"; "test"; "string"|]
[|"this"; "is"; "the"; "third"; "test"; "string"|]
]
let ds_text3 =
"This is\r a test \"string\" for\n\nIn ds_text 3\n"
|> ApplyStandardSetup
let ds_map4 = ConstructMap ds_map ds_text2.[1]
let ds_map5 = [for i in ds_text2 -> ConstructMap ds_map i]
let ds_map6 =
@ -107,13 +111,8 @@ let ds_map7Item = ds_map7.Item(0)
// Data Services
let dss_text =
LoadFile SelectRandomSampleFile
|> ReplaceArtifact "\""
|> ReplaceArtifact "\n\nIn"
|> ReplaceArtifact "\r"
|> ReplaceArtifact "\n"
|> SplitText @"\s+"
|> ConcatToString
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups 2
|> GenerateMap
let dss_startwords = SeperateStartWords dss_text

24
WetPancake/SystemServices.fs

@ -2,10 +2,22 @@
open System
let PickRandomNumber max = Random().Next(1, max);
let PickRandomNumber min max = Random().Next(min, max);
let PickRandomItem (rnd: int -> int) seq =
//let index = rnd 0 ((Seq.length seq) - 1)
//seq |> Seq.item index
let index = Random().Next(Seq.length seq);
seq |> Seq.item index
let PickRandomItem seq =
if (Seq.length seq) = 0 then
seq |> Seq.item 0
else
let index = Random().Next(0, Seq.length seq);
seq |> Seq.item index
(* The if-check is used as a fallback.
The "." is used to signifiy the end of a sentence.
This return is picked up in the system,
in the GenerateMarkovChain function. *)
let PickNextWord seq =
if (Seq.length seq) = 0 then
"."
else
let index = Random().Next(0, Seq.length seq);
seq |> Seq.item index

8
WetPancake/TextFiles/word-generator.txt

@ -0,0 +1,8 @@
Are you the type of person who hates work? Are you someone who resents the fact you're born into a system not of your choosing? Are your teachers lazy, dismissive and not interested in your education? We're looking at you Mr.Heath... Then you need Word Generator. The app for students with a deadline.
Imagine you're at home and finishing off your English essay for Mr. Dillbank. A teacher who is always drunk and has been struggling to put a sentence together since 2014. He never used to be this way but Maureen had to leave him for Derek, the Head of Music at Barnworth High. He isn't even good looking. He looks like an orange balloon with pigeon droppings for a moustache. Who, in the history of mankind, thought that was a good look? No one! That's who! Screw you Derek! Screw you! You're fooling no one with that hair piece...
...
Sorry... I got a little side-tracked there....
Anyway, where was I...
So, you're finishing your essay and you realise your word count is lower than the expected one. Two-hundred words short, as a matter of fact. This is infuriating because you're supposed to be playing football in twenty minutes. You don't have enough time to add two-hundred words and be ready in time for football. What do you do? You open Word Generator of course. You add the extra words in a few clicks and your already off to football, with time to spare. Your mum only checks the word count these days and Mr. Dillbank hasn't seen straight for years. They think you have done your homework and you get to play football. Everyone is a winner here, apart from you in the long term but that's ok. It's not ok but it feels ok and that's what counts right now.
So, you're sold. You're in and wanting to know more. How does it work? I'm glad you asked. It uses the latest in space-age technology. Word Generator utilises the Markov Chain algorithm. When you boot Word Generator up, feed it a plain text (.txt) file and specify what Markov Value you want to use. Using that information, it spits out text that resembles the original text. This helps hide the deception.
Just in case you're wondering, the Markov Value is a number. For the app it's a number between one and ten. The higher the number the closer the generated text will resemble the original text. For example, a value of one will generate non-sense and ten will spit out like-for-like text. If you're feeling confident, I recommend you turn it up to five and see if teachers like Mr. Dillbank notices.

3
WetPancake/WetPancake.fsproj

@ -53,7 +53,7 @@
<ItemGroup>
<Content Include="TextFiles\desktop-clock-info.txt" />
<Content Include="TextFiles\console-waterworks-announcement.txt" />
<Content Include="packages.config" />
<Content Include="TextFiles\word-generator.txt" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="SystemServices.fs" />
<Compile Include="DataAccess.fs" />
@ -63,6 +63,7 @@
<Compile Include="DataServices.fs" />
<Compile Include="ProductServices.fs" />
<None Include="Script.fsx" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />

2
WetPancake/packages.config

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.ValueTuple" version="4.4.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
</packages>

36
WetPancakeCLI/ConsoleCommands.cs

@ -3,6 +3,7 @@ using Console.Waterworks.Attributes;
using System;
using static WetPancake.Pancake;
using static System.Environment;
using System.Diagnostics;
namespace WetPancakeCLI
{
@ -32,28 +33,47 @@ namespace WetPancakeCLI
[Usage("> GenerateRandomText")]
public static string GenerateRandomText()
{
var result = RequestRandomText();
return result;
string result = String.Empty;
try { return RequestRandomText(); }
catch (Exception e)
{
Debug.WriteLine(e.Message);
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command...");
return RequestRandomText();
}
}
[ListCommand]
[Description ("Generates text using the gibberish level and number of sentences specified by the user.")]
[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)
{
var result = RequestText(gibberishLevel, sentences);
return result;
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);
}
}
[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.")]
[Parameters("gibberish level: int, sentences: int, file path: string")]
[Usage("> RequestTextFromFile 3 6 C:/yourfile.txt")]
public static string RequestTextFromFile(int gibberishLevel, int sentences, string filePath)
public static string GenerateTextFromFile(int gibberishLevel, int sentences, string filePath)
{
var result = RequestTextFromFile(gibberishLevel, sentences, filePath);
return result;
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);
}
}
}
}

3
WetPancakeCLI/WetPancakeCLI.csproj

@ -40,6 +40,9 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />

1
WetPancakeCLI/packages.config

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Console.Waterworks" version="0.1.0.0-alpha1" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
</packages>
Loading…
Cancel
Save