1 {-# LANGUAGE OverloadedStrings #-}
3 module Gargantext.Ngrams.Count where
5 import Gargantext.Prelude
8 import Data.Foldable as F
10 import Data.Map.Strict (insertWith)
12 import qualified Data.Map as M
14 --import qualified Data.Text.Lazy.IO as DTLIO
15 import qualified Data.Text.Lazy as DTL
17 -- | /O(n)/ Breaks a 'Text' up into each Text list of chars.
18 -- from slower to faster:
19 letters :: DTL.Text -> [DTL.Text]
20 letters text = DTL.chunksOf 1 text
22 letters' :: DTL.Text -> [DTL.Text]
23 letters' text = DTL.splitOn "#" $ DTL.intersperse '#' text
25 letters'' :: DTL.Text -> [DTL.Text]
26 letters'' = DTL.foldr (\ch xs -> DTL.singleton ch : xs) []
31 -- words between punctuation
32 -- number of punctuation
34 occurrences :: Ord a => [a] -> Map a Int
35 occurrences xs = foldl' (\x y -> insertWith (+) y 1 x) M.empty xs
38 --occurrences' :: Ord a => [a] -> Map a Integer
39 --occurrences' xs = DTL.foldl (\x y -> M.insertWith' (+) y 1 x) M.empty xs
43 -- (fichier:_) <- getArgs
44 -- c <- DTLIO.readFile fichier
45 -- --print $ occurrences $ DTL.chunksOf 1 c
46 -- pure $ occurrences $ letters'' c
47 -- --print $ occurrences $ DTL.words $ DTL.toLower c