Craig Oates
6 years ago
4 changed files with 59 additions and 15 deletions
@ -1 +1,26 @@
|
||||
module internal MapProcessing |
||||
module internal MapProcessing |
||||
|
||||
open TextProcessing |
||||
open System |
||||
|
||||
let SeperateStartWords map = |
||||
let startWords = |
||||
map |
||||
|> Map.partition (fun k _ -> IsStartOfSentence k) |
||||
fst startWords |
||||
|
||||
let rec MarkovChain currentWords (map: Map<string, string list>) sentence = |
||||
let nextChoice = map.[currentWords] |> GetRandomWord |
||||
if IsEndOfSentence nextChoice then nextChoice :: sentence |
||||
else |
||||
let currentState = |
||||
currentWords |
||||
|> SplitIntoWords |
||||
|> Seq.skip 1 |
||||
|> JoinWords |
||||
MarkovChain (CombineWords currentState nextChoice) map (nextChoice :: sentence) |
||||
|
||||
let GetMarkovSentence startWords map = |
||||
MarkovChain startWords map [startWords] |
||||
|> List.rev |
||||
|> JoinWords |
@ -1,8 +1,24 @@
|
||||
// Learn more about F# at http://fsharp.org |
||||
// See the 'F# Tutorial' project for more help. |
||||
|
||||
#load "FileProcessing.fs" |
||||
#load "TextProcessing.fs" |
||||
#load "MapProcessing.fs" |
||||
#load "CoOrdinator.fs" |
||||
|
||||
open FileProcessing |
||||
open TextProcessing |
||||
open MapProcessing |
||||
open CoOrdinator |
||||
|
||||
IsStartOfSentence "bob" |
||||
IsEndOfSentence "bill." |
||||
|
||||
let text = SelectRandomSampleFile |> LoadFile |
||||
let wordGroups = GetWordPairs 4 text |
||||
//let wordGroups = GetWordPairs (PickRandomNumber 13) text |
||||
let map = BuildMarkovMap wordGroups |
||||
let startWords = SeperateStartWords map |
||||
//let temp = snd startWords |
||||
let count = Map.count startWords |
||||
let random = PickRandomNumber (Map.count startWords) |
Loading…
Reference in new issue