Browse Source

Added check to catch the seq. length exception.

All tests are passed before completing this commit.
master
Craig Oates 6 years ago
parent
commit
aeed1fd1f4
  1. 7
      WetPancake/DataServices.fs
  2. 6
      WetPancake/SystemServices.fs

7
WetPancake/DataServices.fs

@ -9,7 +9,8 @@
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 ((Seq.length map) = 0) then nextChoice <- "fallback word."
if ((List.length map.[state]) <= 1) then
nextChoice <- "."
else
nextChoice <- map.[state] |> PickNextWord
//let nextChoice = map.[state] |> PickNextWord
@ -51,13 +52,13 @@
*)
let GenerateMarkovTextTesting noOfSentences map =
let startWords = fst(SeperateStartWords map)
if Seq.isEmpty startWords then
if ((Map.count startWords) <= 1) then
"Failed to generate a result"
else
let result =
seq {
for i in 1 .. noOfSentences do
Thread.Sleep(100)
yield GenerateMarkovSentence map (PickRandomItem startWords).Key
yield GenerateMarkovSentence map (PickRandomItem startWords).Key
}
result |> ConcatToString

6
WetPancake/SystemServices.fs

@ -21,8 +21,10 @@
This return is picked up in the system,
in the GenerateMarkovChain function. *)
let PickNextWord seq =
if (Seq.length seq) = 0 then
"."
if (Seq.length seq) = 1 then
//"."
seq |> Seq.item 0
//let temp = seq |> Seq.item 0
else
let index = PickRandomNumber 1 (Seq.length seq)
seq |> Seq.item index

Loading…
Cancel
Save