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