]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNgrams.hs
[DB/REFACT] intermediary step
[gargantext.git] / src / Gargantext / Database / Schema / NodeNgrams.hs
1 {-|
2 Module : Gargantext.Database.Schema.NodeNgrams
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 NodeNgrams register Context of Ngrams (named Cgrams then)
11
12 -}
13
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
15
16 {-# LANGUAGE Arrows #-}
17 {-# LANGUAGE FlexibleContexts #-}
18 {-# LANGUAGE FlexibleInstances #-}
19 {-# LANGUAGE FunctionalDependencies #-}
20 {-# LANGUAGE QuasiQuotes #-}
21 {-# LANGUAGE MultiParamTypeClasses #-}
22 {-# LANGUAGE NoImplicitPrelude #-}
23 {-# LANGUAGE OverloadedStrings #-}
24 {-# LANGUAGE RankNTypes #-}
25 {-# LANGUAGE TemplateHaskell #-}
26
27 module Gargantext.Database.Schema.NodeNgrams where
28
29 import Data.List.Extra (nubOrd)
30 import Data.Map (Map)
31 import Data.Maybe (Maybe, fromMaybe)
32 import Data.Text (Text)
33 import Database.PostgreSQL.Simple (FromRow)
34 import Database.PostgreSQL.Simple.FromRow (fromRow, field)
35 import Database.PostgreSQL.Simple.SqlQQ (sql)
36 import Database.PostgreSQL.Simple.ToField (toField)
37 import Database.PostgreSQL.Simple.Types (Values(..), QualifiedIdentifier(..))
38 import Gargantext.Core.Types
39 import Gargantext.Database.Admin.Utils
40 import Gargantext.Database.Schema.Ngrams (NgramsType, ngramsTypeId, fromNgramsTypeId)
41 import Gargantext.Prelude
42 import qualified Data.List as List
43 import qualified Data.Map as Map
44 import qualified Database.PostgreSQL.Simple as PGS (Query, Only(..))
45
46
47 data NodeNgramsPoly id
48 node_id'
49 node_subtype
50 ngrams_id
51 ngrams_type
52 ngrams_field
53 ngrams_tag
54 ngrams_class
55 weight
56 = NodeNgrams { _nng_id :: !id
57 , _nng_node_id :: !node_id'
58 , _nng_node_subtype :: !node_subtype
59 , _nng_ngrams_id :: !ngrams_id
60 , _nng_ngrams_type :: !ngrams_type
61 , _nng_ngrams_field :: !ngrams_field
62 , _nng_ngrams_tag :: !ngrams_tag
63 , _nng_ngrams_class :: !ngrams_class
64 , _nng_ngrams_weight :: !weight
65 } deriving (Show, Eq, Ord)
66
67 {-
68 type NodeNgramsWrite = NodeNgramsPoly (Maybe (Column (PGInt4)))
69 (Column (PGInt4))
70 (Maybe (Column (PGInt4)))
71 (Column (PGInt4))
72 (Maybe (Column (PGInt4)))
73 (Maybe (Column (PGInt4)))
74 (Maybe (Column (PGInt4)))
75 (Maybe (Column (PGInt4)))
76 (Maybe (Column (PGFloat8)))
77
78 type NodeNodeRead = NodeNgramsPoly (Column PGInt4)
79 (Column PGInt4)
80 (Column PGInt4)
81 (Column PGInt4)
82 (Column PGInt4)
83 (Column PGInt4)
84 (Column PGInt4)
85 (Column PGInt4)
86 (Column PGFloat8)
87
88 type NodeNgramsReadNull = NodeNgramsPoly (Column (Nullable PGInt4))
89 (Column (Nullable PGInt4))
90 (Column (Nullable PGInt4))
91 (Column (Nullable PGInt4))
92
93 (Column (Nullable PGInt4))
94 (Column (Nullable PGInt4))
95 (Column (Nullable PGInt4))
96 (Column (Nullable PGInt4))
97 (Column (Nullable PGFloat8))
98 -}
99 type NodeNgramsId = Int
100 type NgramsId = Int
101 type NgramsField = Int
102 type NgramsTag = Int
103 type NgramsClass = Int
104 type NgramsText = Text
105
106 -- Example of list Ngrams
107 -- type ListNgrams = NodeNgramsPoly (Maybe Int) ListType Text
108
109 type NodeNgramsW =
110 NodeNgramsPoly (Maybe NodeNgramsId) NodeId ListType NgramsText
111 NgramsType (Maybe NgramsField) (Maybe NgramsTag) (Maybe NgramsClass)
112 Double
113