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 Here is a longer description of this module, containing some
11 commentary with @some markup@.
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
15 {-# LANGUAGE Arrows #-}
16 {-# LANGUAGE FlexibleInstances #-}
17 {-# LANGUAGE FunctionalDependencies #-}
18 {-# LANGUAGE MultiParamTypeClasses #-}
19 {-# LANGUAGE NoImplicitPrelude #-}
20 {-# LANGUAGE TemplateHaskell #-}
22 module Gargantext.Database.NodeNgramNgram where
25 import Data.Maybe (Maybe)
26 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
27 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
28 import qualified Database.PostgreSQL.Simple as PGS
32 data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight
33 = NodeNgramNgram { nodeNgramNgram_NodeNgramNgram_NodeId :: node_id
34 , nodeNgramNgram_NodeNgramNgram_Ngram1Id :: ngram1_id
35 , nodeNgramNgram_NodeNgramNgram_Ngram2Id :: ngram2_id
36 , nodeNgramNgram_NodeNgramNgram_Weight :: weight
40 type NodeNgramNgramWrite = NodeNgramNgramPoly (Maybe (Column PGInt4 ))
43 (Maybe (Column PGFloat8))
45 type NodeNgramNgramRead = NodeNgramNgramPoly (Column PGInt4 )
50 type NodeNgramNgram = NodeNgramNgramPoly (Maybe Int )
55 $(makeAdaptorAndInstance "pNodeNgramNgram" ''NodeNgramNgramPoly)
56 $(makeLensesWith abbreviatedFields ''NodeNgramNgramPoly)
59 nodeNgramNgramTable :: Table NodeNgramNgramWrite NodeNgramNgramRead
60 nodeNgramNgramTable = Table "nodes_ngrams_ngrams"
61 ( pNodeNgramNgram NodeNgramNgram
62 { nodeNgramNgram_NodeNgramNgram_NodeId = optional "node_id"
63 , nodeNgramNgram_NodeNgramNgram_Ngram1Id = required "ngram1_id"
64 , nodeNgramNgram_NodeNgramNgram_Ngram2Id = required "ngram2_id"
65 , nodeNgramNgram_NodeNgramNgram_Weight = optional "weight"
69 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
70 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
72 -- | not optimized (get all ngrams without filters)
73 nodeNgramNgrams :: PGS.Connection -> IO [NodeNgramNgram]
74 nodeNgramNgrams conn = runQuery conn queryNodeNgramNgramTable
76 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
77 queryRunnerColumnDefault = fieldQueryRunnerColumn
79 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
80 queryRunnerColumnDefault = fieldQueryRunnerColumn