2 Module : Gargantext.Database.Schema.Node_NodeNgrams_NodeNgrams
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
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
19 - recursive queries of postgres
20 - group with: https://en.wikipedia.org/wiki/Nested_set_model
24 {-# LANGUAGE Arrows #-}
25 {-# LANGUAGE FlexibleInstances #-}
26 {-# LANGUAGE FunctionalDependencies #-}
27 {-# LANGUAGE MultiParamTypeClasses #-}
28 {-# LANGUAGE NoImplicitPrelude #-}
29 {-# LANGUAGE OverloadedStrings #-}
30 {-# LANGUAGE QuasiQuotes #-}
31 {-# LANGUAGE RankNTypes #-}
32 {-# LANGUAGE TemplateHaskell #-}
33 {-# OPTIONS_GHC -fno-warn-orphans #-}
35 module Gargantext.Database.Schema.Node_NodeNgramsNodeNgrams
38 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
39 import Data.Maybe (Maybe)
40 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
41 import Gargantext.Database.Utils (Cmd, runOpaQuery, mkCmd)
42 import Gargantext.Database.Types.Node (CorpusId)
43 import Gargantext.Database.Schema.Node (pgNodeId)
44 import Gargantext.Prelude
47 data Node_NodeNgrams_NodeNgrams_Poly node_id nng1_id nng2_id weight =
48 Node_NodeNgrams_NodeNgrams { _nnn_node_id :: node_id
49 , _nnn_nng1_id :: nng1_id
50 , _nnn_nng2_id :: nng2_id
51 , _nnn_weight :: weight
54 type Node_NodeNgrams_NodeNgrams_Write =
55 Node_NodeNgrams_NodeNgrams_Poly
59 (Maybe (Column PGFloat8))
61 type Node_NodeNgrams_NodeNgrams_Read =
62 Node_NodeNgrams_NodeNgrams_Poly
68 type ListNgramsId = Int
70 type Node_NodeNgrams_NodeNgrams =
71 Node_NodeNgrams_NodeNgrams_Poly CorpusId ListNgramsId ListNgramsId (Maybe Double)
73 $(makeAdaptorAndInstance "pNode_NodeNgrams_NodeNgrams"
74 ''Node_NodeNgrams_NodeNgrams_Poly)
75 $(makeLensesWith abbreviatedFields
76 ''Node_NodeNgrams_NodeNgrams_Poly)
79 node_NodeNgrams_NodeNgrams_Table :: Table Node_NodeNgrams_NodeNgrams_Write Node_NodeNgrams_NodeNgrams_Read
80 node_NodeNgrams_NodeNgrams_Table =
81 Table "nodes_nodengrams_nodengrams"
82 ( pNode_NodeNgrams_NodeNgrams Node_NodeNgrams_NodeNgrams
83 { _nnn_node_id = required "node_id"
84 , _nnn_nng1_id = required "nng1_id"
85 , _nnn_nng2_id = required "nng2_id"
86 , _nnn_weight = optional "weight"
90 queryNode_NodeNgrams_NodeNgrams_Table :: Query Node_NodeNgrams_NodeNgrams_Read
91 queryNode_NodeNgrams_NodeNgrams_Table = queryTable node_NodeNgrams_NodeNgrams_Table
93 -- | Select NodeNgramsNgrams
94 -- TODO not optimized (get all ngrams without filters)
95 node_Node_NodeNgrams_NodeNgrams :: Cmd err [Node_NodeNgrams_NodeNgrams]
96 node_Node_NodeNgrams_NodeNgrams = runOpaQuery queryNode_NodeNgrams_NodeNgrams_Table
98 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
99 queryRunnerColumnDefault = fieldQueryRunnerColumn
101 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
102 queryRunnerColumnDefault = fieldQueryRunnerColumn
105 -- TODO: Add option on conflict
106 insert_Node_NodeNgrams_NodeNgrams :: [Node_NodeNgrams_NodeNgrams] -> Cmd err Int64
107 insert_Node_NodeNgrams_NodeNgrams = insert_Node_NodeNgrams_NodeNgrams_W
108 . map (\(Node_NodeNgrams_NodeNgrams n ng1 ng2 maybeWeight) ->
109 Node_NodeNgrams_NodeNgrams (pgNodeId n )
112 (pgDouble <$> maybeWeight)
115 insert_Node_NodeNgrams_NodeNgrams_W :: [Node_NodeNgrams_NodeNgrams_Write] -> Cmd err Int64
116 insert_Node_NodeNgrams_NodeNgrams_W ns =
117 mkCmd $ \c -> runInsert_ c Insert { iTable = node_NodeNgrams_NodeNgrams_Table
119 , iReturning = rCount
120 , iOnConflict = (Just DoNothing)