2 Module : Gargantext.Types.Nodes
3 Description : Main Types of Nodes
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE DeriveGeneric #-}
13 {-# LANGUAGE TemplateHaskell #-}
14 {-# LANGUAGE OverloadedStrings #-}
15 {-# LANGUAGE FlexibleInstances #-}
17 -- {-# LANGUAGE DuplicateRecordFields #-}
19 module Gargantext.Types.Node where
21 import Gargantext.Prelude
23 import Text.Show (Show())
24 import Data.Text (Text, unpack)
25 import Text.Read (read)
26 import GHC.Generics (Generic)
28 import Data.Time (UTCTime)
29 import Gargantext.Utils.Prefix (unPrefix)
30 import Data.Aeson.TH (deriveJSON)
35 import Test.QuickCheck.Arbitrary
36 import Test.QuickCheck (elements)
39 import Data.Time.Segment (jour)
40 import Data.Aeson (Value(),toJSON)
43 ------------------------------------------------------------------------
44 data Status = Status { status_Date :: Maybe UTCTime
45 , status_Error :: Maybe Text
46 , status_Action :: Maybe Text
47 , status_Complete :: Maybe Bool
48 , status_Progress :: Maybe Int
49 } deriving (Show, Generic)
50 $(deriveJSON (unPrefix "status_") ''Status)
52 instance Arbitrary Status where
53 arbitrary = elements [Status Nothing Nothing Nothing Nothing Nothing]
56 ------------------------------------------------------------------------
57 data HyperdataDocument = HyperdataDocument { hyperdataDocument_Bdd :: Maybe Text
58 , hyperdataDocument_Doi :: Maybe Text
59 , hyperdataDocument_Url :: Maybe Text
60 , hyperdataDocument_Page :: Maybe Int
61 , hyperdataDocument_Title :: Maybe Text
62 , hyperdataDocument_Authors :: Maybe Text
63 , hyperdataDocument_Abstract :: Maybe Text
64 , hyperdataDocument_Statuses :: Maybe [Status]
65 , hyperdataDocument_Publication_date :: Maybe Text
66 , hyperdataDocument_Publication_year :: Maybe Double
67 , hyperdataDocument_Publication_month :: Maybe Double
68 , hyperdataDocument_Publication_hour :: Maybe Double
69 , hyperdataDocument_Publication_minute :: Maybe Double
70 , hyperdataDocument_Publication_second :: Maybe Double
71 , hyperdataDocument_LanguageIso2 :: Maybe Text
72 } deriving (Show, Generic)
73 $(deriveJSON (unPrefix "hyperdataDocument_") ''HyperdataDocument)
75 hyperdataDocuments :: [HyperdataDocument]
76 hyperdataDocuments = [HyperdataDocument Nothing Nothing Nothing Nothing (Just "Title")
77 Nothing (Just "Abstract") Nothing Nothing
78 Nothing Nothing Nothing Nothing Nothing Nothing
82 instance Arbitrary HyperdataDocument where
83 arbitrary = elements hyperdataDocuments
85 ------------------------------------------------------------------------
86 data LanguageNodes = LanguageNodes { languageNodes___unknown__ :: [Int]}
87 deriving (Show, Generic)
88 $(deriveJSON (unPrefix "languageNodes_") ''LanguageNodes)
91 ------------------------------------------------------------------------
93 data Resource = Resource { resource_Url :: Maybe Text
94 , resource_Path :: Maybe Text
95 , resource_Type :: Maybe Int
96 , resource_Extracted :: Maybe Bool
97 } deriving (Show, Generic)
98 $(deriveJSON (unPrefix "resource_") ''Resource)
100 instance Arbitrary Resource where
101 arbitrary = elements [Resource Nothing Nothing Nothing Nothing]
103 data HyperdataCorpus = HyperdataCorpus { hyperdataCorpus_Action :: Maybe Text
104 , hyperdataCorpus_Statuses :: Maybe [Status]
105 , hyperdataCorpus_Languages :: Maybe LanguageNodes
106 , hyperdataCorpus_Resources :: Maybe [Resource]
107 , hyperdataCorpus_Language_id :: Maybe Text
108 , hyperdataCorpus_Skipped_docs :: Maybe [Int]
109 } deriving (Show, Generic)
110 $(deriveJSON (unPrefix "hyperdataCorpus_") ''HyperdataCorpus)
113 data HyperdataUser = HyperdataUser { hyperdataUser_language :: Maybe Text
114 } deriving (Show, Generic)
115 $(deriveJSON (unPrefix "hyperdataUser_") ''HyperdataUser)
119 data HyperdataFolder = HyperdataFolder { hyperdataFolder_Preferences :: Maybe Text
120 } deriving (Show, Generic)
121 $(deriveJSON (unPrefix "hyperdataFolder_") ''HyperdataFolder)
124 data HyperdataProject = HyperdataProject { hyperdataProject_Preferences :: Maybe Text
125 } deriving (Show, Generic)
126 $(deriveJSON (unPrefix "hyperdataProject_") ''HyperdataProject)
130 data HyperdataList = HyperdataList { hyperdataList_Preferences :: Maybe Text
131 } deriving (Show, Generic)
132 $(deriveJSON (unPrefix "hyperdataList_") ''HyperdataList)
134 data HyperdataScore = HyperdataScore { hyperdataScore_Preferences :: Maybe Text
135 } deriving (Show, Generic)
136 $(deriveJSON (unPrefix "hyperdataScore_") ''HyperdataScore)
140 data HyperdataFavorites = HyperdataFavorites { hyperdataFavorites_Preferences :: Maybe Text
141 } deriving (Show, Generic)
142 $(deriveJSON (unPrefix "hyperdataFavorites_") ''HyperdataFavorites)
144 data HyperdataResource = HyperdataResource { hyperdataResource_Preferences :: Maybe Text
145 } deriving (Show, Generic)
146 $(deriveJSON (unPrefix "hyperdataResource_") ''HyperdataResource)
150 -- TODO add the Graph Structure here
151 data HyperdataGraph = HyperdataGraph { hyperdataGraph_Preferences :: Maybe Text
152 } deriving (Show, Generic)
153 $(deriveJSON (unPrefix "hyperdataGraph_") ''HyperdataGraph)
156 -- TODO add the Graph Structure here
157 data HyperdataPhylo = HyperdataPhylo { hyperdataPhylo_Preferences :: Maybe Text
158 } deriving (Show, Generic)
159 $(deriveJSON (unPrefix "hyperdataPhylo_") ''HyperdataPhylo)
161 -- | TODO FEATURE: Notebook saved in the node (to work with Python or Haskell)
162 data HyperdataNotebook = HyperdataNotebook { hyperdataNotebook_Preferences :: Maybe Text
163 } deriving (Show, Generic)
164 $(deriveJSON (unPrefix "hyperdataNotebook_") ''HyperdataNotebook)
168 -- | NodePoly indicates that Node has a Polymorphism Type
169 type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector
171 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
172 type NodeTypeId = Int
174 type NodeParentId = Int
175 type NodeUserId = Int
177 --type NodeVector = Vector
179 --type NodeUser = Node HyperdataUser
181 -- | Then a Node can be either a Folder or a Corpus or a Document
182 type NodeUser = Node HyperdataUser
183 type Folder = Node HyperdataFolder
184 type Project = Folder -- NP Node HyperdataProject ?
185 type Corpus = Node HyperdataCorpus
186 type Document = Node HyperdataDocument
188 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
191 | Metrics | Occurrences
192 deriving (Show, Read, Eq, Generic)
194 instance FromJSON NodeType
195 instance ToJSON NodeType
196 instance FromHttpApiData NodeType where parseUrlPiece = Right . read . unpack
199 ------------------------------------------------------------------------
200 data NodePoly id typename userId parentId name date hyperdata = Node { node_id :: id
201 , node_typename :: typename
202 , node_userId :: userId
203 -- , nodeHashId :: hashId
204 , node_parentId :: parentId
207 , node_hyperdata :: hyperdata
208 -- , node_titleAbstract :: titleAbstract
210 $(deriveJSON (unPrefix "node_") ''NodePoly)
212 instance Arbitrary (NodePoly NodeId NodeTypeId (Maybe NodeUserId) NodeParentId NodeName UTCTime Value) where
213 arbitrary = elements [Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (toJSON ("{}"::Text))]
216 instance Arbitrary (NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime Value) where
217 arbitrary = elements [Node 1 1 1 (Just 1) "name" (jour 2018 01 01) (toJSON ("{}"::Text))]