3 Module : Gargantext.Database.NodeNodeNgram
5 Copyright : (c) CNRS, 2017-Present
6 License : AGPL + CECILL v3
7 Maintainer : team@gargantext.org
8 Stability : experimental
11 Here is a longer description of this module, containing some
12 commentary with @some markup@.
15 {-# LANGUAGE NoImplicitPrelude #-}
16 {-# LANGUAGE TemplateHaskell #-}
17 {-# LANGUAGE FlexibleInstances #-}
18 {-# LANGUAGE MultiParamTypeClasses #-}
19 {-# LANGUAGE FunctionalDependencies #-}
20 {-# LANGUAGE Arrows #-}
21 {-# OPTIONS_GHC -fno-warn-orphans #-}
24 module Gargantext.Database.NodeNodeNgram where
27 import Data.Maybe (Maybe)
28 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
29 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
30 import qualified Database.PostgreSQL.Simple as PGS
35 data NodeNodeNgramPoly node1_id node2_id ngram_id score
36 = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
37 , nodeNodeNgram_node2_id :: node2_id
38 , nodeNodeNgram_ngram_id :: ngram_id
39 , nodeNodeNgram_score :: score
43 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4 )
46 (Maybe (Column PGFloat8))
48 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4 )
53 type NodeNodeNgramReadNull = NodeNodeNgramPoly (Column (Nullable PGInt4 ))
54 (Column (Nullable PGInt4 ))
55 (Column (Nullable PGInt4 ))
56 (Column (Nullable PGFloat8))
58 type NodeNodeNgram = NodeNodeNgramPoly Int
64 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
65 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
67 nodeNodeNgramTable :: Table NodeNodeNgramWrite NodeNodeNgramRead
68 nodeNodeNgramTable = Table "nodes_nodes_ngrams"
69 ( pNodeNodeNgram NodeNodeNgram
70 { nodeNodeNgram_node1_id = required "node1_id"
71 , nodeNodeNgram_node2_id = required "node2_id"
72 , nodeNodeNgram_ngram_id = required "ngram_id"
73 , nodeNodeNgram_score = optional "score"
78 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
79 queryNodeNodeNgramTable = queryTable nodeNodeNgramTable
81 -- | not optimized (get all ngrams without filters)
82 nodeNodeNgrams :: PGS.Connection -> IO [NodeNodeNgram]
83 nodeNodeNgrams conn = runQuery conn queryNodeNodeNgramTable
85 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
86 queryRunnerColumnDefault = fieldQueryRunnerColumn