2 Module : Gargantext.Text.Metrics.Occurrences
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
17 module Gargantext.Text.Metrics.Occurrences where
19 import Gargantext.Prelude
21 import Control.Monad ((>>),(>>=))
22 import Data.String (String())
23 import Data.Attoparsec.Text
24 import Data.Text (Text)
26 import Data.Either.Extra(Either(..))
27 import qualified Data.Text as T
28 import Control.Applicative
31 occurrenceParser :: Text -> Parser Bool
32 occurrenceParser txt = manyTill anyChar (string txt) >> pure True
34 occurrencesParser :: Text -> Parser Int
35 occurrencesParser txt = case txt of
37 _ -> many (occurrenceParser txt') >>= \matches -> pure (length matches)
41 parseOccurrences :: Text -> Text -> Either String Int
42 parseOccurrences x = parseOnly (occurrencesParser x)