|
|
|
module internal DataServices
|
|
|
|
|
|
|
|
open SystemServices
|
|
|
|
open DataStructuring
|
|
|
|
open DataProcessing
|
|
|
|
open DataCleaning
|
|
|
|
open System.Threading
|
|
|
|
open System
|
|
|
|
open DataAccess
|
|
|
|
|
|
|
|
let CheckFileExists filePath =
|
|
|
|
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
|
|
|
|
else
|
|
|
|
let currentWords =
|
|
|
|
state
|
|
|
|
|> SplitText @"\s+"
|
|
|
|
|> Seq.skip 1
|
|
|
|
|> ConcatToString
|
|
|
|
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain)
|
|
|
|
else
|
|
|
|
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 --
|
|
|
|
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. *)
|
|
|
|
let GenerateMarkovText noOfSentences map =
|
|
|
|
let startWords = fst(SeperateStartWords map)
|
|
|
|
let result =
|
|
|
|
seq {
|
|
|
|
for i in 1 .. noOfSentences do
|
|
|
|
Thread.Sleep(100)
|
|
|
|
yield GenerateMarkovSentence map (PickRandomItem startWords).Key
|
|
|
|
}
|
|
|
|
result |> ConcatToString
|