|
|
|
@ -15,11 +15,11 @@
|
|
|
|
|
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 |
|
|
|
|
|> SplitText "\s+" |
|
|
|
|
|> SplitText @"\s+" |
|
|
|
|
|> Seq.skip 1 |
|
|
|
|
|> ConcatToString |
|
|
|
|
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain) |
|
|
|
@ -73,7 +73,20 @@
|
|
|
|
|
} |
|
|
|
|
result |> ConcatToString |
|
|
|
|
|
|
|
|
|
// TODO: Write up comment for use of ReplaceArtifact. |
|
|
|
|
(* Note: RemoveArtifactSentences Breakdown |
|
|
|
|
================================================================================================================== |
|
|
|
|
This function receives a string and an int as its parameters. |
|
|
|
|
The text being the string and the int being the total of intended sentences. |
|
|
|
|
When using the GenerateMarkovText function, it can sometimes produce an unexpected extra sentence. |
|
|
|
|
(See the GenerateMarkovText-comment above for further details.) |
|
|
|
|
For the most part, the outcome of this "mishap" is fine (this is a random word generator, not a space rocket). |
|
|
|
|
With that said, run the generated text through this function if you want "clean" results. |
|
|
|
|
It will mean it will take longer to process the results but it does reduce the chance of incorrect output. |
|
|
|
|
("Incorrect" from the end-users point-of-view.) |
|
|
|
|
The ReplaceArtifact function at the end counteracts the effects of the text splitting. |
|
|
|
|
SplitText splits the text and adds a space at the split. |
|
|
|
|
This leads to the text having double-spaces when concatenated back together. |
|
|
|
|
*) |
|
|
|
|
let RemoveArtifactSentences noOfSentences text = |
|
|
|
|
text |
|
|
|
|
|> SplitText @"(?<=[\.\!\?]\s)" |
|
|
|
|