1 {-# LANGUAGE OverloadedStrings #-}
3 module Data.Gargantext.Ngrams.Count where
5 import System.Environment (getArgs)
7 import Data.Foldable as F
10 import qualified Data.Map as M
12 import qualified Data.Text.Lazy.IO as DTLIO
13 import qualified Data.Text.Lazy as DTL
15 -- | /O(n)/ Breaks a 'Text' up into each Text list of chars.
16 -- from slower to faster:
17 letters :: DTL.Text -> [DTL.Text]
18 letters text = DTL.chunksOf 1 text
20 letters' :: DTL.Text -> [DTL.Text]
21 letters' text = DTL.splitOn "#" $ DTL.intersperse '#' text
23 letters'' :: DTL.Text -> [DTL.Text]
24 letters'' = DTL.foldr (\ch xs -> DTL.singleton ch : xs) []
29 -- words between punctuation
30 -- number of punctuation
32 occurrences :: Ord a => [a] -> Map a Int
33 occurrences xs = foldl' (\x y -> M.insertWith' (+) y 1 x) M.empty xs
36 --occurrences' :: Ord a => [a] -> Map a Integer
37 --occurrences' xs = DTL.foldl (\x y -> M.insertWith' (+) y 1 x) M.empty xs
41 (fichier:_) <- getArgs
42 c <- DTLIO.readFile fichier
43 --print $ occurrences $ DTL.chunksOf 1 c
44 print $ occurrences $ letters'' c
45 --print $ occurrences $ DTL.words $ DTL.toLower c