2 Module : Gargantext.Viz.Phylo.API
3 Description : Phylo API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
13 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 {-# LANGUAGE RankNTypes #-}
17 {-# LANGUAGE DataKinds #-}
18 {-# LANGUAGE NoImplicitPrelude #-}
19 {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
20 {-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists
21 {-# LANGUAGE TypeOperators #-}
22 {-# LANGUAGE FlexibleInstances #-}
24 module Gargantext.Viz.Phylo.API
27 --import Control.Monad.Reader (ask)
28 import Data.Text (Text)
29 import Data.Map (empty)
31 import Gargantext.API.Types
32 import Gargantext.Database.Types.Node (PhyloId, ListId, CorpusId)
33 import Gargantext.Prelude
34 import Gargantext.Viz.Phylo
35 import Gargantext.Viz.Phylo.Example
36 import Gargantext.Viz.Phylo.Tools
37 import Gargantext.Viz.Phylo.View.ViewMaker
38 import Gargantext.Viz.Phylo.LevelMaker
40 import Servant.Job.Utils (swaggerOptions)
41 import Test.QuickCheck (elements)
42 import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
43 import Web.HttpApiData (parseUrlPiece, readTextData)
45 ------------------------------------------------------------------------
46 type PhyloAPI = Summary "Phylo API"
52 phyloAPI :: PhyloId -> GargServer PhyloAPI
53 phyloAPI n = getPhylo n
57 ------------------------------------------------------------------------
58 type GetPhylo = QueryParam "listId" ListId
59 :> QueryParam "level" Level
60 :> QueryParam "filiation" Filiation
61 :> QueryParam "childs" Bool
62 :> QueryParam "depth" Level
63 :> QueryParam "metrics" [Metric]
64 :> QueryParam "periodsInf" Int
65 :> QueryParam "periodsSup" Int
66 :> QueryParam "minNodes" Int
67 :> QueryParam "taggers" [Tagger]
68 :> QueryParam "sort" Sort
69 :> QueryParam "order" Order
70 :> QueryParam "export" ExportMode
71 :> QueryParam "display" DisplayMode
72 :> QueryParam "verbose" Bool
73 :> Get '[JSON] PhyloView
76 -- Add real text processing
77 -- Fix Filter parameters
78 getPhylo :: PhyloId -> GargServer GetPhylo
79 getPhylo _phyloId _lId l f b l' ms x y z ts s o e d b' = do
81 fs' = maybe (Just []) (\p -> Just [p]) $ LonelyBranch <$> (LBParams <$> x <*> y <*> z)
83 q = initPhyloQueryView l f b l' ms fs' ts so e d b'
84 -- | TODO remove phylo for real data here
85 pure (toPhyloView q phylo)
86 -- TODO remove phylo for real data here
88 ------------------------------------------------------------------------
90 type PutPhylo = (Put '[JSON] Phylo )
91 --putPhylo :: PhyloId -> Maybe ListId -> PhyloQueryBuild -> Phylo
92 putPhylo :: PhyloId -> GargServer PutPhylo
95 ------------------------------------------------------------------------
96 type PostPhylo = QueryParam "listId" ListId
97 :> ReqBody '[JSON] PhyloQueryBuild
98 :> (Post '[JSON] Phylo)
100 postPhylo :: CorpusId -> GargServer PostPhylo
101 postPhylo _n _lId q = do
102 -- TODO get Reader settings
105 vrs = Just ("1" :: Text)
106 sft = Just (Software "Gargantext" "4")
107 prm = initPhyloParam vrs sft (Just q)
108 pure (toPhyloBase q prm corpus actants termList empty)
111 ------------------------------------------------------------------------
112 -- | DELETE Phylo == delete a node
113 ------------------------------------------------------------------------
119 instance Arbitrary PhyloView
121 arbitrary = elements [phyloView]
123 -- | TODO add phyloGroup ex
124 instance Arbitrary PhyloGroup
126 arbitrary = elements []
128 instance Arbitrary Phylo
130 arbitrary = elements [phylo]
133 instance ToSchema Cluster
134 instance ToSchema EdgeType
135 instance ToSchema Filiation
136 instance ToSchema Filter
137 instance ToSchema FisParams
138 instance ToSchema HammingParams
139 instance ToSchema LouvainParams
140 instance ToSchema Metric
141 instance ToSchema Order
142 instance ToSchema Phylo
143 instance ToSchema PhyloFis
144 instance ToSchema PhyloBranch
145 instance ToSchema PhyloEdge
146 instance ToSchema PhyloGroup
147 instance ToSchema PhyloLevel
148 instance ToSchema PhyloNode
149 instance ToSchema PhyloParam
150 instance ToSchema PhyloFoundations
151 instance ToSchema PhyloPeriod
152 instance ToSchema PhyloQueryBuild
153 instance ToSchema PhyloView
154 instance ToSchema RCParams
155 instance ToSchema LBParams
156 instance ToSchema SBParams
157 instance ToSchema Software
158 instance ToSchema WLJParams
161 instance ToParamSchema Order
162 instance FromHttpApiData Order
164 parseUrlPiece = readTextData
167 instance ToParamSchema Metric
168 instance FromHttpApiData [Metric]
170 parseUrlPiece = readTextData
171 instance FromHttpApiData Metric
173 parseUrlPiece = readTextData
176 instance ToParamSchema DisplayMode
177 instance FromHttpApiData DisplayMode
179 parseUrlPiece = readTextData
182 instance ToParamSchema ExportMode
183 instance FromHttpApiData ExportMode
185 parseUrlPiece = readTextData
188 instance FromHttpApiData Sort
190 parseUrlPiece = readTextData
191 instance ToParamSchema Sort
194 instance ToSchema Proximity
196 declareNamedSchema = genericDeclareNamedSchemaUnrestricted
200 instance FromHttpApiData [Tagger]
202 parseUrlPiece = readTextData
203 instance FromHttpApiData Tagger
205 parseUrlPiece = readTextData
206 instance ToParamSchema Tagger
208 instance FromHttpApiData Filiation
210 parseUrlPiece = readTextData
211 instance ToParamSchema Filiation