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