]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNgram.hs
Merge branch 'master' into dbflow
[gargantext.git] / src / Gargantext / Database / NodeNgram.hs
1 {-|
2 Module : Gargantext.Database.NodeNgram
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
16 {-# LANGUAGE Arrows #-}
17 {-# LANGUAGE FlexibleInstances #-}
18 {-# LANGUAGE FunctionalDependencies #-}
19 {-# LANGUAGE MultiParamTypeClasses #-}
20 {-# LANGUAGE NoImplicitPrelude #-}
21 {-# LANGUAGE TemplateHaskell #-}
22
23
24 module Gargantext.Database.NodeNgram where
25
26 import Gargantext.Prelude
27 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
28 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
29 import Gargantext.Database.Node (mkCmd, Cmd(..))
30 import Opaleye
31
32 data NodeNgramPoly id node_id ngram_id weight ngrams_type
33 = NodeNgram { nodeNgram_NodeNgramId :: id
34 , nodeNgram_NodeNgramNodeId :: node_id
35 , nodeNgram_NodeNgramNgramId :: ngram_id
36 , nodeNgram_NodeNgramWeight :: weight
37 , nodeNgram_NodeNgramType :: ngrams_type
38 } deriving (Show)
39
40 type NodeNgramWrite = NodeNgramPoly (Maybe (Column PGInt4 ))
41 (Column PGInt4 )
42 (Column PGInt4 )
43 (Column PGFloat8)
44 (Column PGInt4 )
45
46 type NodeNgramRead = NodeNgramPoly (Column PGInt4 )
47 (Column PGInt4 )
48 (Column PGInt4 )
49 (Column PGFloat8)
50 (Column PGInt4 )
51
52 type NodeNgram = NodeNgramPoly (Maybe Int) Int Int Double Int
53
54 $(makeAdaptorAndInstance "pNodeNgram" ''NodeNgramPoly)
55 $(makeLensesWith abbreviatedFields ''NodeNgramPoly)
56
57
58 nodeNgramTable :: Table NodeNgramWrite NodeNgramRead
59 nodeNgramTable = Table "nodes_ngrams" ( pNodeNgram NodeNgram
60 { nodeNgram_NodeNgramId = optional "id"
61 , nodeNgram_NodeNgramNodeId = required "node_id"
62 , nodeNgram_NodeNgramNgramId = required "ngram_id"
63 , nodeNgram_NodeNgramWeight = required "weight"
64 , nodeNgram_NodeNgramType = required "ngrams_type"
65 }
66 )
67
68 queryNodeNgramTable :: Query NodeNgramRead
69 queryNodeNgramTable = queryTable nodeNgramTable
70
71 insertNodeNgrams :: [NodeNgram] -> Cmd Int
72 insertNodeNgrams = insertNodeNgramW
73 . map (\(NodeNgram _ n g w t) ->
74 NodeNgram Nothing (pgInt4 n) (pgInt4 g)
75 (pgDouble w) (pgInt4 t)
76 )
77
78 insertNodeNgramW :: [NodeNgramWrite] -> Cmd Int
79 insertNodeNgramW nns = mkCmd $ \c -> fromIntegral <$> runInsertMany c nodeNgramTable nns
80
81