Browse Source

Implemented text processing.

master
Craig Oates 6 years ago
parent
commit
020cb02896
  1. 45
      WetPancake/Textprocessing.fs
  2. 2
      WetPancakeCLI/ConsoleCommands.cs

45
WetPancake/Textprocessing.fs

@ -1,3 +1,46 @@
module internal TextProcessing
open FileProcessing
open System.Text.RegularExpressions
open System
let SplitIntoWords text = Regex.Split(text, @"\@s+")
let JoinWords words = String.concat " " words
let GetWordPairs pairSize = SplitIntoWords >> Seq.windowed pairSize
let BisectWords (words:_[]) =
let length = Array.length words
let predictions = words |> Seq.take (length - 1)
(predictions |> JoinWords, words.[length - 1])
let UpdateMap (map:Map<_,_>) key value =
if map.ContainsKey key then
let existingValue = map.[key]
let map = map |> Map.remove key
map |> Map.add key (value :: existingValue)
else
map.Add(key, [value])
let MapBuilder map words =
BisectWords words ||> UpdateMap map
let BuildMarkovMap<'a> = Seq.fold MapBuilder Map.empty
let GetRandomWord (random: int -> int) seq =
let randomIndex = random (Seq.length seq)
seq |> Seq.item randomIndex
let GetWord words =
let randomWord = Random().Next(Seq.length words)
words |> Seq.item randomWord
let CombineWords prev next =
[prev; next]
|> List.filter (fun s -> not (String.IsNullOrWhiteSpace s))
|> JoinWords
let GetMarkovSentence startWord markovChain =
markovChain startWord [startWord]
|> List.rev
|> JoinWords

2
WetPancakeCLI/ConsoleCommands.cs

@ -38,7 +38,7 @@ namespace WetPancakeCLI
public static string test1()
{
return "This is a text method for quickly testing things out";
return "This is a test method for quickly testing things out";
}
}
}

Loading…
Cancel
Save