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 {-# OPTIONS_GHC -fno-warn-orphans #-}
26 {-# LANGUAGE Arrows #-}
27 {-# LANGUAGE FunctionalDependencies #-}
28 {-# LANGUAGE QuasiQuotes #-}
29 {-# LANGUAGE TemplateHaskell #-}
31 module Gargantext.Database.Query.Table.Node_NodeNgramsNodeNgrams
32 ( module Gargantext.Database.Schema.Node_NodeNgramsNodeNgrams
33 , insert_Node_NodeNgrams_NodeNgrams
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
45 queryNode_NodeNgrams_NodeNgrams_Table :: Query Node_NodeNgrams_NodeNgrams_Read
46 queryNode_NodeNgrams_NodeNgrams_Table = selectTable node_NodeNgrams_NodeNgrams_Table
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
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 )
61 (pgDouble <$> maybeWeight)
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
69 , iOnConflict = (Just DoNothing)