2 Module : Gargantext.Database.NodeNgram
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 {-# LANGUAGE Arrows #-}
17 {-# LANGUAGE FlexibleInstances #-}
18 {-# LANGUAGE FunctionalDependencies #-}
19 {-# LANGUAGE MultiParamTypeClasses #-}
20 {-# LANGUAGE NoImplicitPrelude #-}
21 {-# LANGUAGE TemplateHaskell #-}
24 module Gargantext.Database.NodeNgram where
26 import Gargantext.Prelude
27 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
28 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
29 import Gargantext.Database.Node (mkCmd, Cmd(..))
32 data NodeNgramPoly id node_id ngram_id weight ngrams_type
33 = NodeNgram { nodeNgram_NodeNgramId :: id
34 , nodeNgram_NodeNgramNodeId :: node_id
35 , nodeNgram_NodeNgramNgramId :: ngram_id
36 , nodeNgram_NodeNgramWeight :: weight
37 , nodeNgram_NodeNgramType :: ngrams_type
40 type NodeNgramWrite = NodeNgramPoly (Maybe (Column PGInt4 ))
46 type NodeNgramRead = NodeNgramPoly (Column PGInt4 )
52 type NodeNgram = NodeNgramPoly (Maybe Int) Int Int Double Int
54 $(makeAdaptorAndInstance "pNodeNgram" ''NodeNgramPoly)
55 $(makeLensesWith abbreviatedFields ''NodeNgramPoly)
58 nodeNgramTable :: Table NodeNgramWrite NodeNgramRead
59 nodeNgramTable = Table "nodes_ngrams" ( pNodeNgram NodeNgram
60 { nodeNgram_NodeNgramId = optional "id"
61 , nodeNgram_NodeNgramNodeId = required "node_id"
62 , nodeNgram_NodeNgramNgramId = required "ngram_id"
63 , nodeNgram_NodeNgramWeight = required "weight"
64 , nodeNgram_NodeNgramType = required "ngrams_type"
68 queryNodeNgramTable :: Query NodeNgramRead
69 queryNodeNgramTable = queryTable nodeNgramTable
71 insertNodeNgrams :: [NodeNgram] -> Cmd Int
72 insertNodeNgrams = insertNodeNgramW
73 . map (\(NodeNgram _ n g w t) ->
74 NodeNgram Nothing (pgInt4 n) (pgInt4 g)
75 (pgDouble w) (pgInt4 t)
78 insertNodeNgramW :: [NodeNgramWrite] -> Cmd Int
79 insertNodeNgramW nns = mkCmd $ \c -> fromIntegral <$> runInsertMany c nodeNgramTable nns