Skip to content

Instantly share code, notes, and snippets.

@Thorium
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thorium/4ee6b0debdbcb9bddb7f to your computer and use it in GitHub Desktop.
Save Thorium/4ee6b0debdbcb9bddb7f to your computer and use it in GitHub Desktop.
Analyse word count from files. You can use it e.g. to create Tag Clouds
//From NuGet: Sparc.TagCloud
#if INTERACTIVE
#r @"..\packages\Sparc.TagCloud.0.0.1\lib\net40\Sparc.TagCloud.dll"
#else
module MyTagCloud
#endif
open System.IO
open Sparc.TagCloud
let analyzer = new TagCloudAnalyzer()
let path = @"C:\sourcecodes\"
let extension = "*.cs" //e.g. c# files
let lines =
Directory.GetFiles(path, extension, SearchOption.AllDirectories)
|> Seq.map(fun i -> File.ReadAllLines(i))
|> Seq.concat
let ``analyze and print`` =
analyzer.ComputeTagCloud(lines)//.Shuffle()
|> Seq.where(fun i -> i.Text.Length > 3) //over 3 letter words only...
|> Seq.take(50) //top 50 only...
|> Seq.iter(fun r -> printfn "%s\t%i" r.Text r.Count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment