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
26 import Data.Text (Text, concat, pack)
28 import Data.List (zip)
29 import Data.Map (Map, toList, fromList)
30 import Network.HTTP.Media ((//), (/:))
33 import Gargantext.Prelude
34 import Gargantext.API.Ngrams
35 import Gargantext.API.Types (GargServer)
36 import Gargantext.Database.Flow (FlowCmdM)
37 import Gargantext.Database.Schema.Ngrams (NgramsType(..), ngramsTypes)
38 import Gargantext.Database.Types.Node
40 type NgramsList = (Map NgramsType (Versioned NgramsTableMap))
43 instance Accept HTML where
44 contentType _ = "text" // "html" /: ("charset", "utf-8")
45 instance ToJSON a => MimeRender HTML a where
48 type API = ReqBody '[JSON] NgramsList :> Put '[JSON] Bool
49 :<|> Get '[HTML] (Headers '[Header "Content-Disposition" Text] NgramsList)
51 api :: ListId -> GargServer API
52 api l = put l :<|> getHtml l
54 get :: RepoCmdM env err m
55 => ListId -> m NgramsList
58 <$> mapM (getNgramsTableMap lId) ngramsTypes
60 getHtml :: RepoCmdM env err m
61 => ListId -> m (Headers '[Header "Content-Disposition" Text] NgramsList)
65 return $ addHeader (concat ["attachment; filename=GarganText_NgramsList-", pack $ show id, ".json"]) lst
69 put :: FlowCmdM env err m
74 -- TODO check with Version for optim
75 _ <- mapM (\(nt, Versioned _v ns) -> putListNgrams' l nt ns) $ toList m