NodeNgram.hs 2.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{-|
Module      : Gargantext.Database.NodeNgram
Description : 
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

Here is a longer description of this module, containing some
commentary with @some markup@.
-}

{-# OPTIONS_GHC -fno-warn-orphans   #-}

{-# LANGUAGE Arrows                 #-}
{-# LANGUAGE FlexibleInstances      #-}
18
{-# LANGUAGE FunctionalDependencies #-}
19 20 21
{-# LANGUAGE MultiParamTypeClasses  #-}
{-# LANGUAGE NoImplicitPrelude      #-}
{-# LANGUAGE TemplateHaskell        #-}
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38


module Gargantext.Database.NodeNgram where

import Prelude
import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
import Control.Lens.TH (makeLensesWith, abbreviatedFields)

import Opaleye

data NodeNgramPoly id node_id ngram_id weight
                   = NodeNgram { nodeNgram_NodeNgramId      :: id
                               , nodeNgram_NodeNgramNodeId  :: node_id
                               , nodeNgram_NodeNgramNgramId :: ngram_id
                               , nodeNgram_NodeNgramWeight  :: weight
                               } deriving (Show)

Alexandre Delanoë's avatar
Alexandre Delanoë committed
39 40 41 42
type NodeNgramWrite = NodeNgramPoly (Column PGInt4  )
                                    (Column PGInt4  )
                                    (Column PGInt4  )
                                    (Column PGFloat8)
43

Alexandre Delanoë's avatar
Alexandre Delanoë committed
44 45 46 47
type NodeNgramRead  = NodeNgramPoly (Column PGInt4  )
                                    (Column PGInt4  )
                                    (Column PGInt4  )
                                    (Column PGFloat8)
48

49
type NodeNgram = NodeNgramPoly Int Int Int Double
50 51 52 53 54 55

$(makeAdaptorAndInstance "pNodeNgram" ''NodeNgramPoly)
$(makeLensesWith abbreviatedFields    ''NodeNgramPoly)


nodeNgramTable :: Table NodeNgramWrite NodeNgramRead
Alexandre Delanoë's avatar
Alexandre Delanoë committed
56 57 58 59 60 61
nodeNgramTable  = Table "nodes_ngrams" ( pNodeNgram NodeNgram 
                                           { nodeNgram_NodeNgramId = required "id"
                                           , nodeNgram_NodeNgramNodeId   = required "node_id"
                                           , nodeNgram_NodeNgramNgramId  = required "ngram_id"
                                           , nodeNgram_NodeNgramWeight   = required "weight"
                                           }
62 63 64 65 66
                                       )

queryNodeNgramTable :: Query NodeNgramRead
queryNodeNgramTable = queryTable nodeNgramTable