|
|
|
@ -7,21 +7,19 @@
|
|
|
|
|
open System.Threading |
|
|
|
|
|
|
|
|
|
let rec GenerateMarkovChain (map: Map<string, string List>) (state:string) chain = |
|
|
|
|
// up to here need to break th circuit at this point. |
|
|
|
|
let mutable nextChoice = "" |
|
|
|
|
if ((List.length map.[state]) <= 1) then |
|
|
|
|
nextChoice <- "." |
|
|
|
|
if map.ContainsKey state then |
|
|
|
|
let nextChoice = map.[state] |> PickNextWord |
|
|
|
|
if MatchText @"\." nextChoice then nextChoice :: chain |
|
|
|
|
else |
|
|
|
|
let currentWords = |
|
|
|
|
state |
|
|
|
|
|> SplitText @"\s+" |
|
|
|
|
|> Seq.skip 1 |
|
|
|
|
|> ConcatToString |
|
|
|
|
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain) |
|
|
|
|
else |
|
|
|
|
nextChoice <- map.[state] |> PickNextWord |
|
|
|
|
//let nextChoice = map.[state] |> PickNextWord |
|
|
|
|
if MatchText @"\." nextChoice then nextChoice :: chain |
|
|
|
|
else |
|
|
|
|
let currentWords = |
|
|
|
|
state |
|
|
|
|
|> SplitText @"\s+" |
|
|
|
|
|> Seq.skip 1 |
|
|
|
|
|> ConcatToString |
|
|
|
|
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain) |
|
|
|
|
let fallbackChoice = (PickRandomItem map).Key |
|
|
|
|
fallbackChoice + "." :: chain |
|
|
|
|
|
|
|
|
|
let GenerateMarkovSentence map start = |
|
|
|
|
GenerateMarkovChain map start [start] |
|
|
|
@ -52,13 +50,10 @@
|
|
|
|
|
*) |
|
|
|
|
let GenerateMarkovTextTesting noOfSentences map = |
|
|
|
|
let startWords = fst(SeperateStartWords map) |
|
|
|
|
if ((Map.count startWords) <= 1) then |
|
|
|
|
"Failed to generate a result" |
|
|
|
|
else |
|
|
|
|
let result = |
|
|
|
|
let result = |
|
|
|
|
seq { |
|
|
|
|
for i in 1 .. noOfSentences do |
|
|
|
|
Thread.Sleep(100) |
|
|
|
|
yield GenerateMarkovSentence map (PickRandomItem startWords).Key |
|
|
|
|
} |
|
|
|
|
result |> ConcatToString |
|
|
|
|
result |> ConcatToString |