2 Module : Gargantext.Text.Terms.Mono
3 Description : Mono Terms module
4 Copyright : (c) CNRS, 2017 - present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Mono-terms are Nterms where n == 1.
14 {-# LANGUAGE NoImplicitPrelude #-}
16 module Gargantext.Text.Terms.Mono (monoterms, monoterms')
19 import Data.Text (Text, toLower, split, splitOn, pack)
20 import qualified Data.Set as S
22 import Gargantext.Core
23 import Gargantext.Core.Types
24 import Gargantext.Text.Terms.Mono.Stem (stem)
26 import Gargantext.Prelude
27 import Data.Char (isAlphaNum, isSpace)
29 monoterms' :: Lang -> Text -> [Terms]
30 monoterms' l txt = map (text2terms l) $ monoterms txt
32 monoterms :: Text -> [Text]
33 monoterms txt = map toLower $ split isWord txt
35 isWord c = c `elem` [' ', '\'', ',', ';']
37 text2terms :: Lang -> Text -> Terms
38 text2terms lang txt = Terms label stems
40 label = splitOn (pack " ") txt
41 stems = S.fromList $ map (stem lang) label
43 --monograms :: Text -> [Text]
44 --monograms xs = monograms $ toLower $ filter isGram xs
46 isGram :: Char -> Bool
47 isGram c = isAlphaNum c || isSpace c || c `elem` ['-','/','\'']