Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.03 KB | None | 0 0
  1. open System
  2. open System.IO
  3. open System.Collections.Generic
  4. open System.Collections.Concurrent
  5. open System.Text
  6.  
  7. let capitals = ConcurrentDictionary<string, string>()
  8.  
  9. capitals.["Italy"] <- "Rome"
  10. let x = capitals.["Italy"]
  11.  
  12. //Simple word count example
  13. let wordCount dirPath wildCard =
  14.  
  15.     let wordCounts = Dictionary<string, int>()
  16.  
  17.     let processFile fileName =
  18.         let text = File.ReadAllLines(fileName)
  19.  
  20.         text.Split ([|'.'; ' '; '\r'|], StringSplitOptions.RemoveEmptyEntries)
  21.         |> Array.map(fun w -> w.Trim())
  22.         |> Array.filter(fun w -> w.Length > 2)
  23.         |> Array.iter(fun w ->
  24.             let ok, count = wordCounts.TryGetValue(w)
  25.             if ok then
  26.                 wordCounts.[w] <- count + 1
  27.             else
  28.                 wordCounts.[w] <- 1)
  29.  
  30.     Directory.EnumerateFiles(dirPath, wildCard)
  31.     |> Seq.iter processFile
  32.  
  33.     wordCounts
  34.     |> Seq.sortBy(fun kv -> kv.Value)
  35.  
  36.  
  37.  
  38. [<EntryPoint>]
  39. let main argv =
  40.     printfn "%A" argv
  41.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement