]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Ngrams.hs
[API][NGRAMS] NgramsId changes and Patch added.
[gargantext.git] / src / Gargantext / API / Ngrams.hs
1 {-|
2 Module : Gargantext.API.Ngrams
3 Description : Server API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Ngrams API
11
12 -- | TODO
13 -- get data of NgramsTable
14 -- post :: update NodeNodeNgrams
15 -- group ngrams
16
17 get ngrams filtered by NgramsType
18 add get
19
20 -}
21
22 {-# LANGUAGE DeriveGeneric #-}
23 {-# LANGUAGE NoImplicitPrelude #-}
24 {-# LANGUAGE OverloadedStrings #-}
25 {-# LANGUAGE TemplateHaskell #-}
26 {-# LANGUAGE FlexibleInstances #-}
27
28 module Gargantext.API.Ngrams
29 where
30
31 import Data.Aeson (FromJSON, ToJSON)
32 import Data.Aeson.TH (deriveJSON)
33
34 import Data.Map.Strict (Map)
35 import Data.Map.Strict.Patch (Patch, apply, transformWith)
36 import Data.Text (Text)
37 import Data.Set (Set)
38 import GHC.Generics (Generic)
39
40 import Gargantext.Database.Ngram (NgramsId)
41 import Gargantext.Database.User (UserId)
42 import Gargantext.Core.Types (ListType(..))
43 import Gargantext.Core.Types.Main (Tree(..))
44 import Gargantext.Core.Utils.Prefix (unPrefix)
45 import Gargantext.Prelude
46
47 data NgramsElement =
48 NgramsElement { _ne_id :: Int
49 , _ne_ngrams :: Text
50 , _ne_list :: ListType
51 }
52 $(deriveJSON (unPrefix "_ne_") ''NgramsElement)
53
54
55 data NgramsTable = NgramsTable { _ngramsTable :: [Tree NgramsElement] }
56 deriving (Generic)
57
58 instance ToJSON NgramsTable
59 instance FromJSON NgramsTable
60
61 instance FromJSON (Tree NgramsElement)
62 -- TODO
63 instance ToJSON (Tree NgramsElement)
64
65 --data Action = InGroup NgramsId NgramsId
66 -- | OutGroup NgramsId NgramsId
67 -- | SetListType NgramsId ListType
68
69 data NgramsPatch =
70 NgramsPatch { list_types :: Map UserId ListType
71 , add_children :: Set NgramsId
72 , rem_children :: Set NgramsId
73 }
74
75 data Patch = Map NgramsId NgramsPatch
76
77 -- applyPatchBack :: Patch -> IO Patch
78 -- isEmptyPatch = Map.all (\x -> Set.isEmpty (add_children x) && Set.isEmpty ... )
79
80 -------------------------------------------------------------------
81 -------------------------------------------------------------------
82 -------------------------------------------------------------------