1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
module Gargantext.Components.Search where
import Gargantext.Prelude
import Data.Eq.Generic (genericEq)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype)
import Data.Show.Generic (genericShow)
import Gargantext.Utils.SimpleJSON as GUSJ
import Simple.JSON as JSON
import Simple.JSON.Generics as JSONG
-- Example:
-- [["machine","learning"],["artificial","intelligence"]]
-- This searches for documents with "machine learning" or "artificial intelligence"
type TextQuery = Array (Array String)
------------------------------------------------------------------------
data SearchType = SearchDoc | SearchContact
derive instance Generic SearchType _
instance Eq SearchType where eq = genericEq
instance Show SearchType where show = genericShow
instance JSON.ReadForeign SearchType where readImpl = JSONG.enumSumRep
instance JSON.WriteForeign SearchType where writeImpl = JSON.writeImpl <<< show
------------------------------------------------------------------------
newtype SearchQuery = SearchQuery
{ query :: Array String
, expected :: SearchType
}
derive instance Generic SearchQuery _
derive instance Newtype SearchQuery _
instance Eq SearchQuery where eq = genericEq
instance Show SearchQuery where show = genericShow
derive newtype instance JSON.ReadForeign SearchQuery
derive newtype instance JSON.WriteForeign SearchQuery
------------------------------------------------------------------------
------------------------------------------------------------------------
newtype SearchResult = SearchResult { result :: SearchResultTypes }
derive instance Generic SearchResult _
derive instance Newtype SearchResult _
instance Eq SearchResult where eq = genericEq
instance Show SearchResult where show = genericShow
derive newtype instance JSON.ReadForeign SearchResult
derive newtype instance JSON.WriteForeign SearchResult
------------------------------------------------------------------------
data SearchResultTypes = SearchResultDoc { docs :: Array Document }
| SearchNoResult { message :: String }
| SearchResultContact { contacts :: Array Contact }
derive instance Generic SearchResultTypes _
instance Eq SearchResultTypes where eq = genericEq
instance Show SearchResultTypes where show = genericShow
instance JSON.ReadForeign SearchResultTypes where readImpl = GUSJ.taggedSumRep
instance JSON.WriteForeign SearchResultTypes where
writeImpl (SearchResultDoc s) = JSON.writeImpl s
writeImpl (SearchNoResult s) = JSON.writeImpl s
writeImpl (SearchResultContact s) = JSON.writeImpl s
------------------------------------------------------------------------
newtype Document =
Document { id :: Int
, created :: String
, title :: String
, hyperdata :: HyperdataRowDocument
, category :: Int
, score :: Int
}
derive instance Generic Document _
derive instance Newtype Document _
instance Eq Document where eq = genericEq
instance Show Document where show = genericShow
derive newtype instance JSON.ReadForeign Document
derive newtype instance JSON.WriteForeign Document
------------------------------------------------------------------------
newtype HyperdataRowDocument =
HyperdataRowDocument { abstract :: Maybe String
, authors :: Maybe String
, bdd :: Maybe String
, doi :: Maybe String
, institutes :: Maybe String
, language_iso2 :: Maybe String
, page :: Maybe Int
, publication_date :: Maybe String
, publication_day :: Maybe Int
, publication_hour :: Maybe Int
, publication_minute :: Maybe Int
, publication_month :: Maybe Int
, publication_second :: Maybe Int
, publication_year :: Maybe Int
, source :: Maybe String
, title :: Maybe String
, url :: Maybe String
, uniqId :: Maybe String
, uniqIdBdd :: Maybe String
}
derive instance Generic HyperdataRowDocument _
instance Eq HyperdataRowDocument where eq = genericEq
instance Show HyperdataRowDocument where show = genericShow
derive newtype instance JSON.ReadForeign HyperdataRowDocument
derive newtype instance JSON.WriteForeign HyperdataRowDocument
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
newtype Contact =
Contact { c_id :: Int
, c_created :: String
, c_hyperdata :: HyperdataRowContact
, c_score :: Int
, c_annuaireId :: Int
}
derive instance Generic Contact _
instance Eq Contact where eq = genericEq
instance Show Contact where show = genericShow
derive newtype instance JSON.ReadForeign Contact
derive newtype instance JSON.WriteForeign Contact
newtype HyperdataRowContact =
HyperdataRowContact { firstname :: String
, lastname :: String
, labs :: String
}
derive instance Generic HyperdataRowContact _
instance Eq HyperdataRowContact where eq = genericEq
instance Show HyperdataRowContact where show = genericShow
derive newtype instance JSON.ReadForeign HyperdataRowContact
derive newtype instance JSON.WriteForeign HyperdataRowContact
newtype HyperdataContact =
HyperdataContact { bdd :: Maybe String
, who :: Maybe ContactWho
, "where" :: Array ContactWhere
, title :: Maybe String
, source :: Maybe String
, lastValidation :: Maybe String
, uniqIdBdd :: Maybe String
, uniqId :: Maybe String
}
derive instance Generic HyperdataContact _
instance Eq HyperdataContact where eq = genericEq
instance Show HyperdataContact where show = genericShow
derive newtype instance JSON.ReadForeign HyperdataContact
derive newtype instance JSON.WriteForeign HyperdataContact
-------
newtype ContactWho =
ContactWho { id :: Maybe String
, firstName :: Maybe String
, lastName :: Maybe String
, keywords :: Array String
, freetags :: Array String
}
derive instance Generic ContactWho _
instance Eq ContactWho where eq = genericEq
instance Show ContactWho where show = genericShow
derive newtype instance JSON.ReadForeign ContactWho
derive newtype instance JSON.WriteForeign ContactWho
newtype ContactWhere =
ContactWhere { organization :: Array String
, labTeamDepts :: Array String
, role :: Maybe String
, office :: Maybe String
, country :: Maybe String
, city :: Maybe String
, touch :: Maybe ContactTouch
, entry :: Maybe String
, exit :: Maybe String
}
derive instance Generic ContactWhere _
instance Eq ContactWhere where eq = genericEq
instance Show ContactWhere where show = genericShow
derive newtype instance JSON.ReadForeign ContactWhere
derive newtype instance JSON.WriteForeign ContactWhere
newtype ContactTouch =
ContactTouch { mail :: Maybe String
, phone :: Maybe String
, url :: Maybe String
}
derive instance Generic ContactTouch _
instance Eq ContactTouch where eq = genericEq
instance Show ContactTouch where show = genericShow
derive newtype instance JSON.ReadForeign ContactTouch
derive newtype instance JSON.WriteForeign ContactTouch