Created
March 17, 2014 06:56
-
-
Save shwars/9595019 to your computer and use it in GitHub Desktop.
Demonstrating how to process text file using sequences in F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.IO | |
let ReadLines fn = | |
seq { use inp = File.OpenText fn in | |
while not(inp.EndOfStream) do | |
yield (inp.ReadLine()) | |
} | |
#load @"FSharpChart.fsx" | |
#load @"FSharpChartAutoDisplay.fsx" | |
open Samples.Charting | |
type System.String with | |
member x.GoodSplit() = x.Split([|'"';' ';'!';'.';',';';';'-'|]) | |
let file = ReadLines @"c:\books\wap_1.txt" | |
file | |
|> Seq.map (fun x -> x.GoodSplit()) | |
|> Seq.concat | |
|> Seq.filter (fun x->x.Length>3) | |
|> Seq.groupBy (fun x->x.ToLower()) | |
|> Seq.map (fun (l,s) -> (l,-Seq.length s)) | |
|> Seq.sortBy snd | |
|> Seq.take 5 | |
|> FSharpChart.Bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment