2 Module : Gargantext.Database.NodeNgramNgram
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 NodeNgramNgram table is used to group Ngrams
13 - group with: https://en.wikipedia.org/wiki/Nested_set_model
18 {-# OPTIONS_GHC -fno-warn-orphans #-}
19 {-# LANGUAGE Arrows #-}
20 {-# LANGUAGE FlexibleInstances #-}
21 {-# LANGUAGE FunctionalDependencies #-}
22 {-# LANGUAGE MultiParamTypeClasses #-}
23 {-# LANGUAGE NoImplicitPrelude #-}
24 {-# LANGUAGE TemplateHaskell #-}
26 module Gargantext.Database.NodeNgramNgram where
28 import Gargantext.Prelude
29 import Data.Maybe (Maybe)
30 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
31 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
32 import qualified Database.PostgreSQL.Simple as PGS
36 data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight =
37 NodeNgramNgram { nng_NodeId :: node_id
38 , nng_Ngram1Id :: ngram1_id
39 , nng_Ngram2Id :: ngram2_id
40 , nng_Weight :: weight
44 type NodeNgramNgramWrite =
45 NodeNgramNgramPoly (Maybe (Column PGInt4 ))
48 (Maybe (Column PGFloat8))
50 type NodeNgramNgramRead =
51 NodeNgramNgramPoly (Column PGInt4 )
57 NodeNgramNgramPoly (Maybe Int )
62 $(makeAdaptorAndInstance "pNodeNgramNgram"
64 $(makeLensesWith abbreviatedFields
68 nodeNgramNgramTable :: Table NodeNgramNgramWrite NodeNgramNgramRead
70 Table "nodes_ngrams_ngrams"
71 ( pNodeNgramNgram NodeNgramNgram
72 { nng_NodeId = optional "node_id"
73 , nng_Ngram1Id = required "ngram1_id"
74 , nng_Ngram2Id = required "ngram2_id"
75 , nng_Weight = optional "weight"
79 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
80 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
82 -- | not optimized (get all ngrams without filters)
83 nodeNgramNgrams :: PGS.Connection -> IO [NodeNgramNgram]
84 nodeNgramNgrams conn = runQuery conn queryNodeNgramNgramTable
86 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
87 queryRunnerColumnDefault = fieldQueryRunnerColumn
89 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
90 queryRunnerColumnDefault = fieldQueryRunnerColumn