]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNodeNgram.hs
Use desc instead of descr and use defaultCorpus
[gargantext.git] / src / Gargantext / Database / NodeNodeNgram.hs
1
2 {-|
3 Module : Gargantext.Database.NodeNodeNgram
4 Description :
5 Copyright : (c) CNRS, 2017-Present
6 License : AGPL + CECILL v3
7 Maintainer : team@gargantext.org
8 Stability : experimental
9 Portability : POSIX
10
11 Here is a longer description of this module, containing some
12 commentary with @some markup@.
13 -}
14
15 {-# LANGUAGE NoImplicitPrelude #-}
16 {-# LANGUAGE TemplateHaskell #-}
17 {-# LANGUAGE FlexibleInstances #-}
18 {-# LANGUAGE MultiParamTypeClasses #-}
19 {-# LANGUAGE FunctionalDependencies #-}
20 {-# LANGUAGE Arrows #-}
21 {-# OPTIONS_GHC -fno-warn-orphans #-}
22
23
24 module Gargantext.Database.NodeNodeNgram where
25
26 import Prelude
27 import Data.Maybe (Maybe)
28 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
29 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
30 import qualified Database.PostgreSQL.Simple as PGS
31
32 import Opaleye
33
34
35 data NodeNodeNgramPoly node1_id node2_id ngram_id score
36 = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
37 , nodeNodeNgram_node2_id :: node2_id
38 , nodeNodeNgram_ngram_id :: ngram_id
39 , nodeNodeNgram_score :: score
40 } deriving (Show)
41
42
43 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4 )
44 (Column PGInt4 )
45 (Column PGInt4 )
46 (Maybe (Column PGFloat8))
47
48 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4 )
49 (Column PGInt4 )
50 (Column PGInt4 )
51 (Column PGFloat8)
52
53 type NodeNodeNgramReadNull = NodeNodeNgramPoly (Column (Nullable PGInt4 ))
54 (Column (Nullable PGInt4 ))
55 (Column (Nullable PGInt4 ))
56 (Column (Nullable PGFloat8))
57
58 type NodeNodeNgram = NodeNodeNgramPoly Int
59 Int
60 Int
61 (Maybe Double)
62
63
64 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
65 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
66
67 nodeNodeNgramTable :: Table NodeNodeNgramWrite NodeNodeNgramRead
68 nodeNodeNgramTable = Table "nodes_nodes_ngrams"
69 ( pNodeNodeNgram NodeNodeNgram
70 { nodeNodeNgram_node1_id = required "node1_id"
71 , nodeNodeNgram_node2_id = required "node2_id"
72 , nodeNodeNgram_ngram_id = required "ngram_id"
73 , nodeNodeNgram_score = optional "score"
74 }
75 )
76
77
78 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
79 queryNodeNodeNgramTable = queryTable nodeNodeNgramTable
80
81 -- | not optimized (get all ngrams without filters)
82 nodeNodeNgrams :: PGS.Connection -> IO [NodeNodeNgram]
83 nodeNodeNgrams conn = runQuery conn queryNodeNodeNgramTable
84
85 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
86 queryRunnerColumnDefault = fieldQueryRunnerColumn