]> Git — Sourcephile - gargantext.git/blob - src/Data/Gargantext/Database/NodeNgram.hs
[CLEAN] Moving CoreNLP in Ngrams folder.
[gargantext.git] / src / Data / Gargantext / Database / NodeNgram.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.NodeNgram 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 NodeNgramPoly id node_id ngram_id weight
22 = NodeNgram { nodeNgram_NodeNgramId :: id
23 , nodeNgram_NodeNgramNodeId :: node_id
24 , nodeNgram_NodeNgramNgramId :: ngram_id
25 , nodeNgram_NodeNgramWeight :: weight
26 } deriving (Show)
27
28 type NodeNgramWrite = NodeNgramPoly (Maybe (Column PGInt4)) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
29 type NodeNgramRead = NodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) ((Column PGFloat8))
30
31
32 type NodeNgram = NodeNgramPoly (Maybe Int) Int Int (Maybe Double)
33
34 $(makeAdaptorAndInstance "pNodeNgram" ''NodeNgramPoly)
35 $(makeLensesWith abbreviatedFields ''NodeNgramPoly)
36
37
38 nodeNgramTable :: Table NodeNgramWrite NodeNgramRead
39 nodeNgramTable = Table "nodes_ngrams" (pNodeNgram NodeNgram { nodeNgram_NodeNgramId = optional "id"
40 , nodeNgram_NodeNgramNodeId = required "node_id"
41 , nodeNgram_NodeNgramNgramId = required "ngram_id"
42 , nodeNgram_NodeNgramWeight = optional "weight"
43 }
44 )
45
46
47 queryNodeNgramTable :: Query NodeNgramRead
48 queryNodeNgramTable = queryTable nodeNgramTable
49
50
51 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
52 queryRunnerColumnDefault = fieldQueryRunnerColumn
53
54 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
55 queryRunnerColumnDefault = fieldQueryRunnerColumn
56
57
58 -- | not optimized (get all ngrams without filters)
59 nodeNgrams :: IO [NodeNgram]
60 nodeNgrams = do
61 conn <- PGS.connect infoGargandb
62 runQuery conn queryNodeNgramTable