2 Module : Gargantext.Database.NodeNgram
3 Description : NodeNgram for Ngram indexation or Lists
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 NodeNgram: relation between a Node and a Ngrams
12 if Node is a Document then it is indexing
13 if Node is a List then it is listing (either Stop, Candidate or Map)
17 {-# OPTIONS_GHC -fno-warn-orphans #-}
19 {-# LANGUAGE Arrows #-}
20 {-# LANGUAGE FlexibleInstances #-}
21 {-# LANGUAGE FunctionalDependencies #-}
22 {-# LANGUAGE MultiParamTypeClasses #-}
23 {-# LANGUAGE NoImplicitPrelude #-}
24 {-# LANGUAGE TemplateHaskell #-}
27 module Gargantext.Database.NodeNgram where
29 import Gargantext.Prelude
30 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
31 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
32 import Gargantext.Database.Node (mkCmd, Cmd(..))
36 data NodeNgramPoly id node_id ngram_id weight ngrams_type
37 = NodeNgram { nodeNgram_NodeNgramId :: id
38 , nodeNgram_NodeNgramNodeId :: node_id
39 , nodeNgram_NodeNgramNgramId :: ngram_id
40 , nodeNgram_NodeNgramWeight :: weight
41 , nodeNgram_NodeNgramType :: ngrams_type
46 (Maybe (Column PGInt4 ))
61 NodeNgramPoly (Maybe Int) Int Int Double Int
63 $(makeAdaptorAndInstance "pNodeNgram" ''NodeNgramPoly)
64 $(makeLensesWith abbreviatedFields ''NodeNgramPoly)
67 nodeNgramTable :: Table NodeNgramWrite NodeNgramRead
68 nodeNgramTable = Table "nodes_ngrams"
69 ( pNodeNgram NodeNgram
70 { nodeNgram_NodeNgramId = optional "id"
71 , nodeNgram_NodeNgramNodeId = required "node_id"
72 , nodeNgram_NodeNgramNgramId = required "ngram_id"
73 , nodeNgram_NodeNgramWeight = required "weight"
74 , nodeNgram_NodeNgramType = required "ngrams_type"
78 queryNodeNgramTable :: Query NodeNgramRead
79 queryNodeNgramTable = queryTable nodeNgramTable
81 insertNodeNgrams :: [NodeNgram] -> Cmd Int
82 insertNodeNgrams = insertNodeNgramW
83 . map (\(NodeNgram _ n g w t) ->
84 NodeNgram Nothing (pgInt4 n) (pgInt4 g)
85 (pgDouble w) (pgInt4 t)
88 insertNodeNgramW :: [NodeNgramWrite] -> Cmd Int
89 insertNodeNgramW nns =
90 mkCmd $ \c -> fromIntegral
91 <$> runInsertMany c nodeNgramTable nns