1 {-# LANGUAGE OverloadedStrings #-}
3 module Gargantext.Ngrams.Occurrences where
5 import Gargantext.Prelude
7 import Control.Monad ((>>),(>>=))
8 import Data.String (String())
9 import Data.Attoparsec.Text
10 import Data.Text (Text)
12 import Data.Either.Extra(Either(..))
13 import qualified Data.Text as T
14 import Control.Applicative
17 occurrenceParser :: Text -> Parser Bool
18 occurrenceParser txt = manyTill anyChar (string txt) >> pure True
20 occurrencesParser :: Text -> Parser Int
21 occurrencesParser txt = case txt of
23 _ -> many (occurrenceParser txt') >>= \matches -> pure (length matches)
27 parseOccurrences :: Text -> Text -> Either String Int
28 parseOccurrences x = parseOnly (occurrencesParser x)