2 Module : Gargantext.API.Ngrams.List
3 Description : Get Ngrams (lists)
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE DataKinds #-}
13 {-# LANGUAGE DeriveGeneric #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE FlexibleInstances #-}
16 {-# LANGUAGE MultiParamTypeClasses #-}
17 {-# LANGUAGE NoImplicitPrelude #-}
18 {-# LANGUAGE OverloadedStrings #-}
19 {-# LANGUAGE RankNTypes #-}
20 {-# LANGUAGE TemplateHaskell #-}
21 {-# LANGUAGE TypeOperators #-}
23 module Gargantext.API.Ngrams.List
27 -- import qualified Data.ByteString.Lazy as BSL
28 import Data.List (zip)
29 import Data.Map (Map, toList, fromList)
30 -- import qualified Data.Text as T
31 -- import qualified Data.Text.Encoding as TE
32 import Network.HTTP.Media ((//), (/:))
35 import Gargantext.Prelude
36 import Gargantext.API.Ngrams
37 import Gargantext.API.Types (GargServer)
38 import Gargantext.Database.Flow (FlowCmdM)
39 import Gargantext.Database.Schema.Ngrams (NgramsType(..), ngramsTypes)
40 import Gargantext.Database.Types.Node
42 type NgramsList = (Map NgramsType (Versioned NgramsTableMap))
45 instance Accept HTML where
46 contentType _ = "text" // "html" /: ("charset", "utf-8")
47 instance ToJSON a => MimeRender HTML a where
50 type API = Get '[JSON] NgramsList
51 :<|> ReqBody '[JSON] NgramsList :> Put '[JSON] Bool
52 :<|> Get '[HTML] NgramsList
54 api :: ListId -> GargServer API
55 api l = get l :<|> put l :<|> get l
57 get :: RepoCmdM env err m
58 => ListId -> m NgramsList
61 <$> mapM (getNgramsTableMap lId) ngramsTypes
63 getHtml :: RepoCmdM env err m
64 => ListId -> m NgramsList
68 --return $ TE.decodeUtf8 $ BSL.toStrict $ encode lst
72 put :: FlowCmdM env err m
77 -- TODO check with Version for optim
78 _ <- mapM (\(nt, Versioned _v ns) -> putListNgrams' l nt ns) $ toList m