Browse Source

Moved TextContainsValidEndToken to DataProcessing.

End of session check-in.
master
Craig Oates 6 years ago
parent
commit
cde386068d
  1. 7
      WetPancake/DataProcessing.fs
  2. 15
      WetPancake/DataServices.fs
  3. 10
      WetPancake/ProductServices.fs
  4. 12
      WetPancake/Script.fsx

7
WetPancake/DataProcessing.fs

@ -29,6 +29,13 @@
raise (FileNotFoundException("Unable to find the file at the location specified."))
| _ -> ignore
let TextContainsValidEndToken (text: string) =
match text with
| text when text.Contains "." -> true
| text when text.Contains "!" -> true
| text when text.Contains "?" -> true
| _ -> false
let SortIntoGroups groupSize text =
SplitText @"\s+" text // Splits text where there is a space.
|> Seq.windowed groupSize

15
WetPancake/DataServices.fs

@ -93,17 +93,4 @@
|> Array.take noOfSentences
|> ConcatToString
|> ReplaceArtifact " "
|> TrimEnd [|' '|]
let TextContainsValidEndToken (text: string) =
let result = text.Contains "." || text.Contains"!" || text.Contains "?"
match result with
| true -> true
| false -> failwith "The text does not contain a valid end token ('.', '!' and/or '?')."
(*
match text with
| text when (text.Contains".") -> true
| text.Contains "!" -> true
| text.Contains "?" -> true
| _ -> failwith "The text does not contain a valid end token ('.', '!' and/or '?')."
*)
|> TrimEnd [|' '|]

10
WetPancake/ProductServices.fs

@ -44,6 +44,11 @@ module Pancake =
| :? InvalidOperationException -> return text
}
let TextInFileIsValid filePath =
async {
return DataAccess.LoadFile filePath |> TextContainsValidEndToken
}
/// <summary>
/// An asynchronous function which generates random text.
/// </summary>
@ -53,7 +58,7 @@ module Pancake =
/// <remarks>
/// This function will produce a maximum of 10 sentences with each function call.
/// </remarks>
let RequestRandomTextAsync() =
let RequestRandomTextAsync () =
async {
let data =
LoadFile (SelectRandomSampleFile())
@ -147,7 +152,8 @@ module Pancake =
try
GibberishLevelIsValid gibberishLevel |> ignore
SentencesIsValid sentences |> ignore
FilePathIsValid |> ignore
FilePathIsValid filePath |> ignore
// pattern match the TextInFileIsValid function
let data =
LoadFile filePath
|> ApplyStandardSetup

12
WetPancake/Script.fsx

@ -115,6 +115,12 @@ let dp_filePathIsValidException =
| :? ArgumentException as ex -> ex.Message
| :? FileNotFoundException as ex -> ex.Message
let dp_sentences = "This is a test setence." // Edit this to test (valid end token)
let dp_validEndToken () =
let result = TextContainsValidEndToken dp_sentences
result
printfn "Valid End Token: %b" (dp_validEndToken())
// Data Structuring
let ds_map = Map.empty
let ds_text = [|"This"; "is"; "a"; "test"; "string."|]
@ -160,12 +166,6 @@ let dss_clean =
|> RemoveArtefactSentences 6 // Change the no. of sentences to test.
printfn "CLEANED TEXT: %s" dss_clean
let dss_sentences3 = "This is a test setence?"
let dss_validEndToken () =
let result = TextContainsValidEndToken dss_sentences3
result
printfn "Valid End Token: %b" (dss_validEndToken())
// Product Services (Pancake)
let ps_files = Pancake.RequestAllTemplateFilesAsync ()

Loading…
Cancel
Save