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
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
13 {-# LANGUAGE FlexibleInstances #-}
14 {-# LANGUAGE DeriveGeneric #-}
16 module Gargantext.Types.Main where
21 import Data.Monoid ((<>))
22 import Protolude (fromMaybe)
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
43 -- | Language of a Text
44 -- For simplicity, we suppose text has an homogenous language
45 data Language = EN | FR -- | DE | IT | SP
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 (:
54 -- All the Database is structred like a hierarchical Tree
55 data Tree a = NodeT a [Tree a]
56 deriving (Show, Read, Eq)
59 -- data Tree a = NodeT a [Tree a]
64 -- Garg Network is a network of all Garg nodes
65 --gargNetwork = undefined
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]
72 -- | User Tree simplified
73 userTree :: Tree NodeType
74 userTree = NodeT NodeUser [projectTree]
77 projectTree :: Tree NodeType
78 projectTree = NodeT Project [corpusTree]
81 corpusTree :: Tree NodeType
82 corpusTree = NodeT Corpus ( [ leafT Document ]
85 <> [ leafT Classification]
88 -- TODO make instances of Nodes
90 -- * why NodeUser and not just User ?
91 -- * is this supposed to hold data ?
92 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
96 deriving (Show, Read, Eq, Generic)
98 instance FromJSON NodeType
99 instance ToJSON NodeType
100 instance FromHttpApiData NodeType where parseUrlPiece = Right . read . unpack
102 data Classification = Favorites | MyClassifcation
104 data Lists = StopList | MainList | MapList | GroupList
106 data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
107 | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
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
116 type NodeParentId = Int
117 type NodeUserId = Int
119 --type NodeVector = Vector
121 --type NodeUser = Node HyperdataUser
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
130 -- | Community Manager Use Case
131 type Annuaire = Corpus
132 type Individu = Document
134 -- | Favorites Node enable Node categorization
135 type Favorites = Node HyperdataFavorites
137 -- | Favorites Node enable Swap Node with some synonyms for clarity
138 type NodeSwap = Node HyperdataResource
140 -- | Then a Node can be a List which has some synonyms
141 type List = Node HyperdataList
145 type GroupList = List
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
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
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
167 nodeTypes :: [(NodeType, NodeTypeId)]
168 nodeTypes = [ (NodeUser , 1)
179 -- , (Occurrences , 10)
180 -- , (Cooccurrences , 9)
182 -- , (Specclusion , 11)
183 -- , (Genclusion , 18)
186 -- , (TfidfCorpus , 13)
187 -- , (TfidfGlobal , 14)
189 -- , (TirankLocal , 16)
190 -- , (TirankGlobal , 17)
193 -- , (Favorites , 15)
197 nodeTypeId :: NodeType -> NodeTypeId
198 nodeTypeId tn = fromMaybe (error $ "Typename " <> show tn <> " does not exist")
199 (lookup tn nodeTypes)
203 -- Temporary types to be removed
204 type Ngrams = (Text, Text, Text)
205 type ErrorMessage = Text