]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNgramNgram.hs
[FLOW][DB][NGRAMS] grouping function and insertion design (for meeting).
[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 NodeNgramNgram table is used to group Ngrams
11
12 Next Step:
13 - group with: https://en.wikipedia.org/wiki/Nested_set_model
14
15
16 -}
17
18 {-# OPTIONS_GHC -fno-warn-orphans #-}
19 {-# LANGUAGE Arrows #-}
20 {-# LANGUAGE FlexibleInstances #-}
21 {-# LANGUAGE FunctionalDependencies #-}
22 {-# LANGUAGE MultiParamTypeClasses #-}
23 {-# LANGUAGE NoImplicitPrelude #-}
24 {-# LANGUAGE TemplateHaskell #-}
25
26 module Gargantext.Database.NodeNgramNgram where
27
28 import Gargantext.Prelude
29 import Data.Maybe (Maybe)
30 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
31 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
32 import qualified Database.PostgreSQL.Simple as PGS
33
34 import Opaleye
35
36 data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight =
37 NodeNgramNgram { nng_NodeId :: node_id
38 , nng_Ngram1Id :: ngram1_id
39 , nng_Ngram2Id :: ngram2_id
40 , nng_Weight :: weight
41 } deriving (Show)
42
43
44 type NodeNgramNgramWrite =
45 NodeNgramNgramPoly (Maybe (Column PGInt4 ))
46 (Column PGInt4 )
47 (Column PGInt4 )
48 (Maybe (Column PGFloat8))
49
50 type NodeNgramNgramRead =
51 NodeNgramNgramPoly (Column PGInt4 )
52 (Column PGInt4 )
53 (Column PGInt4 )
54 (Column PGFloat8)
55
56 type NodeNgramNgram =
57 NodeNgramNgramPoly (Maybe Int )
58 Int
59 Int
60 (Maybe Double)
61
62 $(makeAdaptorAndInstance "pNodeNgramNgram"
63 ''NodeNgramNgramPoly)
64 $(makeLensesWith abbreviatedFields
65 ''NodeNgramNgramPoly)
66
67
68 nodeNgramNgramTable :: Table NodeNgramNgramWrite NodeNgramNgramRead
69 nodeNgramNgramTable =
70 Table "nodes_ngrams_ngrams"
71 ( pNodeNgramNgram NodeNgramNgram
72 { nng_NodeId = optional "node_id"
73 , nng_Ngram1Id = required "ngram1_id"
74 , nng_Ngram2Id = required "ngram2_id"
75 , nng_Weight = optional "weight"
76 }
77 )
78
79 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
80 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
81
82 -- | not optimized (get all ngrams without filters)
83 nodeNgramNgrams :: PGS.Connection -> IO [NodeNgramNgram]
84 nodeNgramNgrams conn = runQuery conn queryNodeNgramNgramTable
85
86 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
87 queryRunnerColumnDefault = fieldQueryRunnerColumn
88
89 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
90 queryRunnerColumnDefault = fieldQueryRunnerColumn
91
92