]> Git — Sourcephile - gargantext.git/blob - src/Data/Gargantext/Database/NodeNodeNgram.hs
First commit to start with.
[gargantext.git] / src / Data / Gargantext / Database / NodeNodeNgram.hs
1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
6
7 module Data.Gargantext.Database.NodeNodeNgram where
8
9 import Prelude
10 import Data.Time (UTCTime)
11 import Data.Text (Text)
12 import Data.Maybe (Maybe)
13 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
14 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
15 import Control.Arrow (returnA)
16 import qualified Database.PostgreSQL.Simple as PGS
17
18 import qualified Opaleye as O
19 import Opaleye (Column, PGBool, PGInt4, PGText, PGTimestamptz, PGFloat8
20 , Table(Table), Query
21 , QueryRunnerColumnDefault, queryRunnerColumnDefault
22 , fieldQueryRunnerColumn
23 , (.==), (.>)
24 )
25
26 import Data.Gargantext.Database.Private (infoGargandb)
27 import Data.Gargantext.Database.Instances
28
29 data NodeNodeNgramPoly node1_id node2_id ngram_id score
30 = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
31 , nodeNodeNgram_node2_id :: node2_id
32 , nodeNodeNgram_ngram_id :: ngram_id
33 , nodeNodeNgram_score :: score
34 } deriving (Show)
35
36
37 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
38 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Column PGFloat8)
39
40
41 type NodeNodeNgram = NodeNodeNgramPoly Int Int Int (Maybe Double)
42
43 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
44 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
45
46
47 nodeNodeNgramTable :: O.Table NodeNodeNgramWrite NodeNodeNgramRead
48 nodeNodeNgramTable = O.Table "nodes_nodes_ngrams" ( pNodeNodeNgram NodeNodeNgram
49 { nodeNodeNgram_node1_id = O.required "node1_id"
50 , nodeNodeNgram_node2_id = O.required "node2_id"
51 , nodeNodeNgram_ngram_id = O.required "ngram_id"
52 , nodeNodeNgram_score = O.optional "score"
53 }
54 )
55
56
57 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
58 queryNodeNodeNgramTable = O.queryTable nodeNodeNgramTable
59
60
61 -- | not optimized (get all ngrams without filters)
62 nodeNodeNgrams :: IO [NodeNodeNgram]
63 nodeNodeNgrams = do
64 conn <- PGS.connect infoGargandb
65 O.runQuery conn queryNodeNodeNgramTable
66