]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/Node_NodeNgramsNodeNgrams.hs
[WIP] backup during the vacations
[gargantext.git] / src / Gargantext / Database / Query / Table / Node_NodeNgramsNodeNgrams.hs
1 {-|
2 Module : Gargantext.Database.Schema.Node_NodeNgrams_NodeNgrams
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 lgrams: listed ngrams
11
12 Node_NodeNgrams_NodeNgrams table is used to group ngrams
13 - first NodeId :: Referential / space node (corpus)
14 - NodeNgrams where Node is List
15 - lgrams1_id, lgrams2_id where all lgrams2_id will be added to lgrams1_id
16 - weight: score the relation
17
18 Next Step benchmark:
19 - recursive queries of postgres
20 - group with: https://en.wikipedia.org/wiki/Nested_set_model
21
22 -}
23
24 {-# OPTIONS_GHC -fno-warn-orphans #-}
25
26 {-# LANGUAGE Arrows #-}
27 {-# LANGUAGE FunctionalDependencies #-}
28 {-# LANGUAGE QuasiQuotes #-}
29 {-# LANGUAGE TemplateHaskell #-}
30
31 module Gargantext.Database.Query.Table.Node_NodeNgramsNodeNgrams
32 ( module Gargantext.Database.Schema.Node_NodeNgramsNodeNgrams
33 , insert_Node_NodeNgrams_NodeNgrams
34 )
35 where
36
37 import Gargantext.Database.Schema.Prelude
38 import Gargantext.Database.Prelude (Cmd, runOpaQuery, mkCmd)
39 import Gargantext.Database.Admin.Types.Node (pgNodeId)
40 import Gargantext.Database.Schema.Node_NodeNgramsNodeNgrams
41 import Gargantext.Database.Schema.Node()
42 import Gargantext.Prelude
43
44
45 queryNode_NodeNgrams_NodeNgrams_Table :: Query Node_NodeNgrams_NodeNgrams_Read
46 queryNode_NodeNgrams_NodeNgrams_Table = selectTable node_NodeNgrams_NodeNgrams_Table
47
48 -- | Select NodeNgramsNgrams
49 -- TODO not optimized (get all ngrams without filters)
50 _node_Node_NodeNgrams_NodeNgrams :: Cmd err [Node_NodeNgrams_NodeNgrams]
51 _node_Node_NodeNgrams_NodeNgrams = runOpaQuery queryNode_NodeNgrams_NodeNgrams_Table
52
53
54 -- TODO: Add option on conflict
55 insert_Node_NodeNgrams_NodeNgrams :: [Node_NodeNgrams_NodeNgrams] -> Cmd err Int64
56 insert_Node_NodeNgrams_NodeNgrams = insert_Node_NodeNgrams_NodeNgrams_W
57 . map (\(Node_NodeNgrams_NodeNgrams n ng1 ng2 maybeWeight) ->
58 Node_NodeNgrams_NodeNgrams (pgNodeId n )
59 (sqlInt4 <$> ng1)
60 (sqlInt4 ng2)
61 (sqlDouble <$> maybeWeight)
62 )
63
64 insert_Node_NodeNgrams_NodeNgrams_W :: [Node_NodeNgrams_NodeNgrams_Write] -> Cmd err Int64
65 insert_Node_NodeNgrams_NodeNgrams_W ns =
66 mkCmd $ \c -> runInsert_ c Insert { iTable = node_NodeNgrams_NodeNgrams_Table
67 , iRows = ns
68 , iReturning = rCount
69 , iOnConflict = (Just DoNothing)
70 }