Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- let rng = new Random()
- let sentence = "The quick brown fox jumped over the lazy dog"
- let businessWords = ["synergy"; "buzz"; "overflow"; "capital"; "corporate";]
- let splitToPairs (str:string) =
- let rec pairOff arr =
- match arr with
- | h::s::t -> (h, s)::(pairOff t)
- | h::[] -> (h, "")::[]
- | [] -> []
- let words = str.Split [|' '|]
- let pairs = pairOff (List.ofArray words)
- pairs
- let replaceSecondWords pairs words =
- let random (words:string list) =
- let max = words.Length
- let i = rng.Next(0, max)
- words.Item i
- let replacedPairs =
- pairs
- |> List.map(fun p ->
- match p with
- | (f, s) when s = "" -> (f, "")
- | (f, s) -> (f, (random words))
- )
- replacedPairs
- |> List.map(fun p -> String.Join(" ", (fst p), (snd p)))
- |> List.fold (fun state acc -> state + " " + acc) ""
- let newSentence = replaceSecondWords (splitToPairs sentence) businessWords
- (newSentence)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement