]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNgramNgram.hs
Add comments
[gargantext.git] / src / Gargantext / Database / NodeNgramNgram.hs
1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
6 {-# OPTIONS_GHC -fno-warn-orphans #-}
7
8 module Gargantext.Database.NodeNgramNgram where
9
10 import Prelude
11 import Data.Maybe (Maybe)
12 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
13 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
14 import qualified Database.PostgreSQL.Simple as PGS
15
16 import Opaleye
17
18 import Gargantext.Database.Private (infoGargandb)
19
20 data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight
21 = NodeNgramNgram { nodeNgramNgram_NodeNgramNgram_NodeId :: node_id
22 , nodeNgramNgram_NodeNgramNgram_Ngram1Id :: ngram1_id
23 , nodeNgramNgram_NodeNgramNgram_Ngram2Id :: ngram2_id
24 , nodeNgramNgram_NodeNgramNgram_Weight :: weight
25 } deriving (Show)
26
27
28 type NodeNgramNgramWrite = NodeNgramNgramPoly (Maybe (Column PGInt4)) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
29 type NodeNgramNgramRead = NodeNgramNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Column PGFloat8)
30
31
32 type NodeNgramNgram = NodeNgramNgramPoly (Maybe Int) Int Int (Maybe Double)
33
34 $(makeAdaptorAndInstance "pNodeNgramNgram" ''NodeNgramNgramPoly)
35 $(makeLensesWith abbreviatedFields ''NodeNgramNgramPoly)
36
37
38 nodeNgramNgramTable :: Table NodeNgramNgramWrite NodeNgramNgramRead
39 nodeNgramNgramTable = Table "nodes_ngrams_ngrams" ( pNodeNgramNgram NodeNgramNgram
40 { nodeNgramNgram_NodeNgramNgram_NodeId = optional "node_id"
41 , nodeNgramNgram_NodeNgramNgram_Ngram1Id = required "ngram1_id"
42 , nodeNgramNgram_NodeNgramNgram_Ngram2Id = required "ngram2_id"
43 , nodeNgramNgram_NodeNgramNgram_Weight = optional "weight"
44 }
45 )
46
47
48 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
49 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
50
51
52 -- | not optimized (get all ngrams without filters)
53 nodeNgramNgrams :: IO [NodeNgramNgram]
54 nodeNgramNgrams = do
55 conn <- PGS.connect infoGargandb
56 runQuery conn queryNodeNgramNgramTable
57
58 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
59 queryRunnerColumnDefault = fieldQueryRunnerColumn
60
61 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
62 queryRunnerColumnDefault = fieldQueryRunnerColumn