Browse Source

Working working.

Can start the console program and request random text.
master
Craig Oates 6 years ago
parent
commit
c7c265072c
  1. 21
      WetPancake/DataServices.fs
  2. 27
      WetPancake/ProductServices.fs
  3. 7
      WetPancake/Script.fsx
  4. 5
      WetPancakeCLI/ConsoleCommands.cs

21
WetPancake/DataServices.fs

@ -3,21 +3,32 @@
open SystemServices
open System
open DataStructuring
open DataProcessing
open DataCleaning
let PickStartWord words = PickRandomItem (Random().Next) words
let PickRandomWord words = PickRandomItem (Random().Next) words
let rec GenerateMarkovChain (map: Map<string, string List>) (state:string) chain =
let nextChoice = map.[state]
nextChoice
let nextChoice = map.[state] |> PickRandomWord
if MatchText @"\." nextChoice then nextChoice :: chain
else
let currentWords =
state
|> SplitText @"\s+"
|> Seq.skip 1
|> ConcatToString
GenerateMarkovChain map (CombineWords currentWords nextChoice) (nextChoice :: chain)
let GenerateMarkovSentence map start =
GenerateMarkovChain map start [start]
|> List.rev
|> ConcatToString
let GenerateMarkovText noOfSentences map =
let startWords = fst(SeperateStartWords map)
let result =
seq {
for i in 0 .. noOfSentences do
yield GenerateMarkovSentence map (PickStartWord startWords).Key
yield GenerateMarkovSentence map (PickRandomWord startWords).Key
}
Seq.toList result
result |> ConcatToString

27
WetPancake/ProductServices.fs

@ -1,9 +1,28 @@
namespace WetPancake
(*
module Pancake
//let RequestRandomText
module Pancake =
open System
open SystemServices
open DataAccess
open DataCleaning
open DataProcessing
open DataStructuring
open DataServices
let RequestRandomText =
let dss_text =
LoadFile SelectRandomSampleFile
|> ReplaceArtifact "\""
|> ReplaceArtifact "\n\nIn"
|> ReplaceArtifact "\r"
|> ReplaceArtifact "\n"
|> SplitText @"\s+"
|> ConcatToString
|> SortIntoGroups 10
|> GenerateMap
GenerateMarkovText 2 dss_text
//let RequestText (gibberishLevel: int) (sentences: int)
//let RequestTextFromFile (gibberishLevel: int) (sentences: int) (filePath: string)*)
//let RequestTextFromFile (gibberishLevel: int) (sentences: int) (filePath: string)

7
WetPancake/Script.fsx

@ -113,7 +113,8 @@ let dss_text =
|> ReplaceArtifact "\n"
|> SplitText @"\s+"
|> ConcatToString
|> SortIntoGroups 6
|> SortIntoGroups 2
|> GenerateMap
let dss_startwords = SeperateStartWords dss_text
let dss_sentences = GenerateMarkovText 4 dss_text
//let dss_startwords = SeperateStartWords dss_text
let dss_sentences = GenerateMarkovText 2 dss_text
printfn "Text: %A" dss_sentences

5
WetPancakeCLI/ConsoleCommands.cs

@ -1,6 +1,7 @@
using Console.Waterworks;
using Console.Waterworks.Attributes;
using System;
using WetPancake;
//using WetPancake;
using static System.Environment;
@ -32,8 +33,8 @@ namespace WetPancakeCLI
[Usage("> GenerateRandomText")]
public static string GenerateRandomText(int sentences)
{
//var result = Pancake.RequestRandomText;
return "Not implemented yet.";
var result = Pancake.RequestRandomText;
return result;
}
public static string test1()

Loading…
Cancel
Save