]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Types/Main.hs
[REST] Document View route.
[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
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 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
114 type NodeTypeId = Int
115 type NodeId = Int
116 type NodeParentId = Int
117 type NodeUserId = Int
118 type NodeName = Text
119 --type NodeVector = Vector
120
121 --type NodeUser = Node HyperdataUser
122
123 -- | Then a Node can be either a Folder or a Corpus or a Document
124 type NodeUser = Node HyperdataUser
125 type Folder = Node HyperdataFolder
126 type Project = Folder -- NP Node HyperdataProject ?
127 type Corpus = Node HyperdataCorpus
128 type Document = Node HyperdataDocument
129
130 -- | Community Manager Use Case
131 type Annuaire = Corpus
132 type Individu = Document
133
134 -- | Favorites Node enable Node categorization
135 type Favorites = Node HyperdataFavorites
136
137 -- | Favorites Node enable Swap Node with some synonyms for clarity
138 type NodeSwap = Node HyperdataResource
139
140 -- | Then a Node can be a List which has some synonyms
141 type List = Node HyperdataList
142 type StopList = List
143 type MainList = List
144 type MapList = List
145 type GroupList = List
146
147 -- | Then a Node can be a Score which has some synonyms
148 type Score = Node HyperdataScore
149 type Occurrences = Score
150 type Cooccurrences = Score
151 type Specclusion = Score
152 type Genclusion = Score
153 type Cvalue = Score
154 type Tficf = Score
155 ---- TODO All these Tfidf* will be replaced with TFICF
156 type TfidfCorpus = Tficf
157 type TfidfGlobal = Tficf
158 type TirankLocal = Tficf
159 type TirankGlobal = Tficf
160 --
161 ---- | Then a Node can be either a Graph or a Phylo or a Notebook
162 type Graph = Node HyperdataGraph
163 type Phylo = Node HyperdataPhylo
164 type Notebook = Node HyperdataNotebook
165
166
167 nodeTypes :: [(NodeType, NodeTypeId)]
168 nodeTypes = [ (NodeUser , 1)
169 , (Project , 2)
170 , (Corpus , 3)
171 , (Document , 4)
172 --, (NodeSwap , 19)
173 ------ Lists
174 -- , (StopList , 5)
175 -- , (GroupList , 6)
176 -- , (MainList , 7)
177 -- , (MapList ,  8)
178 ---- Scores
179 -- , (Occurrences , 10)
180 -- , (Cooccurrences , 9)
181 --
182 -- , (Specclusion , 11)
183 -- , (Genclusion , 18)
184 -- , (Cvalue , 12)
185 --
186 -- , (TfidfCorpus , 13)
187 -- , (TfidfGlobal , 14)
188 --
189 -- , (TirankLocal , 16)
190 -- , (TirankGlobal , 17)
191 --
192 ---- Node management
193 -- , (Favorites , 15)
194 --
195 ]
196 --
197 nodeTypeId :: NodeType -> NodeTypeId
198 nodeTypeId tn = fromMaybe (error $ "Typename " <> show tn <> " does not exist")
199 (lookup tn nodeTypes)
200
201
202
203 -- Temporary types to be removed
204 type Ngrams = (Text, Text, Text)
205 type ErrorMessage = Text
206
207
208
209