Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.IO
- open System.Text.RegularExpressions
- let readFile (path : string) : string =
- use stream = new StreamReader(path)
- let mutable keepReading = true
- let mutable text = ""
- while (keepReading) do
- let line = stream.ReadLine()
- if (line = null) then
- keepReading <- false
- else
- text <- text + line
- text
- let createStats (text : string) =
- // text.ToLower().Split([|',';' ';'\n'|])
- Regex.Split (text.ToLower(), "[^A-Za-zæøåÆØÅ]")
- |> Seq.where (fun w -> w.Length > 0)
- |> Seq.countBy (fun s -> s.Trim())
- |> Seq.sortBy (snd >> (~-))
- let writeToFile (wordSeq : seq<string * int>) (sw:StreamWriter) =
- let wordList = Seq.toList wordSeq
- for pair in wordList do
- sw.WriteLine( string (fst pair) + " : " + string (snd pair) )
- let text = readFile "./storeClausLilleClaus.txt"
- let seq = createStats text
- let sw = new StreamWriter("hyppighed.txt")
- writeToFile seq sw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement