]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Types/Main.hs
[API/Count] Adding route and types.
[gargantext.git] / src / Gargantext / Types / Main.hs
1 {-|
2 Module : .Gargantext.Types.Main
3 Description : Short description
4 Copyright : (c) CNRS, 2017
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
12 -}
13 {-# LANGUAGE FlexibleInstances #-}
14 {-# LANGUAGE DeriveGeneric #-}
15
16 module Gargantext.Types.Main where
17
18 import Prelude
19
20 import Data.Eq (Eq())
21 import Data.Monoid ((<>))
22 import Protolude (fromMaybe)
23 import Data.Aeson
24 import GHC.Generics
25 import Servant
26 import Data.Text (unpack)
27 import Text.Read (read)
28 import Data.Either (Either(Right))
29 --import Data.ByteString (ByteString())
30 import Data.Text (Text)
31 import Data.Time (UTCTime)
32 import Data.List (lookup)
33 import Gargantext.Types.Node ( NodePoly, HyperdataUser
34 , HyperdataFolder , HyperdataCorpus , HyperdataDocument
35 , HyperdataFavorites, HyperdataResource
36 , HyperdataList , HyperdataScore
37 , HyperdataGraph
38 , HyperdataPhylo
39 , HyperdataNotebook
40 )
41
42
43 -- | Language of a Text
44 -- For simplicity, we suppose text has an homogenous language
45 data Language = EN | FR -- | DE | IT | SP
46 -- > EN == english
47 -- > FR == french
48 -- > DE == deutch (not implemented yet)
49 -- > IT == italian (not implemented yet)
50 -- > SP == spanish (not implemented yet)
51 -- > ... add your language and help us to implement it (:
52
53
54 -- All the Database is structred like a hierarchical Tree
55 data Tree a = NodeT a [Tree a]
56 deriving (Show, Read, Eq)
57
58
59 -- data Tree a = NodeT a [Tree a]
60 -- same as Data.Tree
61 leafT :: a -> Tree a
62 leafT x = NodeT x []
63
64 -- Garg Network is a network of all Garg nodes
65 --gargNetwork = undefined
66
67 -- | Garg Node is Database Schema Typed as specification
68 -- gargNode gathers all the Nodes of all users on one Node
69 gargNode :: [Tree NodeType]
70 gargNode = [userTree]
71
72 -- | User Tree simplified
73 userTree :: Tree NodeType
74 userTree = NodeT NodeUser [projectTree]
75
76 -- | Project Tree
77 projectTree :: Tree NodeType
78 projectTree = NodeT Project [corpusTree]
79
80 -- | Corpus Tree
81 corpusTree :: Tree NodeType
82 corpusTree = NodeT Corpus ( [ leafT Document ]
83 <> [ leafT Lists ]
84 <> [ leafT Metrics ]
85 <> [ leafT Classification]
86 )
87
88 -- TODO make instances of Nodes
89 -- NP
90 -- * why NodeUser and not just User ?
91 -- * is this supposed to hold data ?
92 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
93 | Classification
94 | Lists
95 | Metrics | Occurrences
96 deriving (Show, Read, Eq, Generic)
97
98 instance FromJSON NodeType
99 instance ToJSON NodeType
100 instance FromHttpApiData NodeType where parseUrlPiece = Right . read . unpack
101
102 data Classification = Favorites | MyClassifcation
103
104 data Lists = StopList | MainList | MapList | GroupList
105
106 -- data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
107 -- | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
108
109
110
111 -- | NodePoly indicates that Node has a Polymorphism Type
112 type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector
113
114 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
115 type NodeTypeId = Int
116 type NodeId = Int
117 type NodeParentId = Int
118 type NodeUserId = Int
119 type NodeName = Text
120 --type NodeVector = Vector
121
122 --type NodeUser = Node HyperdataUser
123
124 -- | Then a Node can be either a Folder or a Corpus or a Document
125 type NodeUser = Node HyperdataUser
126 type Folder = Node HyperdataFolder
127 type Project = Folder -- NP Node HyperdataProject ?
128 type Corpus = Node HyperdataCorpus
129 type Document = Node HyperdataDocument
130
131 -- | Community Manager Use Case
132 type Annuaire = Corpus
133 type Individu = Document
134
135 -- | Favorites Node enable Node categorization
136 type Favorites = Node HyperdataFavorites
137
138 -- | Favorites Node enable Swap Node with some synonyms for clarity
139 type NodeSwap = Node HyperdataResource
140
141 -- | Then a Node can be a List which has some synonyms
142 type List = Node HyperdataList
143 type StopList = List
144 type MainList = List
145 type MapList = List
146 type GroupList = List
147
148 -- | Then a Node can be a Score which has some synonyms
149 type Score = Node HyperdataScore
150 type Occurrences = Score
151 type Cooccurrences = Score
152 type Specclusion = Score
153 type Genclusion = Score
154 type Cvalue = Score
155 type Tficf = Score
156 ---- TODO All these Tfidf* will be replaced with TFICF
157 type TfidfCorpus = Tficf
158 type TfidfGlobal = Tficf
159 type TirankLocal = Tficf
160 type TirankGlobal = Tficf
161 --
162 ---- | Then a Node can be either a Graph or a Phylo or a Notebook
163 type Graph = Node HyperdataGraph
164 type Phylo = Node HyperdataPhylo
165 type Notebook = Node HyperdataNotebook
166
167
168 nodeTypes :: [(NodeType, NodeTypeId)]
169 nodeTypes = [ (NodeUser , 1)
170 , (Project , 2)
171 , (Corpus , 3)
172 , (Document , 4)
173 --, (NodeSwap , 19)
174 ------ Lists
175 -- , (StopList , 5)
176 -- , (GroupList , 6)
177 -- , (MainList , 7)
178 -- , (MapList ,  8)
179 ---- Scores
180 , (Occurrences , 10)
181 -- , (Cooccurrences , 9)
182 --
183 -- , (Specclusion , 11)
184 -- , (Genclusion , 18)
185 -- , (Cvalue , 12)
186 --
187 -- , (TfidfCorpus , 13)
188 -- , (TfidfGlobal , 14)
189 --
190 -- , (TirankLocal , 16)
191 -- , (TirankGlobal , 17)
192 --
193 ---- Node management
194 -- , (Favorites , 15)
195 --
196 ]
197 --
198 nodeTypeId :: NodeType -> NodeTypeId
199 nodeTypeId tn = fromMaybe (error $ "Typename " <> show tn <> " does not exist")
200 (lookup tn nodeTypes)
201
202
203
204
205 -- Temporary types to be removed
206 type Ngrams = (Text, Text, Text)
207 type ErrorMessage = Text
208
209 -- Queries
210 type ParentId = NodeId
211 type Limit = Int
212 type Offset = Int
213
214