2 Module : Gargantext.Database.Ngrams
3 Description : Deal with in Gargantext Database.
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE Arrows #-}
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE RankNTypes #-}
17 module Gargantext.Database.Ngrams
20 import Data.Text (Text)
21 import Control.Lens ((^.))
22 import Gargantext.Core.Types
23 import Gargantext.Database.Utils (runOpaQuery, Cmd)
24 import Gargantext.Database.Schema.Ngrams
25 import Gargantext.Database.Schema.NodeNodeNgrams
26 import Gargantext.Database.Schema.Node
27 import Gargantext.Prelude
29 import Control.Arrow (returnA)
31 selectNgramsByDoc :: [CorpusId] -> DocId -> NgramsType -> Cmd err [Text]
32 selectNgramsByDoc cIds dId nt = runOpaQuery (query cIds dId nt)
35 join :: Query (NgramsRead, NodeNodeNgramsReadNull)
36 join = leftJoin queryNgramsTable queryNodeNodeNgramsTable on1
38 on1 (ng,nnng) = ng^.ngrams_id .== nnng^.nnng_ngrams_id
40 query cIds' dId' nt' = proc () -> do
41 (ng,nnng) <- join -< ()
42 restrict -< foldl (\b cId -> ((toNullable $ pgNodeId cId) .== nnng^.nnng_node1_id) .|| b) (pgBool True) cIds'
43 restrict -< (toNullable $ pgNodeId dId') .== nnng^.nnng_node2_id
44 restrict -< (toNullable $ pgNgramsType nt') .== nnng^.nnng_ngramsType
45 returnA -< ng^.ngrams_terms
48 postNgrams :: CorpusId -> DocId -> [Text] -> Cmd err Int
49 postNgrams = undefined