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