]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Ngrams/Occurrences.hs
fix typo
[gargantext.git] / src / Gargantext / Ngrams / Occurrences.hs
1 {-|
2 Module : Gargantext.Ngrams.Occurrences
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
12 -}
13
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16
17 module Gargantext.Ngrams.Occurrences where
18
19 import Gargantext.Prelude
20
21 import Control.Monad ((>>),(>>=))
22 import Data.String (String())
23 import Data.Attoparsec.Text
24 import Data.Text (Text)
25
26 import Data.Either.Extra(Either(..))
27 import qualified Data.Text as T
28 import Control.Applicative
29
30
31 occurrenceParser :: Text -> Parser Bool
32 occurrenceParser txt = manyTill anyChar (string txt) >> pure True
33
34 occurrencesParser :: Text -> Parser Int
35 occurrencesParser txt = case txt of
36 "" -> pure 0
37 _ -> many (occurrenceParser txt') >>= \matches -> pure (length matches)
38 where
39 txt' = T.toLower txt
40
41 parseOccurrences :: Text -> Text -> Either String Int
42 parseOccurrences x = parseOnly (occurrencesParser x)