]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNodeNgram.hs
[TEXT-MINING] adding first functions/datatypes.
[gargantext.git] / src / 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 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
20 data NodeNodeNgramPoly node1_id node2_id ngram_id score
21 = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
22 , nodeNodeNgram_node2_id :: node2_id
23 , nodeNodeNgram_ngram_id :: ngram_id
24 , nodeNodeNgram_score :: score
25 } deriving (Show)
26
27
28 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4 )
29 (Column PGInt4 )
30 (Column PGInt4 )
31 (Maybe (Column PGFloat8))
32
33 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4 )
34 (Column PGInt4 )
35 (Column PGInt4 )
36 (Column PGFloat8)
37
38 type NodeNodeNgramReadNull = NodeNodeNgramPoly (Column (Nullable PGInt4 ))
39 (Column (Nullable PGInt4 ))
40 (Column (Nullable PGInt4 ))
41 (Column (Nullable PGFloat8))
42
43 type NodeNodeNgram = NodeNodeNgramPoly Int
44 Int
45 Int
46 (Maybe Double)
47
48
49 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
50 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
51
52 nodeNodeNgramTable :: Table NodeNodeNgramWrite NodeNodeNgramRead
53 nodeNodeNgramTable = Table "nodes_nodes_ngrams"
54 ( pNodeNodeNgram NodeNodeNgram
55 { nodeNodeNgram_node1_id = required "node1_id"
56 , nodeNodeNgram_node2_id = required "node2_id"
57 , nodeNodeNgram_ngram_id = required "ngram_id"
58 , nodeNodeNgram_score = optional "score"
59 }
60 )
61
62
63 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
64 queryNodeNodeNgramTable = queryTable nodeNodeNgramTable
65
66 -- | not optimized (get all ngrams without filters)
67 nodeNodeNgrams :: PGS.Connection -> IO [NodeNodeNgram]
68 nodeNodeNgrams conn = runQuery conn queryNodeNodeNgramTable
69
70 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
71 queryRunnerColumnDefault = fieldQueryRunnerColumn