|
|
|
@ -12,10 +12,11 @@
|
|
|
|
|
ListSampleFiles |
|
|
|
|
|> Array.contains filePath |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 +25,46 @@
|
|
|
|
|
|> 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 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 indepth breakdown of data types/structures.) |
|
|
|
|
1. 'Seperate 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 senetence" ["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 the data-cleaner function. |
|
|
|
|
(THE DATA-CLEANER FUNCTION HAS NOT BEEN MADE YET.) |
|
|
|
|
*) |
|
|
|
|
let GenerateMarkovText noOfSentences map = |
|
|
|
|
let startWords = fst(SeperateStartWords map) |
|
|
|
|
let result = |
|
|
|
|