Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
156790ff
Commit
156790ff
authored
Dec 20, 2021
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] backup during the vacations
parent
2d69d20f
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
1153 additions
and
289 deletions
+1153
-289
Main.hs
bin/gargantext-init/Main.hs
+5
-1
create
devops/postgres/create
+3
-3
schema.sql
devops/postgres/schema.sql
+113
-60
Flow.hs
src/Gargantext/Database/Action/Flow.hs
+8
-5
Utils.hs
src/Gargantext/Database/Action/Flow/Utils.hs
+7
-7
NgramsByNode.hs
src/Gargantext/Database/Action/Metrics/NgramsByNode.hs
+53
-53
ContextNodeNgrams.hs
src/Gargantext/Database/Admin/Trigger/ContextNodeNgrams.hs
+23
-23
Init.hs
src/Gargantext/Database/Admin/Trigger/Init.hs
+2
-2
Nodes.hs
src/Gargantext/Database/Admin/Trigger/Nodes.hs
+6
-3
Node.hs
src/Gargantext/Database/Admin/Types/Node.hs
+62
-5
Facet.hs
src/Gargantext/Database/Query/Facet.hs
+49
-77
Join.hs
src/Gargantext/Database/Query/Join.hs
+1
-2
Context.hs
src/Gargantext/Database/Query/Table/Context.hs
+120
-0
ContextNodeNgrams.hs
src/Gargantext/Database/Query/Table/ContextNodeNgrams.hs
+55
-0
ContextNodeNgrams2.hs
src/Gargantext/Database/Query/Table/ContextNodeNgrams2.hs
+15
-15
Ngrams.hs
src/Gargantext/Database/Query/Table/Ngrams.hs
+8
-8
Add.hs
src/Gargantext/Database/Query/Table/Node/Document/Add.hs
+3
-3
Insert.hs
src/Gargantext/Database/Query/Table/Node/Document/Insert.hs
+3
-3
NodeContext.hs
src/Gargantext/Database/Query/Table/NodeContext.hs
+217
-0
Context.hs
src/Gargantext/Database/Schema/Context.hs
+178
-0
ContextNodeNgrams.hs
src/Gargantext/Database/Schema/ContextNodeNgrams.hs
+74
-0
ContextNodeNgrams2.hs
src/Gargantext/Database/Schema/ContextNodeNgrams2.hs
+63
-0
NgramsPostag.hs
src/Gargantext/Database/Schema/NgramsPostag.hs
+20
-19
NodeContext.hs
src/Gargantext/Database/Schema/NodeContext.hs
+65
-0
No files found.
bin/gargantext-init/Main.hs
View file @
156790ff
...
@@ -39,7 +39,11 @@ secret = "Database secret to change"
...
@@ -39,7 +39,11 @@ secret = "Database secret to change"
main
::
IO
()
main
::
IO
()
main
=
do
main
=
do
[
iniPath
]
<-
getArgs
params
@
[
iniPath
]
<-
getArgs
_
<-
if
length
params
/=
1
then
panic
"USAGE: ./gargantext-init gargantext.ini"
else
pure
()
putStrLn
"Enter master user (gargantua) _password_ :"
putStrLn
"Enter master user (gargantua) _password_ :"
password
<-
getLine
password
<-
getLine
...
...
devops/postgres/create
View file @
156790ff
...
@@ -5,11 +5,11 @@
...
@@ -5,11 +5,11 @@
# postgresql://$USER:$PW@localhost/$DB
# postgresql://$USER:$PW@localhost/$DB
PW
=
"C8kdcUrAQy66U"
PW
=
"C8kdcUrAQy66U"
DB
=
"gargandb
V5
"
DB
=
"gargandb
1
"
USER
=
"gargantua"
USER
=
"gargantua"
psql
-c
"CREATE USER
\"
${
USER
}
\"
"
#
psql -c "CREATE USER \"${USER}\""
psql
-c
"ALTER USER
\"
${
USER
}
\"
with PASSWORD '
${
PW
}
'"
#
psql -c "ALTER USER \"${USER}\" with PASSWORD '${PW}'"
psql
-c
"DROP DATABASE IF EXISTS
\"
${
DB
}
\"
"
psql
-c
"DROP DATABASE IF EXISTS
\"
${
DB
}
\"
"
createdb
"
${
DB
}
"
createdb
"
${
DB
}
"
...
...
devops/postgres/schema.sql
View file @
156790ff
...
@@ -19,8 +19,8 @@ CREATE TABLE public.auth_user (
...
@@ -19,8 +19,8 @@ CREATE TABLE public.auth_user (
date_joined
TIMESTAMP
with
time
zone
DEFAULT
now
()
NOT
NULL
,
date_joined
TIMESTAMP
with
time
zone
DEFAULT
now
()
NOT
NULL
,
PRIMARY
KEY
(
id
)
PRIMARY
KEY
(
id
)
);
);
ALTER
TABLE
public
.
auth_user
OWNER
TO
gargantua
;
ALTER
TABLE
public
.
auth_user
OWNER
TO
gargantua
;
-----------------------------------------------------------------
-- TODO add publication_date
-- TODO add publication_date
-- TODO typename -> type_id
-- TODO typename -> type_id
...
@@ -38,6 +38,25 @@ CREATE TABLE public.nodes (
...
@@ -38,6 +38,25 @@ CREATE TABLE public.nodes (
FOREIGN
KEY
(
user_id
)
REFERENCES
public
.
auth_user
(
id
)
ON
DELETE
CASCADE
FOREIGN
KEY
(
user_id
)
REFERENCES
public
.
auth_user
(
id
)
ON
DELETE
CASCADE
);
);
ALTER
TABLE
public
.
nodes
OWNER
TO
gargantua
;
ALTER
TABLE
public
.
nodes
OWNER
TO
gargantua
;
--------------------------------------------------------------
-- TODO add publication_date
-- TODO typename -> type_id
CREATE
TABLE
public
.
contexts
(
id
SERIAL
,
hash_id
CHARACTER
varying
(
66
)
DEFAULT
''
::
character
varying
NOT
NULL
,
typename
INTEGER
NOT
NULL
,
user_id
INTEGER
NOT
NULL
,
parent_id
INTEGER
REFERENCES
public
.
contexts
(
id
)
ON
DELETE
CASCADE
,
name
CHARACTER
varying
(
255
)
DEFAULT
''
::
character
varying
NOT
NULL
,
date
TIMESTAMP
with
time
zone
DEFAULT
now
()
NOT
NULL
,
hyperdata
jsonb
DEFAULT
'{}'
::
jsonb
NOT
NULL
,
search
tsvector
,
PRIMARY
KEY
(
id
),
FOREIGN
KEY
(
user_id
)
REFERENCES
public
.
auth_user
(
id
)
ON
DELETE
CASCADE
);
ALTER
TABLE
public
.
contexts
OWNER
TO
gargantua
;
--------------------------------------------------------------
--------------------------------------------------------------
-- | Ngrams
-- | Ngrams
CREATE
TABLE
public
.
ngrams
(
CREATE
TABLE
public
.
ngrams
(
...
@@ -50,51 +69,51 @@ ALTER TABLE public.ngrams OWNER TO gargantua;
...
@@ -50,51 +69,51 @@ ALTER TABLE public.ngrams OWNER TO gargantua;
-- | Ngrams PosTag
-- | Ngrams PosTag
CREATE
TABLE
public
.
ngrams_postag
(
CREATE
TABLE
public
.
ngrams_postag
(
id
SERIAL
,
id
SERIAL
,
lang_id
INTEGER
,
lang_id
INTEGER
,
algo_id
INTEGER
,
algo_id
INTEGER
,
postag
CHARACTER
varying
(
5
)
,
postag
CHARACTER
varying
(
5
)
,
ngrams_id
INTEGER
NOT
NULL
,
ngrams_id
INTEGER
NOT
NULL
,
lemm_id
INTEGER
NOT
NULL
,
lemm_id
INTEGER
NOT
NULL
,
score
INTEGER
DEFAULT
1
::
integer
NOT
NULL
,
score
INTEGER
DEFAULT
1
::
integer
NOT
NULL
,
FOREIGN
KEY
(
ngrams_id
)
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
,
FOREIGN
KEY
(
ngrams_id
)
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
,
FOREIGN
KEY
(
lemm_id
)
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
FOREIGN
KEY
(
lemm_id
)
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
);
);
ALTER
TABLE
public
.
ngrams_postag
OWNER
TO
gargantua
;
ALTER
TABLE
public
.
ngrams_postag
OWNER
TO
gargantua
;
--------------------------------------------------------------
--------------------------------------------------------------
-- Node here should have type NodeList
CREATE
TABLE
public
.
node_ngrams
(
CREATE
TABLE
public
.
node_ngrams
(
id
SERIAL
,
id
SERIAL
,
node_id
INTEGER
NOT
NULL
,
node_id
INTEGER
NOT
NULL
,
node_subtype
INTEGER
,
node_subtype
INTEGER
,
ngrams_id
INTEGER
NOT
NULL
,
ngrams_id
INTEGER
NOT
NULL
,
ngrams_type
INTEGER
,
-- change to ngrams_field? (no for pedagogic reason)
ngrams_type
INTEGER
,
-- change to ngrams_field? (no for pedagogic reason)
ngrams_field
INTEGER
,
ngrams_field
INTEGER
,
ngrams_tag
INTEGER
,
ngrams_tag
INTEGER
,
ngrams_class
INTEGER
,
ngrams_class
INTEGER
,
weight
double
precision
,
weight
double
precision
,
PRIMARY
KEY
(
id
),
PRIMARY
KEY
(
id
)
,
FOREIGN
KEY
(
node_id
)
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
FOREIGN
KEY
(
node_id
)
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
FOREIGN
KEY
(
ngrams_id
)
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
FOREIGN
KEY
(
ngrams_id
)
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
);
);
ALTER
TABLE
public
.
node_ngrams
OWNER
TO
gargantua
;
ALTER
TABLE
public
.
node_ngrams
OWNER
TO
gargantua
;
CREATE
TABLE
public
.
node
_nodengrams_nodengrams
(
--CREATE TABLE public.context
_nodengrams_nodengrams (
node_id
INTEGER
NOT
NULL
,
-- context_id INTEGER NOT NULL
,
node_ngrams1_id
INTEGER
NOT
NULL
,
-- node_ngrams1_id INTEGER NOT NULL
,
node_ngrams2_id
INTEGER
NOT
NULL
,
-- node_ngrams2_id INTEGER NOT NULL
,
weight
double
precision
,
-- weight double precision
,
FOREIGN
KEY
(
node_id
)
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
-- FOREIGN KEY (node_id) REFERENCES public.contexts(id) ON DELETE CASCADE
,
FOREIGN
KEY
(
node_ngrams1_id
)
REFERENCES
public
.
node_ngrams
(
id
)
ON
DELETE
CASCADE
,
--
FOREIGN KEY (node_ngrams1_id) REFERENCES public.node_ngrams(id) ON DELETE CASCADE,
FOREIGN
KEY
(
node_ngrams2_id
)
REFERENCES
public
.
node_ngrams
(
id
)
ON
DELETE
CASCADE
,
--
FOREIGN KEY (node_ngrams2_id) REFERENCES public.node_ngrams(id) ON DELETE CASCADE,
PRIMARY
KEY
(
node_id
,
node_ngrams1_id
,
node_ngrams2_id
)
--
PRIMARY KEY (node_id, node_ngrams1_id, node_ngrams2_id)
);
--
);
ALTER
TABLE
public
.
node
_nodengrams_nodengrams
OWNER
TO
gargantua
;
--ALTER TABLE public.context
_nodengrams_nodengrams OWNER TO gargantua;
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--
--
--
--CREATE TABLE public.nodes_ngrams_ngrams (
--CREATE TABLE public.nodes_ngrams_ngrams (
-- node_id integer NOT NULL REFERENCES public.nodes(id) ON DELETE CASCADE,
-- node_id integer NOT NULL REFERENCES public.nodes(id) ON DELETE CASCADE,
-- ngram1_id integer NOT NULL REFERENCES public.ngrams(id) ON DELETE CASCADE,
-- ngram1_id integer NOT NULL REFERENCES public.ngrams(id) ON DELETE CASCADE,
...
@@ -109,31 +128,43 @@ ALTER TABLE public.node_nodengrams_nodengrams OWNER TO gargantua;
...
@@ -109,31 +128,43 @@ ALTER TABLE public.node_nodengrams_nodengrams OWNER TO gargantua;
CREATE
TABLE
public
.
nodes_nodes
(
CREATE
TABLE
public
.
nodes_nodes
(
node1_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
node1_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
node2_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
node2_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
score
REAL
,
score
REAL
,
category
INTEGER
,
category
INTEGER
,
PRIMARY
KEY
(
node1_id
,
node2_id
)
PRIMARY
KEY
(
node1_id
,
node2_id
)
);
);
ALTER
TABLE
public
.
nodes_nodes
OWNER
TO
gargantua
;
ALTER
TABLE
public
.
nodes_nodes
OWNER
TO
gargantua
;
---------------------------------------------------------------
-- To attach contexts to a Corpus
CREATE
TABLE
public
.
node_node_ngrams
(
CREATE
TABLE
public
.
nodes_contexts
(
node1_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
node_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
node2_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
context_id
INTEGER
NOT
NULL
REFERENCES
public
.
contexts
(
id
)
ON
DELETE
CASCADE
,
ngrams_id
INTEGER
NOT
NULL
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
,
score
REAL
,
ngrams_type
INTEGER
,
category
INTEGER
,
weight
double
precision
,
PRIMARY
KEY
(
node_id
,
context_id
)
PRIMARY
KEY
(
node1_id
,
node2_id
,
ngrams_id
,
ngrams_type
)
);
);
ALTER
TABLE
public
.
node_node_ngrams
OWNER
TO
gargantua
;
ALTER
TABLE
public
.
nodes_contexts
OWNER
TO
gargantua
;
---------------------------------------------------------------
CREATE
TABLE
public
.
context_node_ngrams
(
context_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
node_id
INTEGER
NOT
NULL
REFERENCES
public
.
contexts
(
id
)
ON
DELETE
CASCADE
,
ngrams_id
INTEGER
NOT
NULL
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
,
ngrams_type
INTEGER
,
weight
double
precision
,
PRIMARY
KEY
(
context_id
,
node_id
,
ngrams_id
,
ngrams_type
)
);
CREATE
TABLE
public
.
node_node_ngrams2
(
node_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
ALTER
TABLE
public
.
context_node_ngrams
OWNER
TO
gargantua
;
nodengrams_id
INTEGER
NOT
NULL
REFERENCES
public
.
node_ngrams
(
id
)
ON
DELETE
CASCADE
,
weight
double
precision
,
CREATE
TABLE
public
.
context_node_ngrams2
(
PRIMARY
KEY
(
node_id
,
nodengrams_id
)
context_id
INTEGER
NOT
NULL
REFERENCES
public
.
contexts
(
id
)
ON
DELETE
CASCADE
,
nodengrams_id
INTEGER
NOT
NULL
REFERENCES
public
.
node_ngrams
(
id
)
ON
DELETE
CASCADE
,
weight
double
precision
,
PRIMARY
KEY
(
context_id
,
nodengrams_id
)
);
);
ALTER
TABLE
public
.
node
_node_ngrams2
OWNER
TO
gargantua
;
ALTER
TABLE
public
.
context
_node_ngrams2
OWNER
TO
gargantua
;
--------------------------------------------------------------
--------------------------------------------------------------
...
@@ -148,7 +179,6 @@ ALTER TABLE public.node_node_ngrams2 OWNER TO gargantua;
...
@@ -148,7 +179,6 @@ ALTER TABLE public.node_node_ngrams2 OWNER TO gargantua;
-- If needed for rights management at row level
-- If needed for rights management at row level
-- CREATE EXTENSION IF NOT EXISTS acl WITH SCHEMA public;
-- CREATE EXTENSION IF NOT EXISTS acl WITH SCHEMA public;
CREATE
TABLE
public
.
rights
(
CREATE
TABLE
public
.
rights
(
user_id
INTEGER
NOT
NULL
REFERENCES
public
.
auth_user
(
id
)
ON
DELETE
CASCADE
,
user_id
INTEGER
NOT
NULL
REFERENCES
public
.
auth_user
(
id
)
ON
DELETE
CASCADE
,
node_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
node_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
...
@@ -171,6 +201,15 @@ CREATE INDEX ON public.nodes USING btree (id, typename, date ASC);
...
@@ -171,6 +201,15 @@ CREATE INDEX ON public.nodes USING btree (id, typename, date ASC);
CREATE
INDEX
ON
public
.
nodes
USING
btree
(
id
,
typename
,
date
DESC
);
CREATE
INDEX
ON
public
.
nodes
USING
btree
(
id
,
typename
,
date
DESC
);
CREATE
INDEX
ON
public
.
nodes
USING
btree
(
typename
,
id
);
CREATE
INDEX
ON
public
.
nodes
USING
btree
(
typename
,
id
);
CREATE
UNIQUE
INDEX
ON
public
.
nodes
USING
btree
(
hash_id
);
CREATE
UNIQUE
INDEX
ON
public
.
nodes
USING
btree
(
hash_id
);
CREATE
INDEX
ON
public
.
contexts
USING
gin
(
hyperdata
);
CREATE
INDEX
ON
public
.
contexts
USING
btree
(
user_id
,
typename
,
parent_id
);
CREATE
INDEX
ON
public
.
contexts
USING
btree
(
id
,
typename
,
date
ASC
);
CREATE
INDEX
ON
public
.
contexts
USING
btree
(
id
,
typename
,
date
DESC
);
CREATE
INDEX
ON
public
.
contexts
USING
btree
(
typename
,
id
);
CREATE
UNIQUE
INDEX
ON
public
.
contexts
USING
btree
(
hash_id
);
-- CREATE UNIQUE INDEX ON public.nodes USING btree (((hyperdata ->> 'uniqId'::text)));
-- CREATE UNIQUE INDEX ON public.nodes USING btree (((hyperdata ->> 'uniqId'::text)));
-- CREATE UNIQUE INDEX ON public.nodes USING btree (((hyperdata ->> 'uniqIdBdd'::text)));
-- CREATE UNIQUE INDEX ON public.nodes USING btree (((hyperdata ->> 'uniqIdBdd'::text)));
-- CREATE UNIQUE INDEX ON public.nodes USING btree (typename, parent_id, ((hyperdata ->> 'uniqId'::text)));
-- CREATE UNIQUE INDEX ON public.nodes USING btree (typename, parent_id, ((hyperdata ->> 'uniqId'::text)));
...
@@ -178,23 +217,37 @@ CREATE UNIQUE INDEX ON public.nodes USING btree (hash_id);
...
@@ -178,23 +217,37 @@ CREATE UNIQUE INDEX ON public.nodes USING btree (hash_id);
CREATE
UNIQUE
INDEX
ON
public
.
ngrams
(
terms
);
-- TEST GIN
CREATE
UNIQUE
INDEX
ON
public
.
ngrams
(
terms
);
-- TEST GIN
CREATE
INDEX
ON
public
.
ngrams
USING
btree
(
id
,
terms
);
CREATE
INDEX
ON
public
.
ngrams
USING
btree
(
id
,
terms
);
CREATE
UNIQUE
INDEX
ON
public
.
ngrams_postag
(
lang_id
,
algo_id
,
postag
,
ngrams_id
,
lemm_id
);
CREATE
UNIQUE
INDEX
ON
public
.
ngrams_postag
(
lang_id
,
algo_id
,
postag
,
ngrams_id
,
lemm_id
);
-- To save the Node Ngrams Repo
CREATE
INDEX
ON
public
.
node_ngrams
USING
btree
(
node_id
,
node_subtype
);
CREATE
INDEX
ON
public
.
node_ngrams
USING
btree
(
node_id
,
node_subtype
);
CREATE
UNIQUE
INDEX
ON
public
.
node_ngrams
USING
btree
(
node_id
,
node_subtype
,
ngrams_id
);
CREATE
UNIQUE
INDEX
ON
public
.
node_ngrams
USING
btree
(
node_id
,
node_subtype
,
ngrams_id
);
-- To make the links between Nodes in Tree/Forest
CREATE
UNIQUE
INDEX
ON
public
.
nodes_nodes
USING
btree
(
node1_id
,
node2_id
);
CREATE
UNIQUE
INDEX
ON
public
.
nodes_nodes
USING
btree
(
node1_id
,
node2_id
);
CREATE
INDEX
ON
public
.
nodes_nodes
USING
btree
(
node1_id
,
node2_id
,
category
);
CREATE
INDEX
ON
public
.
nodes_nodes
USING
btree
(
node1_id
,
node2_id
,
category
);
CREATE
UNIQUE
INDEX
ON
public
.
node_node_ngrams
USING
btree
(
node1_id
,
node2_id
,
ngrams_id
,
ngrams_type
);
-- To make the links between Corpus Node and its contexts
CREATE
INDEX
ON
public
.
node_node_ngrams
USING
btree
(
node1_id
,
node2_id
);
CREATE
UNIQUE
INDEX
ON
public
.
nodes_contexts
USING
btree
(
node_id
,
context_id
);
CREATE
INDEX
ON
public
.
node_node_ngrams
USING
btree
(
ngrams_id
,
node2_id
);
CREATE
INDEX
ON
public
.
nodes_contexts
USING
btree
(
node_id
,
context_id
,
category
);
CREATE
INDEX
ON
public
.
node_node_ngrams
USING
btree
(
ngrams_type
);
CREATE
INDEX
ON
public
.
node_nodengrams_nodengrams
USING
btree
(
node_id
,
node_ngrams1_id
,
node_ngrams2_id
);
CREATE
INDEX
ON
public
.
node_nodengrams_nodengrams
USING
btree
(
node_ngrams1_id
);
------------------------------------------------------------------------
CREATE
INDEX
ON
public
.
node_nodengrams_nodengrams
USING
btree
(
node_ngrams2_id
);
CREATE
UNIQUE
INDEX
ON
public
.
context_node_ngrams
USING
btree
(
context_id
,
node_id
,
ngrams_id
,
ngrams_type
);
CREATE
INDEX
ON
public
.
node_node_ngrams2
USING
btree
(
node_id
);
CREATE
INDEX
ON
public
.
context_node_ngrams
USING
btree
(
context_id
,
node_id
);
CREATE
INDEX
ON
public
.
node_node_ngrams2
USING
btree
(
nodengrams_id
);
CREATE
INDEX
ON
public
.
context_node_ngrams
USING
btree
(
ngrams_id
,
node_id
);
CREATE
INDEX
ON
public
.
node_node_ngrams2
USING
btree
(
node_id
,
nodengrams_id
);
CREATE
INDEX
ON
public
.
context_node_ngrams
USING
btree
(
ngrams_type
);
------------------------------------------------------------
CREATE
INDEX
ON
public
.
context_node_ngrams2
USING
btree
(
context_id
);
CREATE
INDEX
ON
public
.
context_node_ngrams2
USING
btree
(
nodengrams_id
);
CREATE
INDEX
ON
public
.
context_node_ngrams2
USING
btree
(
context_id
,
nodengrams_id
);
-- CREATE INDEX ON public.context_nodengrams_nodengrams USING btree (context_id, node_ngrams1_id, node_ngrams2_id);
-- CREATE INDEX ON public.context_nodengrams_nodengrams USING btree (node_ngrams1_id);
-- CREATE INDEX ON public.context_nodengrams_nodengrams USING btree (node_ngrams2_id);
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Ngrams Full DB Extraction Optim
-- Ngrams Full DB Extraction Optim
-- TODO remove hard parameter and move elsewhere
-- TODO remove hard parameter and move elsewhere
...
...
src/Gargantext/Database/Action/Flow.hs
View file @
156790ff
...
@@ -94,7 +94,7 @@ import Gargantext.Database.Query.Table.Node
...
@@ -94,7 +94,7 @@ import Gargantext.Database.Query.Table.Node
import
Gargantext.Database.Query.Table.Node.Document.Insert
-- (insertDocuments, ReturnId(..), addUniqIdsDoc, addUniqIdsContact, ToDbData(..))
import
Gargantext.Database.Query.Table.Node.Document.Insert
-- (insertDocuments, ReturnId(..), addUniqIdsDoc, addUniqIdsContact, ToDbData(..))
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
(
..
))
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
(
..
))
import
Gargantext.Database.Query.Table.NodeNgrams
(
listInsertDb
,
getCgramsId
)
import
Gargantext.Database.Query.Table.NodeNgrams
(
listInsertDb
,
getCgramsId
)
import
Gargantext.Database.Query.Table.
Node
NodeNgrams2
import
Gargantext.Database.Query.Table.
Context
NodeNgrams2
import
Gargantext.Database.Query.Tree.Root
(
getOrMkRoot
,
getOrMk_RootWithCorpus
)
import
Gargantext.Database.Query.Tree.Root
(
getOrMkRoot
,
getOrMk_RootWithCorpus
)
import
Gargantext.Database.Schema.Node
(
NodePoly
(
..
),
node_id
)
import
Gargantext.Database.Schema.Node
(
NodePoly
(
..
),
node_id
)
import
Gargantext.Database.Types
import
Gargantext.Database.Types
...
@@ -231,6 +231,9 @@ flow c u cn la mfslw docs logStatus = do
...
@@ -231,6 +231,9 @@ flow c u cn la mfslw docs logStatus = do
)
(
zip
[
1
..
]
docs
)
)
(
zip
[
1
..
]
docs
)
flowCorpusUser
(
la
^.
tt_lang
)
u
cn
c
(
concat
ids
)
mfslw
flowCorpusUser
(
la
^.
tt_lang
)
u
cn
c
(
concat
ids
)
mfslw
------------------------------------------------------------------------
------------------------------------------------------------------------
flowCorpusUser
::
(
FlowCmdM
env
err
m
flowCorpusUser
::
(
FlowCmdM
env
err
m
,
MkCorpus
c
,
MkCorpus
c
...
@@ -325,8 +328,8 @@ saveDocNgramsWith lId mapNgramsDocs' = do
...
@@ -325,8 +328,8 @@ saveDocNgramsWith lId mapNgramsDocs' = do
$
HashMap
.
toList
mapNgramsDocs
$
HashMap
.
toList
mapNgramsDocs
-- insertDocNgrams
-- insertDocNgrams
_return
<-
insert
Node
NodeNgrams2
_return
<-
insert
Context
NodeNgrams2
$
catMaybes
[
Node
NodeNgrams2
<$>
Just
nId
$
catMaybes
[
Context
NodeNgrams2
<$>
Just
nId
<*>
getCgramsId
mapCgramsId
ngrams_type
(
_ngramsTerms
terms''
)
<*>
getCgramsId
mapCgramsId
ngrams_type
(
_ngramsTerms
terms''
)
<*>
Just
(
fromIntegral
w
::
Double
)
<*>
Just
(
fromIntegral
w
::
Double
)
|
(
terms''
,
mapNgramsTypes
)
<-
HashMap
.
toList
mapNgramsDocs
|
(
terms''
,
mapNgramsTypes
)
<-
HashMap
.
toList
mapNgramsDocs
...
...
src/Gargantext/Database/Action/Flow/Utils.hs
View file @
156790ff
...
@@ -17,7 +17,7 @@ import Data.Map (Map)
...
@@ -17,7 +17,7 @@ import Data.Map (Map)
import
Data.HashMap.Strict
(
HashMap
)
import
Data.HashMap.Strict
(
HashMap
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Database.Query.Table.
Node
NodeNgrams
import
Gargantext.Database.Query.Table.
Context
NodeNgrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Types
import
Gargantext.Database.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
...
@@ -31,11 +31,11 @@ data DocumentIdWithNgrams a b =
...
@@ -31,11 +31,11 @@ data DocumentIdWithNgrams a b =
,
documentNgrams
::
HashMap
b
(
Map
NgramsType
Int
)
,
documentNgrams
::
HashMap
b
(
Map
NgramsType
Int
)
}
deriving
(
Show
)
}
deriving
(
Show
)
docNgrams2
node
NodeNgrams
::
CorpusId
docNgrams2
context
NodeNgrams
::
CorpusId
->
DocNgrams
->
DocNgrams
->
Node
NodeNgrams
->
Context
NodeNgrams
docNgrams2
node
NodeNgrams
cId
(
DocNgrams
d
n
nt
w
)
=
docNgrams2
context
NodeNgrams
cId
(
DocNgrams
d
n
nt
w
)
=
Node
NodeNgrams
cId
d
n
nt
w
Context
NodeNgrams
cId
d
n
nt
w
data
DocNgrams
=
DocNgrams
{
dn_doc_id
::
DocId
data
DocNgrams
=
DocNgrams
{
dn_doc_id
::
DocId
,
dn_ngrams_id
::
Int
,
dn_ngrams_id
::
Int
...
@@ -47,8 +47,8 @@ insertDocNgramsOn :: CorpusId
...
@@ -47,8 +47,8 @@ insertDocNgramsOn :: CorpusId
->
[
DocNgrams
]
->
[
DocNgrams
]
->
Cmd
err
Int
->
Cmd
err
Int
insertDocNgramsOn
cId
dn
=
insertDocNgramsOn
cId
dn
=
insert
Node
NodeNgrams
insert
Context
NodeNgrams
$
(
map
(
docNgrams2
node
NodeNgrams
cId
)
dn
)
$
(
map
(
docNgrams2
context
NodeNgrams
cId
)
dn
)
insertDocNgrams
::
CorpusId
insertDocNgrams
::
CorpusId
->
HashMap
(
Indexed
Int
Ngrams
)
(
Map
NgramsType
(
Map
NodeId
Int
))
->
HashMap
(
Indexed
Int
Ngrams
)
(
Map
NgramsType
(
Map
NodeId
Int
))
...
...
src/Gargantext/Database/Action/Metrics/NgramsByNode.hs
View file @
156790ff
...
@@ -81,16 +81,16 @@ getNodesByNgramsUser cId nt =
...
@@ -81,16 +81,16 @@ getNodesByNgramsUser cId nt =
queryNgramsByNodeUser
::
DPS
.
Query
queryNgramsByNodeUser
::
DPS
.
Query
queryNgramsByNodeUser
=
[
sql
|
queryNgramsByNodeUser
=
[
sql
|
SELECT
nng.node2_id, ng.terms FROM node_node_ngrams n
ng
SELECT
cng.node_id, ng.terms FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN nodes_nodes nn ON nn.node2_id =
nng.node2
_id
JOIN nodes_nodes nn ON nn.node2_id =
cng.node
_id
JOIN nodes n ON nn.node2_id = n.id
JOIN nodes n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? -- toDBid
AND n.typename = ? -- toDBid
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY
nng.node2
_id, ng.terms
GROUP BY
cng.node
_id, ng.terms
ORDER BY (
nng.node2
_id, ng.terms) DESC
ORDER BY (
cng.node
_id, ng.terms) DESC
-- LIMIT ?
-- LIMIT ?
-- OFFSET ?
-- OFFSET ?
|]
|]
...
@@ -143,14 +143,14 @@ getOccByNgramsOnlyFast' cId lId nt tms = trace (show (cId, lId)) $
...
@@ -143,14 +143,14 @@ getOccByNgramsOnlyFast' cId lId nt tms = trace (show (cId, lId)) $
query
::
DPS
.
Query
query
::
DPS
.
Query
query
=
[
sql
|
query
=
[
sql
|
WITH input_rows(terms) AS (?)
WITH input_rows(terms) AS (?)
SELECT ng.terms,
nng.weight FROM node_node_ngrams n
ng
SELECT ng.terms,
cng.weight FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_rows ir ON ir.terms = ng.terms
WHERE
nng.node1
_id = ? -- CorpusId
WHERE
cng.context
_id = ? -- CorpusId
AND
nng.node2
_id = ? -- ListId
AND
cng.node
_id = ? -- ListId
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
-- AND nn.category > 0 -- TODO
-- AND nn.category > 0 -- TODO
GROUP BY ng.terms,
n
ng.weight
GROUP BY ng.terms,
c
ng.weight
|]
|]
...
@@ -210,16 +210,16 @@ selectNgramsOccurrencesOnlyByNodeUser cId nt tms =
...
@@ -210,16 +210,16 @@ selectNgramsOccurrencesOnlyByNodeUser cId nt tms =
queryNgramsOccurrencesOnlyByNodeUser
::
DPS
.
Query
queryNgramsOccurrencesOnlyByNodeUser
::
DPS
.
Query
queryNgramsOccurrencesOnlyByNodeUser
=
[
sql
|
queryNgramsOccurrencesOnlyByNodeUser
=
[
sql
|
WITH input_rows(terms) AS (?)
WITH input_rows(terms) AS (?)
SELECT ng.terms, COUNT(
nng.node2_id) FROM node_node_ngrams n
ng
SELECT ng.terms, COUNT(
cng.node_id) FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_rows ir ON ir.terms = ng.terms
JOIN nodes_nodes nn ON nn.node
2_id = nng.node2
_id
JOIN nodes_nodes nn ON nn.node
_id = cng.node
_id
JOIN nodes n ON nn.node
2
_id = n.id
JOIN nodes n ON nn.node_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? -- toDBid
AND n.typename = ? -- toDBid
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY
nng.node2
_id, ng.terms
GROUP BY
cng.node
_id, ng.terms
|]
|]
...
@@ -249,15 +249,15 @@ queryNgramsOccurrencesOnlyByNodeUser_withSample = [sql|
...
@@ -249,15 +249,15 @@ queryNgramsOccurrencesOnlyByNodeUser_withSample = [sql|
WHERE n.typename = ?
WHERE n.typename = ?
AND nn.node1_id = ?),
AND nn.node1_id = ?),
input_rows(terms) AS (?)
input_rows(terms) AS (?)
SELECT ng.terms, COUNT(
nng.node2_id) FROM node_node_ngrams n
ng
SELECT ng.terms, COUNT(
cng.node_id) FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_rows ir ON ir.terms = ng.terms
JOIN nodes_nodes nn ON nn.node2_id =
nng.node2
_id
JOIN nodes_nodes nn ON nn.node2_id =
cng.node
_id
JOIN nodes_sample n ON nn.node2_id = n.id
JOIN nodes_sample n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY
nng.node2
_id, ng.terms
GROUP BY
cng.node
_id, ng.terms
|]
|]
...
@@ -265,16 +265,16 @@ queryNgramsOccurrencesOnlyByNodeUser_withSample = [sql|
...
@@ -265,16 +265,16 @@ queryNgramsOccurrencesOnlyByNodeUser_withSample = [sql|
queryNgramsOccurrencesOnlyByNodeUser'
::
DPS
.
Query
queryNgramsOccurrencesOnlyByNodeUser'
::
DPS
.
Query
queryNgramsOccurrencesOnlyByNodeUser'
=
[
sql
|
queryNgramsOccurrencesOnlyByNodeUser'
=
[
sql
|
WITH input_rows(terms) AS (?)
WITH input_rows(terms) AS (?)
SELECT ng.terms, COUNT(
nng.node2_id) FROM node_node_ngrams n
ng
SELECT ng.terms, COUNT(
cng.node_id) FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_rows ir ON ir.terms = ng.terms
JOIN nodes_nodes nn ON nn.node2_id =
nng.node2
_id
JOIN nodes_nodes nn ON nn.node2_id =
cng.node
_id
JOIN nodes n ON nn.node2_id = n.id
JOIN nodes n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? -- toDBid
AND n.typename = ? -- toDBid
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY
nng.node2
_id, ng.terms
GROUP BY
cng.node
_id, ng.terms
|]
|]
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -331,17 +331,17 @@ queryNgramsOnlyByNodeUser :: DPS.Query
...
@@ -331,17 +331,17 @@ queryNgramsOnlyByNodeUser :: DPS.Query
queryNgramsOnlyByNodeUser
=
[
sql
|
queryNgramsOnlyByNodeUser
=
[
sql
|
WITH input_rows(terms) AS (?),
WITH input_rows(terms) AS (?),
input_list(id) AS (?)
input_list(id) AS (?)
SELECT ng.terms,
nng.node2_id FROM node_node_ngrams n
ng
SELECT ng.terms,
cng.node_id FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_list il ON il.id =
nng.node1
_id
JOIN input_list il ON il.id =
cng.context
_id
JOIN nodes_nodes nn ON nn.node2_id =
nng.node2
_id
JOIN nodes_nodes nn ON nn.node2_id =
cng.node
_id
JOIN nodes n ON nn.node2_id = n.id
JOIN nodes n ON nn.node2_id = n.id
WHERE nn.node1_id = ? -- CorpusId
WHERE nn.node1_id = ? -- CorpusId
AND n.typename = ? -- toDBid
AND n.typename = ? -- toDBid
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
GROUP BY ng.terms,
nng.node2
_id
GROUP BY ng.terms,
cng.node
_id
|]
|]
...
@@ -367,14 +367,14 @@ queryNgramsOnlyByNodeUser' :: DPS.Query
...
@@ -367,14 +367,14 @@ queryNgramsOnlyByNodeUser' :: DPS.Query
queryNgramsOnlyByNodeUser'
=
[
sql
|
queryNgramsOnlyByNodeUser'
=
[
sql
|
WITH input_rows(terms) AS (?),
WITH input_rows(terms) AS (?),
input_list(id) AS (?)
input_list(id) AS (?)
SELECT ng.terms,
nng.weight FROM node_node_ngrams n
ng
SELECT ng.terms,
cng.weight FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_list il ON il.id =
nng.node2
_id
JOIN input_list il ON il.id =
cng.node
_id
WHERE
nng.node1
_id = ? -- CorpusId
WHERE
cng.context
_id = ? -- CorpusId
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
-- AND nn.category > 0
-- AND nn.category > 0
GROUP BY ng.terms,
n
ng.weight
GROUP BY ng.terms,
c
ng.weight
|]
|]
...
@@ -411,13 +411,13 @@ queryNgramsOnlyByDocUser :: DPS.Query
...
@@ -411,13 +411,13 @@ queryNgramsOnlyByDocUser :: DPS.Query
queryNgramsOnlyByDocUser
=
[
sql
|
queryNgramsOnlyByDocUser
=
[
sql
|
WITH input_rows(terms) AS (?),
WITH input_rows(terms) AS (?),
input_list(id) AS (?)
input_list(id) AS (?)
SELECT ng.terms,
nng.node2_id FROM node_node_ngrams n
ng
SELECT ng.terms,
cng.node_id FROM context_node_ngrams c
ng
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_rows ir ON ir.terms = ng.terms
JOIN input_list il ON il.id =
nng.node1
_id
JOIN input_list il ON il.id =
cng.context
_id
WHERE
nng.node2
_id = ? -- DocId
WHERE
cng.node
_id = ? -- DocId
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
GROUP BY ng.terms,
nng.node2
_id
GROUP BY ng.terms,
cng.node
_id
|]
|]
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -450,18 +450,18 @@ selectNgramsByNodeMaster n ucId mcId p = runPGSQuery
...
@@ -450,18 +450,18 @@ selectNgramsByNodeMaster n ucId mcId p = runPGSQuery
,
ngramsTypeId
NgramsTerms
,
ngramsTypeId
NgramsTerms
)
)
-- | TODO fix
node
_node_ngrams relation
-- | TODO fix
context
_node_ngrams relation
queryNgramsByNodeMaster'
::
DPS
.
Query
queryNgramsByNodeMaster'
::
DPS
.
Query
queryNgramsByNodeMaster'
=
[
sql
|
queryNgramsByNodeMaster'
=
[
sql
|
WITH nodesByNgramsUser AS (
WITH nodesByNgramsUser AS (
SELECT n.id, ng.terms FROM nodes n
SELECT n.id, ng.terms FROM nodes n
JOIN nodes_nodes nn ON n.id = nn.node2_id
JOIN nodes_nodes nn ON n.id = nn.node2_id
JOIN
node_node_ngrams nng ON nng.node2
_id = n.id
JOIN
context_node_ngrams cng ON cng.node
_id = n.id
JOIN ngrams ng ON
n
ng.ngrams_id = ng.id
JOIN ngrams ng ON
c
ng.ngrams_id = ng.id
WHERE nn.node1_id = ? -- UserCorpusId
WHERE nn.node1_id = ? -- UserCorpusId
-- AND n.typename = ? -- toDBid
-- AND n.typename = ? -- toDBid
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
AND nn.category > 0
AND nn.category > 0
AND node_pos(n.id,?) >= ?
AND node_pos(n.id,?) >= ?
AND node_pos(n.id,?) < ?
AND node_pos(n.id,?) < ?
...
@@ -472,12 +472,12 @@ queryNgramsByNodeMaster' = [sql|
...
@@ -472,12 +472,12 @@ queryNgramsByNodeMaster' = [sql|
nodesByNgramsMaster AS (
nodesByNgramsMaster AS (
SELECT n.id, ng.terms FROM nodes n TABLESAMPLE SYSTEM_ROWS(?)
SELECT n.id, ng.terms FROM nodes n TABLESAMPLE SYSTEM_ROWS(?)
JOIN
node_node_ngrams nng ON n.id = nng.node2
_id
JOIN
context_node_ngrams cng ON n.id = cng.node
_id
JOIN ngrams ng ON ng.id =
n
ng.ngrams_id
JOIN ngrams ng ON ng.id =
c
ng.ngrams_id
WHERE n.parent_id = ? -- Master Corpus toDBid
WHERE n.parent_id = ? -- Master Corpus toDBid
AND n.typename = ? -- toDBid
AND n.typename = ? -- toDBid
AND
n
ng.ngrams_type = ? -- NgramsTypeId
AND
c
ng.ngrams_type = ? -- NgramsTypeId
GROUP BY n.id, ng.terms
GROUP BY n.id, ng.terms
)
)
...
...
src/Gargantext/Database/Admin/Trigger/
Node
NodeNgrams.hs
→
src/Gargantext/Database/Admin/Trigger/
Context
NodeNgrams.hs
View file @
156790ff
...
@@ -13,7 +13,7 @@ Triggers on NodeNodeNgrams table.
...
@@ -13,7 +13,7 @@ Triggers on NodeNodeNgrams table.
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE QuasiQuotes #-}
module
Gargantext.Database.Admin.Trigger.
Node
NodeNgrams
module
Gargantext.Database.Admin.Trigger.
Context
NodeNgrams
where
where
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
...
@@ -35,16 +35,16 @@ triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList)
...
@@ -35,16 +35,16 @@ triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList)
RETURN NEW;
RETURN NEW;
END IF;
END IF;
IF TG_OP = 'INSERT' THEN
IF TG_OP = 'INSERT' THEN
INSERT INTO
node_node_ngrams (node1_id, node2
_id, ngrams_id, ngrams_type, weight)
INSERT INTO
context_node_ngrams (context_id, node
_id, ngrams_id, ngrams_type, weight)
select n.parent_id, n.id, new
1.ngrams_id, new1.ngrams_type, count(*) from NEW as new1
select n.parent_id, n.id, new
0.ngrams_id, new0.ngrams_type, count(*) from NEW as new0
INNER JOIN
nodes n ON n.id = new1.node1
_id
INNER JOIN
contexts n ON n.id = new0.context
_id
INNER JOIN nodes n2 ON n2.id = new
1.node2
_id
INNER JOIN nodes n2 ON n2.id = new
0.node
_id
WHERE n2.typename = ? -- not mandatory
WHERE n2.typename = ? -- not mandatory
AND n.typename = ? -- not mandatory
AND n.typename = ? -- not mandatory
AND n.parent_id <> n2.id -- not mandatory
AND n.parent_id <> n2.id -- not mandatory
GROUP BY n.parent_id, n.id, new
1.ngrams_id, new1
.ngrams_type
GROUP BY n.parent_id, n.id, new
0.ngrams_id, new0
.ngrams_type
ON CONFLICT (
node1_id, node2
_id, ngrams_id, ngrams_type)
ON CONFLICT (
context_id, node
_id, ngrams_id, ngrams_type)
DO UPDATE set weight =
node
_node_ngrams.weight + excluded.weight
DO UPDATE set weight =
context
_node_ngrams.weight + excluded.weight
;
;
END IF;
END IF;
...
@@ -52,9 +52,9 @@ triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList)
...
@@ -52,9 +52,9 @@ triggerCountInsert = execPGSQuery query (toDBid NodeDocument, toDBid NodeList)
END
END
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql;
-- DROP trigger trigger_count_insert on
node
_node_ngrams;
-- DROP trigger trigger_count_insert on
context
_node_ngrams;
CREATE TRIGGER trigger_count_insert AFTER INSERT on
node
_node_ngrams
CREATE TRIGGER trigger_count_insert AFTER INSERT on
context
_node_ngrams
REFERENCING NEW TABLE AS NEW
REFERENCING NEW TABLE AS NEW
FOR EACH STATEMENT
FOR EACH STATEMENT
EXECUTE PROCEDURE set_ngrams_global_count();
EXECUTE PROCEDURE set_ngrams_global_count();
...
@@ -74,11 +74,11 @@ triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
...
@@ -74,11 +74,11 @@ triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
RETURN NEW;
RETURN NEW;
END IF;
END IF;
IF TG_OP = 'INSERT' THEN
IF TG_OP = 'INSERT' THEN
INSERT INTO
node_node_ngrams2 (node
_id, nodengrams_id, weight)
INSERT INTO
context_node_ngrams2 (context
_id, nodengrams_id, weight)
SELECT corpus.id, nng.id, count(*) from NEW as new
1
SELECT corpus.id, nng.id, count(*) from NEW as new
3
INNER JOIN node_ngrams nng ON nng.id
= new1
.nodengrams_id
INNER JOIN node_ngrams nng ON nng.id
= new3
.nodengrams_id
INNER JOIN nodes list ON list.id = nng.node_id
INNER JOIN nodes list ON list.id = nng.node_id
INNER JOIN nodes_nodes nn ON nn.node2_id = new
1.node
_id
INNER JOIN nodes_nodes nn ON nn.node2_id = new
3.context
_id
INNER JOIN nodes corpus ON corpus.id = nn.node1_id
INNER JOIN nodes corpus ON corpus.id = nn.node1_id
INNER JOIN nodes doc ON doc.id = nn.node2_id
INNER JOIN nodes doc ON doc.id = nn.node2_id
WHERE corpus.typename = ? -- 30 -- corpus
WHERE corpus.typename = ? -- 30 -- corpus
...
@@ -86,8 +86,8 @@ triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
...
@@ -86,8 +86,8 @@ triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
AND list.typename = ? -- 5 -- list
AND list.typename = ? -- 5 -- list
GROUP BY corpus.id, nng.id
GROUP BY corpus.id, nng.id
ON CONFLICT (
node
_id, nodengrams_id)
ON CONFLICT (
context
_id, nodengrams_id)
DO UPDATE set weight =
node
_node_ngrams2.weight + excluded.weight
DO UPDATE set weight =
context
_node_ngrams2.weight + excluded.weight
;
;
END IF;
END IF;
...
@@ -95,15 +95,16 @@ triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
...
@@ -95,15 +95,16 @@ triggerCountInsert2 = execPGSQuery query ( toDBid NodeCorpus
END
END
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql;
-- DROP trigger trigger_count_insert2 on
node
_node_ngrams2;
-- DROP trigger trigger_count_insert2 on
context
_node_ngrams2;
CREATE TRIGGER trigger_count_insert2 AFTER INSERT on
node
_node_ngrams2
CREATE TRIGGER trigger_count_insert2 AFTER INSERT on
context
_node_ngrams2
REFERENCING NEW TABLE AS NEW
REFERENCING NEW TABLE AS NEW
FOR EACH STATEMENT
FOR EACH STATEMENT
EXECUTE PROCEDURE set_ngrams_global_count2();
EXECUTE PROCEDURE set_ngrams_global_count2();
|]
|]
-- TODO add the groups
-- TODO add the groups
-- TODO use context instead of nodes of type doc
triggerCoocInsert
::
HasDBid
NodeType
=>
Cmd
err
Int64
triggerCoocInsert
::
HasDBid
NodeType
=>
Cmd
err
Int64
triggerCoocInsert
=
execPGSQuery
query
(
toDBid
NodeCorpus
triggerCoocInsert
=
execPGSQuery
query
(
toDBid
NodeCorpus
,
toDBid
NodeDocument
,
toDBid
NodeDocument
...
@@ -122,10 +123,10 @@ triggerCoocInsert = execPGSQuery query ( toDBid NodeCorpus
...
@@ -122,10 +123,10 @@ triggerCoocInsert = execPGSQuery query ( toDBid NodeCorpus
IF TG_OP = 'INSERT' THEN
IF TG_OP = 'INSERT' THEN
INSERT INTO node_nodengrams_nodengrams (node_id, node_ngrams1_id, node_ngrams2_id, weight)
INSERT INTO node_nodengrams_nodengrams (node_id, node_ngrams1_id, node_ngrams2_id, weight)
WITH input(corpus_id, nn1, nn2, weight) AS (
WITH input(corpus_id, nn1, nn2, weight) AS (
SELECT corpus.id, nng1.id, nng2.id, count(*) from NEW as new
1
SELECT corpus.id, nng1.id, nng2.id, count(*) from NEW as new
2
INNER JOIN node_ngrams nng1 ON nng1.id = new
1
.nodengrams_id
INNER JOIN node_ngrams nng1 ON nng1.id = new
2
.nodengrams_id
INNER JOIN nodes list ON list.id = nng1.node_id
INNER JOIN nodes list ON list.id = nng1.node_id
INNER JOIN nodes_nodes nn ON nn.node2_id = new
1
.node_id
INNER JOIN nodes_nodes nn ON nn.node2_id = new
2
.node_id
INNER JOIN nodes corpus ON corpus.id = nn.node1_id
INNER JOIN nodes corpus ON corpus.id = nn.node1_id
INNER JOIN nodes doc ON doc.id = nn.node2_id
INNER JOIN nodes doc ON doc.id = nn.node2_id
...
@@ -159,4 +160,3 @@ triggerCoocInsert = execPGSQuery query ( toDBid NodeCorpus
...
@@ -159,4 +160,3 @@ triggerCoocInsert = execPGSQuery query ( toDBid NodeCorpus
FOR EACH STATEMENT
FOR EACH STATEMENT
EXECUTE PROCEDURE set_cooc();
EXECUTE PROCEDURE set_cooc();
|]
|]
src/Gargantext/Database/Admin/Trigger/Init.hs
View file @
156790ff
...
@@ -17,7 +17,7 @@ module Gargantext.Database.Admin.Trigger.Init
...
@@ -17,7 +17,7 @@ module Gargantext.Database.Admin.Trigger.Init
where
where
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.Database.Admin.Trigger.
Node
NodeNgrams
(
triggerCountInsert
,
triggerCountInsert2
)
import
Gargantext.Database.Admin.Trigger.
Context
NodeNgrams
(
triggerCountInsert
,
triggerCountInsert2
)
import
Gargantext.Database.Admin.Trigger.Nodes
(
triggerSearchUpdate
,
triggerUpdateHash
)
import
Gargantext.Database.Admin.Trigger.Nodes
(
triggerSearchUpdate
,
triggerUpdateHash
)
import
Gargantext.Database.Admin.Trigger.NodesNodes
(
triggerDeleteCount
,
triggerInsertCount
,
triggerUpdateAdd
,
triggerUpdateDel
,
MasterListId
)
-- , triggerCoocInsert)
import
Gargantext.Database.Admin.Trigger.NodesNodes
(
triggerDeleteCount
,
triggerInsertCount
,
triggerUpdateAdd
,
triggerUpdateDel
,
MasterListId
)
-- , triggerCoocInsert)
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Database.Prelude
(
Cmd
)
...
@@ -34,7 +34,7 @@ initLastTriggers lId = do
...
@@ -34,7 +34,7 @@ initLastTriggers lId = do
t0
<-
triggerSearchUpdate
t0
<-
triggerSearchUpdate
t1
<-
triggerCountInsert
t1
<-
triggerCountInsert
t1'
<-
triggerCountInsert2
t1'
<-
triggerCountInsert2
--
t1'' <- triggerCoocInsert lId
--
t1'' <- triggerCoocInsert lId
t2
<-
triggerDeleteCount
lId
t2
<-
triggerDeleteCount
lId
t3
<-
triggerInsertCount
lId
t3
<-
triggerInsertCount
lId
t4
<-
triggerUpdateAdd
lId
t4
<-
triggerUpdateAdd
lId
...
...
src/Gargantext/Database/Admin/Trigger/Nodes.hs
View file @
156790ff
...
@@ -33,7 +33,7 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
...
@@ -33,7 +33,7 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
where
where
query
::
DPS
.
Query
query
::
DPS
.
Query
query
=
[
sql
|
query
=
[
sql
|
-- DROP TRIGGER search_update_trigger on
node
s;
-- DROP TRIGGER search_update_trigger on
context
s;
CREATE OR REPLACE FUNCTION public.search_update()
CREATE OR REPLACE FUNCTION public.search_update()
RETURNS trigger AS $$
RETURNS trigger AS $$
begin
begin
...
@@ -59,11 +59,11 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
...
@@ -59,11 +59,11 @@ triggerSearchUpdate = execPGSQuery query ( toDBid NodeDocument
CREATE TRIGGER search_update_trigger
CREATE TRIGGER search_update_trigger
BEFORE INSERT OR UPDATE
BEFORE INSERT OR UPDATE
ON
node
s FOR EACH ROW
ON
context
s FOR EACH ROW
EXECUTE PROCEDURE search_update();
EXECUTE PROCEDURE search_update();
-- Initialize index with already existing data
-- Initialize index with already existing data
UPDATE
node
s SET hyperdata = hyperdata;
UPDATE
context
s SET hyperdata = hyperdata;
|]
|]
...
@@ -113,6 +113,9 @@ triggerUpdateHash secret = execPGSQuery query ( toDBid NodeDocument
...
@@ -113,6 +113,9 @@ triggerUpdateHash secret = execPGSQuery query ( toDBid NodeDocument
CREATE TRIGGER nodes_hash_insert BEFORE INSERT ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_insert_nodes();
CREATE TRIGGER nodes_hash_insert BEFORE INSERT ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_insert_nodes();
CREATE TRIGGER nodes_hash_update BEFORE UPDATE ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_update_nodes();
CREATE TRIGGER nodes_hash_update BEFORE UPDATE ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_update_nodes();
CREATE TRIGGER contexts_hash_insert BEFORE INSERT ON contexts FOR EACH ROW EXECUTE PROCEDURE hash_insert_nodes();
CREATE TRIGGER contexts_hash_update BEFORE UPDATE ON nodes FOR EACH ROW EXECUTE PROCEDURE hash_update_nodes();
|]
|]
src/Gargantext/Database/Admin/Types/Node.hs
View file @
156790ff
...
@@ -46,13 +46,24 @@ import Text.Read (read)
...
@@ -46,13 +46,24 @@ import Text.Read (read)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
,
wellNamedSchema
)
-- import Gargantext.Database.Prelude (fromField')
-- import Gargantext.Database.Prelude (fromField')
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Context
import
Gargantext.Prelude
import
Gargantext.Prelude
type
UserId
=
Int
type
UserId
=
Int
type
MasterUserId
=
UserId
type
MasterUserId
=
UserId
type
NodeTypeId
=
Int
type
NodeName
=
Text
type
ContextName
=
Text
type
TSVector
=
Text
type
ContextTitle
=
Text
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | NodePoly indicates that Node has a Polymorphism Type
-- | NodePoly indicates that Node has a Polymorphism Type
type
Node
json
=
NodePoly
NodeId
(
Maybe
Hash
)
NodeTypeId
UserId
(
Maybe
ParentId
)
NodeName
UTCTime
json
type
Node
json
=
NodePoly
NodeId
(
Maybe
Hash
)
NodeTypeId
UserId
(
Maybe
ParentId
)
NodeName
UTCTime
json
type
Context
json
=
ContextPoly
NodeId
(
Maybe
Hash
)
NodeTypeId
UserId
(
Maybe
ParentId
)
ContextTitle
UTCTime
json
-- | NodeSearch (queries)
-- | NodeSearch (queries)
-- type NodeSearch json = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json (Maybe TSVector)
-- type NodeSearch json = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json (Maybe TSVector)
...
@@ -120,6 +131,8 @@ instance (Arbitrary nodeId
...
@@ -120,6 +131,8 @@ instance (Arbitrary nodeId
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
instance
(
Arbitrary
hyperdata
instance
(
Arbitrary
hyperdata
,
Arbitrary
nodeId
,
Arbitrary
nodeId
,
Arbitrary
toDBid
,
Arbitrary
toDBid
...
@@ -144,6 +157,47 @@ instance (Arbitrary hyperdata
...
@@ -144,6 +157,47 @@ instance (Arbitrary hyperdata
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
instance
(
Arbitrary
contextId
,
Arbitrary
hashId
,
Arbitrary
toDBid
,
Arbitrary
userId
,
Arbitrary
contextParentId
,
Arbitrary
hyperdata
)
=>
Arbitrary
(
ContextPoly
contextId
hashId
toDBid
userId
contextParentId
ContextName
UTCTime
hyperdata
)
where
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
arbitrary
=
Context
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
instance
(
Arbitrary
hyperdata
,
Arbitrary
contextId
,
Arbitrary
toDBid
,
Arbitrary
userId
,
Arbitrary
contextParentId
)
=>
Arbitrary
(
ContextPolySearch
contextId
toDBid
userId
contextParentId
ContextName
UTCTime
hyperdata
(
Maybe
TSVector
)
)
where
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
arbitrary
=
ContextSearch
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
------------------------------------------------------------------------
------------------------------------------------------------------------
pgNodeId
::
NodeId
->
O
.
Column
O
.
SqlInt4
pgNodeId
::
NodeId
->
O
.
Column
O
.
SqlInt4
pgNodeId
=
O
.
sqlInt4
.
id2int
pgNodeId
=
O
.
sqlInt4
.
id2int
...
@@ -151,9 +205,16 @@ pgNodeId = O.sqlInt4 . id2int
...
@@ -151,9 +205,16 @@ pgNodeId = O.sqlInt4 . id2int
id2int
::
NodeId
->
Int
id2int
::
NodeId
->
Int
id2int
(
NodeId
n
)
=
n
id2int
(
NodeId
n
)
=
n
pgContextId
::
ContextId
->
O
.
Column
O
.
SqlInt4
pgContextId
=
pgNodeId
------------------------------------------------------------------------
------------------------------------------------------------------------
newtype
NodeId
=
NodeId
Int
newtype
NodeId
=
NodeId
Int
deriving
(
Read
,
Generic
,
Num
,
Eq
,
Ord
,
Enum
,
ToJSONKey
,
FromJSONKey
,
ToJSON
,
FromJSON
,
Hashable
,
Csv
.
ToField
)
deriving
(
Read
,
Generic
,
Num
,
Eq
,
Ord
,
Enum
,
ToJSONKey
,
FromJSONKey
,
ToJSON
,
FromJSON
,
Hashable
,
Csv
.
ToField
)
-- TODO make another type?
type
ContextId
=
NodeId
instance
GQLType
NodeId
instance
GQLType
NodeId
instance
Show
NodeId
where
instance
Show
NodeId
where
show
(
NodeId
n
)
=
"nodeId-"
<>
show
n
show
(
NodeId
n
)
=
"nodeId-"
<>
show
n
...
@@ -173,10 +234,6 @@ instance ToSchema NodeId
...
@@ -173,10 +234,6 @@ instance ToSchema NodeId
unNodeId
::
NodeId
->
Int
unNodeId
::
NodeId
->
Int
unNodeId
(
NodeId
n
)
=
n
unNodeId
(
NodeId
n
)
=
n
type
NodeTypeId
=
Int
type
NodeName
=
Text
type
TSVector
=
Text
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
instance
FromHttpApiData
NodeId
where
instance
FromHttpApiData
NodeId
where
...
...
src/Gargantext/Database/Query/Facet.hs
View file @
156790ff
...
@@ -66,9 +66,10 @@ import Gargantext.Database.Admin.Types.Hyperdata
...
@@ -66,9 +66,10 @@ import Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Query.Filter
import
Gargantext.Database.Query.Filter
import
Gargantext.Database.Query.Join
(
leftJoin5
)
import
Gargantext.Database.Query.Join
(
leftJoin5
)
import
Gargantext.Database.Query.Table.Ngrams
import
Gargantext.Database.Query.Table.Ngrams
import
Gargantext.Database.Query.Table.Node
(
queryNodeSearchTable
)
import
Gargantext.Database.Query.Table.Context
import
Gargantext.Database.Query.Table.NodeNode
import
Gargantext.Database.Schema.Context
import
Gargantext.Database.Query.Table.NodeNodeNgrams
import
Gargantext.Database.Query.Table.NodeContext
import
Gargantext.Database.Query.Table.ContextNodeNgrams
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Node
import
Gargantext.Prelude
(
printDebug
)
import
Gargantext.Prelude
(
printDebug
)
...
@@ -242,8 +243,6 @@ instance Arbitrary OrderBy
...
@@ -242,8 +243,6 @@ instance Arbitrary OrderBy
-- TODO-SECURITY check
-- TODO-SECURITY check
--{-
runViewAuthorsDoc
::
HasDBid
NodeType
runViewAuthorsDoc
::
HasDBid
NodeType
=>
ContactId
=>
ContactId
->
IsTrash
->
IsTrash
...
@@ -264,11 +263,6 @@ viewAuthorsDoc :: HasDBid NodeType
...
@@ -264,11 +263,6 @@ viewAuthorsDoc :: HasDBid NodeType
viewAuthorsDoc
cId
_
nt
=
proc
()
->
do
viewAuthorsDoc
cId
_
nt
=
proc
()
->
do
(
doc
,(
_
,(
_
,(
_
,
contact'
))))
<-
queryAuthorsDoc
-<
()
(
doc
,(
_
,(
_
,(
_
,
contact'
))))
<-
queryAuthorsDoc
-<
()
{-nn <- queryNodeNodeTable -< ()
restrict -< nn_node1_id nn .== _node_id doc
-- restrict -< nn_delete nn .== (sqlBool t)
-}
restrict
-<
_node_id
contact'
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
_node_id
contact'
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
_node_typename
doc
.==
(
sqlInt4
$
toDBid
nt
)
restrict
-<
_node_typename
doc
.==
(
sqlInt4
$
toDBid
nt
)
...
@@ -280,26 +274,25 @@ viewAuthorsDoc cId _ nt = proc () -> do
...
@@ -280,26 +274,25 @@ viewAuthorsDoc cId _ nt = proc () -> do
,
facetDoc_ngramCount
=
toNullable
$
sqlDouble
1
,
facetDoc_ngramCount
=
toNullable
$
sqlDouble
1
,
facetDoc_score
=
toNullable
$
sqlDouble
1
}
,
facetDoc_score
=
toNullable
$
sqlDouble
1
}
queryAuthorsDoc
::
Select
(
NodeRead
,
(
NodeNodeNgramsReadNull
,
(
NgramsReadNull
,
(
Node
NodeNgramsReadNull
,
NodeReadNull
))))
queryAuthorsDoc
::
Select
(
NodeRead
,
(
ContextNodeNgramsReadNull
,
(
NgramsReadNull
,
(
Context
NodeNgramsReadNull
,
NodeReadNull
))))
queryAuthorsDoc
=
leftJoin5
queryNodeTable
query
NodeNodeNgramsTable
queryNgramsTable
queryNode
NodeNgramsTable
queryNodeTable
cond12
cond23
cond34
cond45
queryAuthorsDoc
=
leftJoin5
queryNodeTable
query
ContextNodeNgramsTable
queryNgramsTable
queryContext
NodeNgramsTable
queryNodeTable
cond12
cond23
cond34
cond45
where
where
cond12
::
(
Node
NodeNgramsRead
,
NodeRead
)
->
Column
SqlBool
cond12
::
(
Context
NodeNgramsRead
,
NodeRead
)
->
Column
SqlBool
cond12
(
nodeNgram
,
doc
)
=
_node_id
doc
cond12
(
nodeNgram
,
doc
)
=
_node_id
doc
.==
_
nnng_node1
_id
nodeNgram
.==
_
cnng_context
_id
nodeNgram
cond23
::
(
NgramsRead
,
(
Node
NodeNgramsRead
,
NodeReadNull
))
->
Column
SqlBool
cond23
::
(
NgramsRead
,
(
Context
NodeNgramsRead
,
NodeReadNull
))
->
Column
SqlBool
cond23
(
ngrams'
,
(
nodeNgram
,
_
))
=
ngrams'
^.
ngrams_id
cond23
(
ngrams'
,
(
nodeNgram
,
_
))
=
ngrams'
^.
ngrams_id
.==
_
n
nng_ngrams_id
nodeNgram
.==
_
c
nng_ngrams_id
nodeNgram
cond34
::
(
NodeNodeNgramsRead
,
(
NgramsRead
,
(
Node
NodeNgramsReadNull
,
NodeReadNull
)))
->
Column
SqlBool
cond34
::
(
ContextNodeNgramsRead
,
(
NgramsRead
,
(
Context
NodeNgramsReadNull
,
NodeReadNull
)))
->
Column
SqlBool
cond34
(
nodeNgram2
,
(
ngrams'
,
(
_
,
_
)))
=
ngrams'
^.
ngrams_id
.==
_
n
nng_ngrams_id
nodeNgram2
cond34
(
nodeNgram2
,
(
ngrams'
,
(
_
,
_
)))
=
ngrams'
^.
ngrams_id
.==
_
c
nng_ngrams_id
nodeNgram2
cond45
::
(
NodeRead
,
(
NodeNodeNgramsRead
,
(
NgramsReadNull
,
(
Node
NodeNgramsReadNull
,
NodeReadNull
))))
->
Column
SqlBool
cond45
::
(
NodeRead
,
(
ContextNodeNgramsRead
,
(
NgramsReadNull
,
(
Context
NodeNgramsReadNull
,
NodeReadNull
))))
->
Column
SqlBool
cond45
(
contact'
,
(
nodeNgram2'
,
(
_
,
(
_
,
_
))))
=
_node_id
contact'
.==
_
nnng_node1
_id
nodeNgram2'
cond45
(
contact'
,
(
nodeNgram2'
,
(
_
,
(
_
,
_
))))
=
_node_id
contact'
.==
_
cnng_context
_id
nodeNgram2'
--}
------------------------------------------------------------------------
------------------------------------------------------------------------
-- TODO-SECURITY check
-- TODO-SECURITY check
runViewDocuments
::
HasDBid
NodeType
runViewDocuments
::
HasDBid
NodeType
=>
CorpusId
=>
CorpusId
...
@@ -310,29 +303,11 @@ runViewDocuments :: HasDBid NodeType
...
@@ -310,29 +303,11 @@ runViewDocuments :: HasDBid NodeType
->
Maybe
Text
->
Maybe
Text
->
Cmd
err
[
FacetDoc
]
->
Cmd
err
[
FacetDoc
]
runViewDocuments
cId
t
o
l
order
query
=
do
runViewDocuments
cId
t
o
l
order
query
=
do
-- docs <- runPGSQuery viewDocuments'
-- ( cId
-- , ntId
-- , (if t then 0 else 1) :: Int
-- , fromMaybe "" query
-- , fromMaybe "" query)
-- pure $ (\(id, date, name', hyperdata, category, score) -> FacetDoc id date name' hyperdata category score score) <$> docs
printDebug
"[runViewDocuments] sqlQuery"
$
showSql
sqlQuery
printDebug
"[runViewDocuments] sqlQuery"
$
showSql
sqlQuery
runOpaQuery
$
filterWith
o
l
order
sqlQuery
runOpaQuery
$
filterWith
o
l
order
sqlQuery
where
where
ntId
=
toDBid
NodeDocument
ntId
=
toDBid
NodeDocument
sqlQuery
=
viewDocuments
cId
t
ntId
query
sqlQuery
=
viewDocuments
cId
t
ntId
query
-- viewDocuments' :: DPS.Query
-- viewDocuments' = [sql|
-- SELECT n.id, n.date, n.name, n.hyperdata, nn.category, nn.score
-- FROM nodes AS n
-- JOIN nodes_nodes AS nn
-- ON n.id = nn.node2_id
-- WHERE nn.node1_id = ? -- corpusId
-- AND n.typename = ? -- NodeTypeId
-- AND nn.category = ? -- isTrash or not
-- AND (n.search @@ to_tsquery(?) OR ? = '') -- query with an OR hack for empty to_tsquery('') results
-- |]
runCountDocuments
::
HasDBid
NodeType
=>
CorpusId
->
IsTrash
->
Maybe
Text
->
Cmd
err
Int
runCountDocuments
::
HasDBid
NodeType
=>
CorpusId
->
IsTrash
->
Maybe
Text
->
Cmd
err
Int
runCountDocuments
cId
t
mQuery
=
do
runCountDocuments
cId
t
mQuery
=
do
...
@@ -346,53 +321,50 @@ viewDocuments :: CorpusId
...
@@ -346,53 +321,50 @@ viewDocuments :: CorpusId
->
NodeTypeId
->
NodeTypeId
->
Maybe
Text
->
Maybe
Text
->
Select
FacetDocRead
->
Select
FacetDocRead
viewDocuments
cId
t
ntId
mQuery
=
viewDocumentsQuery
cId
t
ntId
mQuery
>>>
proc
(
n
,
nn
)
->
do
viewDocuments
cId
t
ntId
mQuery
=
viewDocumentsQuery
cId
t
ntId
mQuery
>>>
proc
(
c
,
nc
)
->
do
returnA
-<
FacetDoc
{
facetDoc_id
=
_ns_id
n
returnA
-<
FacetDoc
{
facetDoc_id
=
_cs_id
c
,
facetDoc_created
=
_ns_date
n
,
facetDoc_created
=
_cs_date
c
,
facetDoc_title
=
_ns_name
n
,
facetDoc_title
=
_cs_name
c
,
facetDoc_hyperdata
=
_ns_hyperdata
n
,
facetDoc_hyperdata
=
_cs_hyperdata
c
,
facetDoc_category
=
toNullable
$
nn
^.
nn_category
,
facetDoc_category
=
toNullable
$
nc
^.
nc_category
,
facetDoc_ngramCount
=
toNullable
$
nn
^.
nn_score
,
facetDoc_ngramCount
=
toNullable
$
nc
^.
nc_score
,
facetDoc_score
=
toNullable
$
nn
^.
nn_score
}
,
facetDoc_score
=
toNullable
$
nc
^.
nc_score
}
viewDocuments'
::
CorpusId
viewDocuments'
::
CorpusId
->
IsTrash
->
IsTrash
->
NodeTypeId
->
NodeTypeId
->
Maybe
Text
->
Maybe
Text
->
Select
NodeRead
->
Select
NodeRead
viewDocuments'
cId
t
ntId
mQuery
=
viewDocumentsQuery
cId
t
ntId
mQuery
>>>
proc
(
n
,
_nn
)
->
do
viewDocuments'
cId
t
ntId
mQuery
=
viewDocumentsQuery
cId
t
ntId
mQuery
>>>
proc
(
c
,
_nc
)
->
do
returnA
-<
Node
{
_node_id
=
_
ns_id
n
returnA
-<
Node
{
_node_id
=
_
cs_id
c
,
_node_hash_id
=
""
,
_node_hash_id
=
""
,
_node_typename
=
_
ns_typename
n
,
_node_typename
=
_
cs_typename
c
,
_node_user_id
=
_
ns_user_id
n
,
_node_user_id
=
_
cs_user_id
c
,
_node_parent_id
=
-
1
,
_node_parent_id
=
-
1
,
_node_name
=
_ns_name
n
,
_node_name
=
_cs_name
c
,
_node_date
=
_ns_date
n
,
_node_date
=
_cs_date
c
,
_node_hyperdata
=
_ns_hyperdata
n
}
,
_node_hyperdata
=
_cs_hyperdata
c
}
viewDocumentsQuery
::
CorpusId
viewDocumentsQuery
::
CorpusId
->
IsTrash
->
IsTrash
->
NodeTypeId
->
NodeTypeId
->
Maybe
Text
->
Maybe
Text
->
Select
(
NodeSearchRead
,
NodeNode
Read
)
->
Select
(
ContextSearchRead
,
NodeContext
Read
)
viewDocumentsQuery
cId
t
ntId
mQuery
=
proc
()
->
do
viewDocumentsQuery
cId
t
ntId
mQuery
=
proc
()
->
do
n
<-
queryNodeSearchTable
-<
()
c
<-
queryContextSearchTable
-<
()
nn
<-
queryNodeNodeTable
-<
()
nc
<-
queryNodeContextTable
-<
()
restrict
-<
n
^.
ns_id
.==
nn
^.
nn_node2_id
restrict
-<
c
^.
cs_id
.==
nc
^.
nc_context_id
restrict
-<
nn
^.
nn_node1_id
.==
(
pgNodeId
cId
)
restrict
-<
nc
^.
nc_node_id
.==
(
pgNodeId
cId
)
restrict
-<
n
^.
ns_typename
.==
(
sqlInt4
ntId
)
restrict
-<
c
^.
cs_typename
.==
(
sqlInt4
ntId
)
restrict
-<
if
t
then
nn
^.
nn_category
.==
(
sqlInt4
0
)
restrict
-<
if
t
then
nc
^.
nc_category
.==
(
sqlInt4
0
)
else
nn
^.
nn_category
.>=
(
sqlInt4
1
)
else
nc
^.
nc_category
.>=
(
sqlInt4
1
)
let
query
=
(
fromMaybe
""
mQuery
)
let
query
=
(
fromMaybe
""
mQuery
)
-- iLikeQuery = T.intercalate "" ["%", query, "%"]
-- restrict -< (n^.node_name) `ilike` (sqlStrictText iLikeQuery)
restrict
-<
if
query
==
""
restrict
-<
if
query
==
""
then
sqlBool
True
then
sqlBool
True
--else (n^.ns_search) @@ (pgTSQuery (T.unpack query))
else
(
c
^.
cs_search
)
@@
(
plaintoTSQuery
$
T
.
unpack
query
)
else
(
n
^.
ns_search
)
@@
(
plaintoTSQuery
$
T
.
unpack
query
)
returnA
-<
(
c
,
nc
)
returnA
-<
(
n
,
nn
)
------------------------------------------------------------------------
------------------------------------------------------------------------
filterWith
::
(
SqlOrd
date
,
SqlOrd
title
,
SqlOrd
category
,
SqlOrd
score
,
hyperdata
~
Column
SqlJsonb
)
=>
filterWith
::
(
SqlOrd
date
,
SqlOrd
title
,
SqlOrd
category
,
SqlOrd
score
,
hyperdata
~
Column
SqlJsonb
)
=>
...
...
src/Gargantext/Database/Query/Join.hs
View file @
156790ff
...
@@ -77,10 +77,9 @@ leftJoin3 :: ( Default Unpackspec b2 b2
...
@@ -77,10 +77,9 @@ leftJoin3 :: ( Default Unpackspec b2 b2
->
((
b3
,
fieldsR
)
->
Column
SqlBool
)
->
((
b3
,
fieldsR
)
->
Column
SqlBool
)
->
((
fieldsL
,
(
b3
,
b2
))
->
Column
SqlBool
)
->
((
fieldsL
,
(
b3
,
b2
))
->
Column
SqlBool
)
->
Select
(
fieldsL
,
(
b4
,
b5
))
->
Select
(
fieldsL
,
(
b4
,
b5
))
leftJoin3
q1
q2
q3
leftJoin3
q1
q2
q3
cond12
cond23
=
cond12
cond23
=
leftJoin
q3
(
leftJoin
q2
q1
cond12
)
cond23
leftJoin
q3
(
leftJoin
q2
q1
cond12
)
cond23
leftJoin4
::
(
Default
Unpackspec
b2
b2
,
leftJoin4
::
(
Default
Unpackspec
b2
b2
,
...
...
src/Gargantext/Database/Query/Table/Context.hs
0 → 100644
View file @
156790ff
{-|
import Gargantext.Database.Prelude (Cmd, runPGSQuery)
Module : Gargantext.Database.Query.Table.Node
Description : Main Tools of Node to the database
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module
Gargantext.Database.Query.Table.Context
where
import
Control.Arrow
(
returnA
)
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Filter
(
limit'
,
offset'
)
import
Gargantext.Database.Query.Table.Node.Error
import
Gargantext.Database.Schema.Context
import
Gargantext.Prelude
hiding
(
sum
,
head
)
import
Opaleye
hiding
(
FromField
)
import
Prelude
hiding
(
null
,
id
,
map
,
sum
)
queryContextSearchTable
::
Select
ContextSearchRead
queryContextSearchTable
=
selectTable
contextTableSearch
selectContext
::
Column
SqlInt4
->
Select
ContextRead
selectContext
id'
=
proc
()
->
do
row
<-
queryContextTable
-<
()
restrict
-<
_context_id
row
.==
id'
returnA
-<
row
runGetContexts
::
Select
ContextRead
->
Cmd
err
[
Context
HyperdataAny
]
runGetContexts
=
runOpaQuery
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | order by publication date
-- Favorites (Bool), node_ngrams
selectContextsWith
::
HasDBid
NodeType
=>
ParentId
->
Maybe
NodeType
->
Maybe
Offset
->
Maybe
Limit
->
Select
ContextRead
selectContextsWith
parentId
maybeContextType
maybeOffset
maybeLimit
=
--offset' maybeOffset $ limit' maybeLimit $ orderBy (asc (hyperdataDocument_Publication_date . node_hyperdata)) $ selectNodesWith' parentId typeId
limit'
maybeLimit
$
offset'
maybeOffset
$
orderBy
(
asc
_context_id
)
$
selectContextsWith'
parentId
maybeContextType
selectContextsWith'
::
HasDBid
NodeType
=>
ParentId
->
Maybe
NodeType
->
Select
ContextRead
selectContextsWith'
parentId
maybeContextType
=
proc
()
->
do
context'
<-
(
proc
()
->
do
row
@
(
Context
_
_
typeId
_
parentId'
_
_
_
)
<-
queryContextTable
-<
()
restrict
-<
parentId'
.==
(
pgNodeId
parentId
)
let
typeId'
=
maybe
0
toDBid
maybeContextType
restrict
-<
if
typeId'
>
0
then
typeId
.==
(
sqlInt4
(
typeId'
::
Int
))
else
(
sqlBool
True
)
returnA
-<
row
)
-<
()
returnA
-<
context'
------------------------------------------------------------------------
getDocumentsV3WithParentId
::
HasDBid
NodeType
=>
NodeId
->
Cmd
err
[
Context
HyperdataDocumentV3
]
getDocumentsV3WithParentId
n
=
runOpaQuery
$
selectContextsWith'
n
(
Just
NodeDocument
)
-- TODO: merge with getDocumentsWithParentId by having a class IsHyperdataDocument
getDocumentsWithParentId
::
HasDBid
NodeType
=>
NodeId
->
Cmd
err
[
Context
HyperdataDocument
]
getDocumentsWithParentId
n
=
runOpaQuery
$
selectContextsWith'
n
(
Just
NodeDocument
)
------------------------------------------------------------------------
selectContextsWithParentID
::
NodeId
->
Select
ContextRead
selectContextsWithParentID
n
=
proc
()
->
do
row
@
(
Context
_
_
_
_
parent_id
_
_
_
)
<-
queryContextTable
-<
()
restrict
-<
parent_id
.==
(
pgNodeId
n
)
returnA
-<
row
------------------------------------------------------------------------
-- | Example of use:
-- runCmdReplEasy (getNodesWithType NodeList (Proxy :: Proxy HyperdataList))
getContextsWithType
::
(
HasNodeError
err
,
JSONB
a
,
HasDBid
NodeType
)
=>
NodeType
->
proxy
a
->
Cmd
err
[
Context
a
]
getContextsWithType
nt
_
=
runOpaQuery
$
selectContextsWithType
nt
where
selectContextsWithType
::
HasDBid
NodeType
=>
NodeType
->
Select
ContextRead
selectContextsWithType
nt'
=
proc
()
->
do
row
@
(
Context
_
_
tn
_
_
_
_
_
)
<-
queryContextTable
-<
()
restrict
-<
tn
.==
(
sqlInt4
$
toDBid
nt'
)
returnA
-<
row
getContextsIdWithType
::
(
HasNodeError
err
,
HasDBid
NodeType
)
=>
NodeType
->
Cmd
err
[
ContextId
]
getContextsIdWithType
nt
=
do
ns
<-
runOpaQuery
$
selectContextsIdWithType
nt
pure
(
map
NodeId
ns
)
selectContextsIdWithType
::
HasDBid
NodeType
=>
NodeType
->
Select
(
Column
SqlInt4
)
selectContextsIdWithType
nt
=
proc
()
->
do
row
@
(
Context
_
_
tn
_
_
_
_
_
)
<-
queryContextTable
-<
()
restrict
-<
tn
.==
(
sqlInt4
$
toDBid
nt
)
returnA
-<
_context_id
row
------------------------------------------------------------------------
src/Gargantext/Database/Query/Table/ContextNodeNgrams.hs
0 → 100644
View file @
156790ff
{-|
Module : Gargantext.Database.Schema.NodeNodeNgrams
Description : TODO: remove this module and table in database
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Database.Query.Table.ContextNodeNgrams
(
module
Gargantext
.
Database
.
Schema
.
ContextNodeNgrams
,
queryContextNodeNgramsTable
,
insertContextNodeNgrams
)
where
import
Gargantext.Database.Admin.Types.Node
(
pgNodeId
,
pgContextId
)
import
Gargantext.Database.Prelude
(
Cmd
,
mkCmd
)
import
Gargantext.Database.Schema.Ngrams
(
pgNgramsTypeId
)
import
Gargantext.Database.Schema.ContextNodeNgrams
import
Gargantext.Database.Schema.Prelude
import
Prelude
queryContextNodeNgramsTable
::
Query
ContextNodeNgramsRead
queryContextNodeNgramsTable
=
selectTable
contextNodeNgramsTable
-- | Insert utils
insertContextNodeNgrams
::
[
ContextNodeNgrams
]
->
Cmd
err
Int
insertContextNodeNgrams
=
insertContextNodeNgramsW
.
map
(
\
(
ContextNodeNgrams
c
n
ng
nt
w
)
->
ContextNodeNgrams
(
pgContextId
c
)
(
pgNodeId
n
)
(
sqlInt4
ng
)
(
pgNgramsTypeId
nt
)
(
sqlDouble
w
)
)
insertContextNodeNgramsW
::
[
ContextNodeNgramsWrite
]
->
Cmd
err
Int
insertContextNodeNgramsW
nnnw
=
mkCmd
$
\
c
->
fromIntegral
<$>
runInsert_
c
insertNothing
where
insertNothing
=
Insert
{
iTable
=
contextNodeNgramsTable
,
iRows
=
nnnw
,
iReturning
=
rCount
,
iOnConflict
=
(
Just
DoNothing
)
}
src/Gargantext/Database/Query/Table/
Node
NodeNgrams2.hs
→
src/Gargantext/Database/Query/Table/
Context
NodeNgrams2.hs
View file @
156790ff
...
@@ -15,36 +15,36 @@ Portability : POSIX
...
@@ -15,36 +15,36 @@ Portability : POSIX
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Database.Query.Table.
Node
NodeNgrams2
module
Gargantext.Database.Query.Table.
Context
NodeNgrams2
(
module
Gargantext
.
Database
.
Schema
.
Node
NodeNgrams2
(
module
Gargantext
.
Database
.
Schema
.
Context
NodeNgrams2
,
insert
Node
NodeNgrams2
,
insert
Context
NodeNgrams2
)
)
where
where
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Schema.
Node
NodeNgrams2
import
Gargantext.Database.Schema.
Context
NodeNgrams2
import
Gargantext.Database.Admin.Types.Node
(
pgNodeId
)
import
Gargantext.Database.Admin.Types.Node
(
pgNodeId
)
import
Gargantext.Database.Prelude
(
Cmd
,
mkCmd
)
import
Gargantext.Database.Prelude
(
Cmd
,
mkCmd
)
import
Prelude
import
Prelude
_query
NodeNodeNgrams2Table
::
Query
Node
NodeNgrams2Read
_query
ContextNodeNgrams2Table
::
Query
Context
NodeNgrams2Read
_query
NodeNodeNgrams2Table
=
selectTable
node
NodeNgrams2Table
_query
ContextNodeNgrams2Table
=
selectTable
context
NodeNgrams2Table
-- | Insert utils
-- | Insert utils
insert
NodeNodeNgrams2
::
[
Node
NodeNgrams2
]
->
Cmd
err
Int
insert
ContextNodeNgrams2
::
[
Context
NodeNgrams2
]
->
Cmd
err
Int
insert
NodeNodeNgrams2
=
insertNode
NodeNgrams2W
insert
ContextNodeNgrams2
=
insertContext
NodeNgrams2W
.
map
(
\
(
Node
NodeNgrams2
n1
n2
w
)
->
.
map
(
\
(
Context
NodeNgrams2
n1
n2
w
)
->
Node
NodeNgrams2
(
pgNodeId
n1
)
Context
NodeNgrams2
(
pgNodeId
n1
)
(
sqlInt4
n2
)
(
sqlInt4
n2
)
(
sqlDouble
w
)
(
sqlDouble
w
)
)
)
insert
NodeNodeNgrams2W
::
[
Node
NodeNgrams2Write
]
->
Cmd
err
Int
insert
ContextNodeNgrams2W
::
[
Context
NodeNgrams2Write
]
->
Cmd
err
Int
insert
Node
NodeNgrams2W
nnnw
=
insert
Context
NodeNgrams2W
nnnw
=
mkCmd
$
\
c
->
fromIntegral
<$>
runInsert_
c
insertNothing
mkCmd
$
\
c
->
fromIntegral
<$>
runInsert_
c
insertNothing
where
where
insertNothing
=
Insert
{
iTable
=
node
NodeNgrams2Table
insertNothing
=
Insert
{
iTable
=
context
NodeNgrams2Table
,
iRows
=
nnnw
,
iRows
=
nnnw
,
iReturning
=
rCount
,
iReturning
=
rCount
,
iOnConflict
=
(
Just
DoNothing
)
,
iOnConflict
=
(
Just
DoNothing
)
...
...
src/Gargantext/Database/Query/Table/Ngrams.hs
View file @
156790ff
...
@@ -32,7 +32,7 @@ import qualified Data.HashMap.Strict as HashMap
...
@@ -32,7 +32,7 @@ import qualified Data.HashMap.Strict as HashMap
import
Gargantext.Core.Types
import
Gargantext.Core.Types
import
Gargantext.Database.Prelude
(
runOpaQuery
,
Cmd
)
import
Gargantext.Database.Prelude
(
runOpaQuery
,
Cmd
)
import
Gargantext.Database.Prelude
(
runPGSQuery
,
formatPGSQuery
)
import
Gargantext.Database.Prelude
(
runPGSQuery
,
formatPGSQuery
)
import
Gargantext.Database.Query.Table.
Node
NodeNgrams
import
Gargantext.Database.Query.Table.
Context
NodeNgrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Types
import
Gargantext.Database.Types
...
@@ -45,16 +45,16 @@ selectNgramsByDoc :: [ListId] -> DocId -> NgramsType -> Cmd err [Text]
...
@@ -45,16 +45,16 @@ selectNgramsByDoc :: [ListId] -> DocId -> NgramsType -> Cmd err [Text]
selectNgramsByDoc
lIds
dId
nt
=
runOpaQuery
(
query
lIds
dId
nt
)
selectNgramsByDoc
lIds
dId
nt
=
runOpaQuery
(
query
lIds
dId
nt
)
where
where
join
::
Query
(
NgramsRead
,
Node
NodeNgramsReadNull
)
join
::
Query
(
NgramsRead
,
Context
NodeNgramsReadNull
)
join
=
leftJoin
queryNgramsTable
query
Node
NodeNgramsTable
on1
join
=
leftJoin
queryNgramsTable
query
Context
NodeNgramsTable
on1
where
where
on1
(
ng
,
nnng
)
=
ng
^.
ngrams_id
.==
nnng
^.
n
nng_ngrams_id
on1
(
ng
,
cnng
)
=
ng
^.
ngrams_id
.==
cnng
^.
c
nng_ngrams_id
query
cIds'
dId'
nt'
=
proc
()
->
do
query
cIds'
dId'
nt'
=
proc
()
->
do
(
ng
,
n
nng
)
<-
join
-<
()
(
ng
,
c
nng
)
<-
join
-<
()
restrict
-<
foldl
(
\
b
cId
->
((
toNullable
$
pgNodeId
cId
)
.==
nnng
^.
nnng_node1
_id
)
.||
b
)
(
sqlBool
True
)
cIds'
restrict
-<
foldl
(
\
b
cId
->
((
toNullable
$
pgNodeId
cId
)
.==
cnng
^.
cnng_node
_id
)
.||
b
)
(
sqlBool
True
)
cIds'
restrict
-<
(
toNullable
$
pgNodeId
dId'
)
.==
nnng
^.
nnng_node2
_id
restrict
-<
(
toNullable
$
pgNodeId
dId'
)
.==
cnng
^.
cnng_context
_id
restrict
-<
(
toNullable
$
pgNgramsType
nt'
)
.==
nnng
^.
n
nng_ngramsType
restrict
-<
(
toNullable
$
pgNgramsType
nt'
)
.==
cnng
^.
c
nng_ngramsType
returnA
-<
ng
^.
ngrams_terms
returnA
-<
ng
^.
ngrams_terms
...
...
src/Gargantext/Database/Query/Table/Node/Document/Add.hs
View file @
156790ff
...
@@ -54,10 +54,10 @@ inputSqlTypes = ["int4","int4","int4"]
...
@@ -54,10 +54,10 @@ inputSqlTypes = ["int4","int4","int4"]
-- TODO return id of added documents only
-- TODO return id of added documents only
queryAdd
::
Query
queryAdd
::
Query
queryAdd
=
[
sql
|
queryAdd
=
[
sql
|
WITH input_rows(node
1_id,node2
_id,category) AS (?)
WITH input_rows(node
_id,context
_id,category) AS (?)
INSERT INTO nodes_
nodes (node1_id, node2
_id,category)
INSERT INTO nodes_
contexts (node_id, context
_id,category)
SELECT * FROM input_rows
SELECT * FROM input_rows
ON CONFLICT (node
1_id, node2
_id) DO NOTHING -- on unique index
ON CONFLICT (node
_id, context
_id) DO NOTHING -- on unique index
RETURNING 1
RETURNING 1
;
;
|]
|]
...
...
src/Gargantext/Database/Query/Table/Node/Document/Insert.hs
View file @
156790ff
...
@@ -90,7 +90,7 @@ import Database.PostgreSQL.Simple (formatQuery)
...
@@ -90,7 +90,7 @@ import Database.PostgreSQL.Simple (formatQuery)
-- UserId : user who is inserting the documents
-- UserId : user who is inserting the documents
-- ParentId : folder ID which is parent of the inserted documents
-- ParentId : folder ID which is parent of the inserted documents
-- Administrator of the database has to create a uniq index as following SQL command:
-- Administrator of the database has to create a uniq index as following SQL command:
-- `create unique index on
nodes
(typename, parent_id, (hyperdata ->> 'uniqId'));`
-- `create unique index on
contexts table
(typename, parent_id, (hyperdata ->> 'uniqId'));`
insertDb
::
(
InsertDb
a
,
HasDBid
NodeType
)
=>
UserId
->
ParentId
->
[
a
]
->
Cmd
err
[
ReturnId
]
insertDb
::
(
InsertDb
a
,
HasDBid
NodeType
)
=>
UserId
->
ParentId
->
[
a
]
->
Cmd
err
[
ReturnId
]
insertDb
u
p
=
runPGSQuery
queryInsert
.
Only
.
Values
fields
.
map
(
insertDb'
u
p
)
insertDb
u
p
=
runPGSQuery
queryInsert
.
Only
.
Values
fields
.
map
(
insertDb'
u
p
)
where
where
...
@@ -155,7 +155,7 @@ queryInsert :: Query
...
@@ -155,7 +155,7 @@ queryInsert :: Query
queryInsert
=
[
sql
|
queryInsert
=
[
sql
|
WITH input_rows(hash_id,typename,user_id,parent_id,name,date,hyperdata) AS (?)
WITH input_rows(hash_id,typename,user_id,parent_id,name,date,hyperdata) AS (?)
, ins AS (
, ins AS (
INSERT INTO
node
s (hash_id, typename,user_id,parent_id,name,date,hyperdata)
INSERT INTO
context
s (hash_id, typename,user_id,parent_id,name,date,hyperdata)
SELECT * FROM input_rows
SELECT * FROM input_rows
ON CONFLICT (hash_id) DO NOTHING -- on unique index -- this does not return the ids
ON CONFLICT (hash_id) DO NOTHING -- on unique index -- this does not return the ids
RETURNING id,hash_id
RETURNING id,hash_id
...
@@ -170,7 +170,7 @@ queryInsert = [sql|
...
@@ -170,7 +170,7 @@ queryInsert = [sql|
, n.id
, n.id
, hash_id
, hash_id
FROM input_rows
FROM input_rows
JOIN
node
s n USING (hash_id); -- columns of unique index
JOIN
context
s n USING (hash_id); -- columns of unique index
|]
|]
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
src/Gargantext/Database/Query/Table/NodeContext.hs
0 → 100644
View file @
156790ff
{-|
Module : Gargantext.Database.Query.Table.NodeNode
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 FunctionalDependencies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Database.Query.Table.NodeContext
(
module
Gargantext
.
Database
.
Schema
.
NodeContext
,
queryNodeContextTable
,
selectDocsDates
,
selectDocNodes
,
selectDocs
,
nodeContextsCategory
,
nodeContextsScore
,
getNodeContext
,
insertNodeContext
,
deleteNodeContext
,
selectPublicContexts
,
selectCountDocs
)
where
import
Control.Arrow
(
returnA
)
import
Control.Lens
(
view
,
(
^.
))
import
Data.Maybe
(
catMaybes
)
import
Data.Text
(
Text
,
splitOn
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
qualified
Database.PostgreSQL.Simple
as
PGS
(
Query
,
Only
(
..
))
import
qualified
Opaleye
as
O
import
Opaleye
import
Gargantext.Core
import
Gargantext.Core.Types
import
Gargantext.Database.Schema.NodeContext
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Prelude
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Context
import
Gargantext.Prelude
queryNodeContextTable
::
Select
NodeContextRead
queryNodeContextTable
=
selectTable
nodeContextTable
-- | not optimized (get all ngrams without filters)
_nodesContexts
::
Cmd
err
[
NodeContext
]
_nodesContexts
=
runOpaQuery
queryNodeContextTable
------------------------------------------------------------------------
-- | Basic NodeContext tools
getNodeContext
::
NodeId
->
Cmd
err
[
NodeContext
]
getNodeContext
n
=
runOpaQuery
(
selectNodeContext
$
pgNodeId
n
)
where
selectNodeContext
::
Column
SqlInt4
->
Select
NodeContextRead
selectNodeContext
n'
=
proc
()
->
do
ns
<-
queryNodeContextTable
-<
()
restrict
-<
_nc_node_id
ns
.==
n'
returnA
-<
ns
------------------------------------------------------------------------
insertNodeContext
::
[
NodeContext
]
->
Cmd
err
Int
insertNodeContext
ns
=
mkCmd
$
\
conn
->
fromIntegral
<$>
(
runInsert_
conn
$
Insert
nodeContextTable
ns'
rCount
(
Just
DoNothing
))
where
ns'
::
[
NodeContextWrite
]
ns'
=
map
(
\
(
NodeContext
n
c
x
y
)
->
NodeContext
(
pgNodeId
n
)
(
pgNodeId
c
)
(
sqlDouble
<$>
x
)
(
sqlInt4
<$>
y
)
)
ns
------------------------------------------------------------------------
type
Node_Id
=
NodeId
type
Context_Id
=
NodeId
deleteNodeContext
::
Node_Id
->
Context_Id
->
Cmd
err
Int
deleteNodeContext
n
c
=
mkCmd
$
\
conn
->
fromIntegral
<$>
runDelete_
conn
(
Delete
nodeContextTable
(
\
(
NodeContext
n_id
c_id
_
_
)
->
n_id
.==
pgNodeId
n
.&&
c_id
.==
pgNodeId
c
)
rCount
)
------------------------------------------------------------------------
-- | Favorite management
_nodeContextCategory
::
CorpusId
->
DocId
->
Int
->
Cmd
err
[
Int
]
_nodeContextCategory
cId
dId
c
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
favQuery
(
c
,
cId
,
dId
)
where
favQuery
::
PGS
.
Query
favQuery
=
[
sql
|
UPDATE nodes_contexts SET category = ?
WHERE node_id = ? AND context_id = ?
RETURNING context_id;
|]
nodeContextsCategory
::
[(
CorpusId
,
DocId
,
Int
)]
->
Cmd
err
[
Int
]
nodeContextsCategory
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
catQuery
(
PGS
.
Only
$
Values
fields
inputData
)
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
[
"int4"
,
"int4"
,
"int4"
]
catQuery
::
PGS
.
Query
catQuery
=
[
sql
|
UPDATE nodes_contexts as nn0
SET category = nn1.category
FROM (?) as nn1(node_id,context_id,category)
WHERE nn0.node1_id = nn1.node_id
AND nn0.node2_id = nn1.context_id
RETURNING nn1.context_id
|]
------------------------------------------------------------------------
-- | Score management
_nodeContextScore
::
CorpusId
->
DocId
->
Int
->
Cmd
err
[
Int
]
_nodeContextScore
cId
dId
c
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
scoreQuery
(
c
,
cId
,
dId
)
where
scoreQuery
::
PGS
.
Query
scoreQuery
=
[
sql
|
UPDATE nodes_contexts SET score = ?
WHERE node_id = ? AND context_id = ?
RETURNING context_id;
|]
nodeContextsScore
::
[(
CorpusId
,
DocId
,
Int
)]
->
Cmd
err
[
Int
]
nodeContextsScore
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
catScore
(
PGS
.
Only
$
Values
fields
inputData
)
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
[
"int4"
,
"int4"
,
"int4"
]
catScore
::
PGS
.
Query
catScore
=
[
sql
|
UPDATE nodes_contexts as nn0
SET score = nn1.score
FROM (?) as nn1(node_id, context_id, score)
WHERE nn0.node_id = nn1.node_id
AND nn0.context_id = nn1.context_id
RETURNING nn1.context_id
|]
------------------------------------------------------------------------
selectCountDocs
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
Int
selectCountDocs
cId
=
runCountOpaQuery
(
queryCountDocs
cId
)
where
queryCountDocs
cId'
=
proc
()
->
do
(
c
,
nc
)
<-
joinInCorpus
-<
()
restrict
-<
nc
^.
nc_node_id
.==
(
toNullable
$
pgNodeId
cId'
)
restrict
-<
nc
^.
nc_category
.>=
(
toNullable
$
sqlInt4
1
)
restrict
-<
c
^.
context_typename
.==
(
sqlInt4
$
toDBid
NodeDocument
)
returnA
-<
c
-- | TODO use UTCTime fast
selectDocsDates
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
[
Text
]
selectDocsDates
cId
=
map
(
head'
"selectDocsDates"
.
splitOn
"-"
)
<$>
catMaybes
<$>
map
(
view
hd_publication_date
)
<$>
selectDocs
cId
selectDocs
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
[
HyperdataDocument
]
selectDocs
cId
=
runOpaQuery
(
queryDocs
cId
)
queryDocs
::
HasDBid
NodeType
=>
CorpusId
->
O
.
Select
(
Column
SqlJsonb
)
queryDocs
cId
=
proc
()
->
do
(
c
,
nn
)
<-
joinInCorpus
-<
()
restrict
-<
nn
^.
nc_node_id
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
nn
^.
nc_category
.>=
(
toNullable
$
sqlInt4
1
)
restrict
-<
c
^.
context_typename
.==
(
sqlInt4
$
toDBid
NodeDocument
)
returnA
-<
view
(
context_hyperdata
)
c
selectDocNodes
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
[
Context
HyperdataDocument
]
selectDocNodes
cId
=
runOpaQuery
(
queryDocNodes
cId
)
queryDocNodes
::
HasDBid
NodeType
=>
CorpusId
->
O
.
Select
ContextRead
queryDocNodes
cId
=
proc
()
->
do
(
c
,
nc
)
<-
joinInCorpus
-<
()
restrict
-<
nc
^.
nc_node_id
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
nc
^.
nc_category
.>=
(
toNullable
$
sqlInt4
1
)
restrict
-<
c
^.
context_typename
.==
(
sqlInt4
$
toDBid
NodeDocument
)
returnA
-<
c
joinInCorpus
::
O
.
Select
(
ContextRead
,
NodeContextReadNull
)
joinInCorpus
=
leftJoin
queryContextTable
queryNodeContextTable
cond
where
cond
::
(
ContextRead
,
NodeContextRead
)
->
Column
SqlBool
cond
(
c
,
nc
)
=
c
^.
context_id
.==
nc
^.
nc_node_id
joinOn1
::
O
.
Select
(
NodeRead
,
NodeContextReadNull
)
joinOn1
=
leftJoin
queryNodeTable
queryNodeContextTable
cond
where
cond
::
(
NodeRead
,
NodeContextRead
)
->
Column
SqlBool
cond
(
n
,
nc
)
=
nc
^.
nc_node_id
.==
n
^.
node_id
------------------------------------------------------------------------
selectPublicContexts
::
HasDBid
NodeType
=>
(
Hyperdata
a
,
DefaultFromField
SqlJsonb
a
)
=>
Cmd
err
[(
Node
a
,
Maybe
Int
)]
selectPublicContexts
=
runOpaQuery
(
queryWithType
NodeFolderPublic
)
queryWithType
::
HasDBid
NodeType
=>
NodeType
->
O
.
Select
(
NodeRead
,
Column
(
Nullable
SqlInt4
))
queryWithType
nt
=
proc
()
->
do
(
n
,
nc
)
<-
joinOn1
-<
()
restrict
-<
n
^.
node_typename
.==
(
sqlInt4
$
toDBid
nt
)
returnA
-<
(
n
,
nc
^.
nc_context_id
)
src/Gargantext/Database/Schema/Context.hs
0 → 100644
View file @
156790ff
{-|
Module : Gargantext.Database.Schema.Node
Description : Main requests of Node to the database
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module
Gargantext.Database.Schema.Context
where
import
Control.Lens
hiding
(
elements
,
(
&
),
Context
)
import
Gargantext.Database.Schema.Prelude
import
Prelude
hiding
(
null
,
id
,
map
,
sum
)
------------------------------------------------------------------------
-- Main polymorphic Node definition
data
ContextPoly
id
hash_id
typename
user_id
parent_id
name
date
hyperdata
=
Context
{
_context_id
::
!
id
,
_context_hash_id
::
!
hash_id
,
_context_typename
::
!
typename
,
_context_user_id
::
!
user_id
,
_context_parent_id
::
!
parent_id
,
_context_name
::
!
name
,
_context_date
::
!
date
,
_context_hyperdata
::
!
hyperdata
}
deriving
(
Show
,
Generic
)
------------------------------------------------------------------------
-- Automatic instances derivation
$
(
deriveJSON
(
unPrefix
"_context_"
)
''
C
ontextPoly
)
$
(
makeLenses
''
C
ontextPoly
)
$
(
makeAdaptorAndInstance
"pContext"
''
C
ontextPoly
)
$
(
makeLensesWith
abbreviatedFields
''
C
ontextPoly
)
contextTable
::
Table
ContextWrite
ContextRead
contextTable
=
Table
"contexts"
(
pContext
Context
{
_context_id
=
optionalTableField
"id"
,
_context_hash_id
=
optionalTableField
"hash_id"
,
_context_typename
=
requiredTableField
"typename"
,
_context_user_id
=
requiredTableField
"user_id"
,
_context_parent_id
=
optionalTableField
"parent_id"
,
_context_name
=
requiredTableField
"name"
,
_context_date
=
optionalTableField
"date"
,
_context_hyperdata
=
requiredTableField
"hyperdata"
-- ignoring ts_vector field here
}
)
queryContextTable
::
Query
ContextRead
queryContextTable
=
selectTable
contextTable
------------------------------------------------------------------------
type
ContextWrite
=
ContextPoly
(
Maybe
(
Column
SqlInt4
)
)
(
Maybe
(
Column
SqlText
)
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Maybe
(
Column
SqlInt4
)
)
(
Column
SqlText
)
(
Maybe
(
Column
SqlTimestamptz
))
(
Column
SqlJsonb
)
type
ContextRead
=
ContextPoly
(
Column
SqlInt4
)
(
Column
SqlText
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlText
)
(
Column
SqlTimestamptz
)
(
Column
SqlJsonb
)
type
ContextReadNull
=
ContextPoly
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlText
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlText
))
(
Column
(
Nullable
SqlTimestamptz
))
(
Column
(
Nullable
SqlJsonb
))
------------------------------------------------------------------------
-- | Context(Read|Write)Search is slower than Context(Write|Read) use it
-- for full text search only
type
ContextSearchWrite
=
ContextPolySearch
(
Maybe
(
Column
SqlInt4
)
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
(
Nullable
SqlInt4
)
)
(
Column
SqlText
)
(
Maybe
(
Column
SqlTimestamptz
))
(
Column
SqlJsonb
)
(
Maybe
(
Column
SqlTSVector
)
)
type
ContextSearchRead
=
ContextPolySearch
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
(
Nullable
SqlInt4
))
(
Column
SqlText
)
(
Column
SqlTimestamptz
)
(
Column
SqlJsonb
)
(
Column
SqlTSVector
)
type
ContextSearchReadNull
=
ContextPolySearch
(
Column
(
Nullable
SqlInt4
)
)
(
Column
(
Nullable
SqlInt4
)
)
(
Column
(
Nullable
SqlInt4
)
)
(
Column
(
Nullable
SqlInt4
)
)
(
Column
(
Nullable
SqlText
)
)
(
Column
(
Nullable
SqlTimestamptz
))
(
Column
(
Nullable
SqlJsonb
)
)
(
Column
(
Nullable
SqlTSVector
)
)
data
ContextPolySearch
id
typename
user_id
parent_id
name
date
hyperdata
search
=
ContextSearch
{
_cs_id
::
id
,
_cs_typename
::
typename
,
_cs_user_id
::
user_id
-- , ContextUniqId :: shaId
,
_cs_parent_id
::
parent_id
,
_cs_name
::
name
,
_cs_date
::
date
,
_cs_hyperdata
::
hyperdata
,
_cs_search
::
search
}
deriving
(
Show
,
Generic
)
$
(
makeAdaptorAndInstance
"pContextSearch"
''
C
ontextPolySearch
)
$
(
makeLensesWith
abbreviatedFields
''
C
ontextPolySearch
)
$
(
deriveJSON
(
unPrefix
"_cs_"
)
''
C
ontextPolySearch
)
$
(
makeLenses
''
C
ontextPolySearch
)
contextTableSearch
::
Table
ContextSearchWrite
ContextSearchRead
contextTableSearch
=
Table
"contexts"
(
pContextSearch
ContextSearch
{
_cs_id
=
optionalTableField
"id"
,
_cs_typename
=
requiredTableField
"typename"
,
_cs_user_id
=
requiredTableField
"user_id"
,
_cs_parent_id
=
requiredTableField
"parent_id"
,
_cs_name
=
requiredTableField
"name"
,
_cs_date
=
optionalTableField
"date"
,
_cs_hyperdata
=
requiredTableField
"hyperdata"
,
_cs_search
=
optionalTableField
"search"
}
)
------------------------------------------------------------------------
src/Gargantext/Database/Schema/ContextNodeNgrams.hs
0 → 100644
View file @
156790ff
{-|
Module : Gargantext.Database.Schema.NodeNodeNgrams
Description : TODO: remove this module and table in database
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Database.Schema.ContextNodeNgrams
where
import
Prelude
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Schema.Ngrams
(
NgramsTypeId
,
NgramsId
)
import
Gargantext.Database.Admin.Types.Node
type
ContextNodeNgrams
=
ContextNodeNgramsPoly
ContextId
ListId
NgramsId
NgramsTypeId
Double
data
ContextNodeNgramsPoly
c
n
ngrams_id
ngt
w
=
ContextNodeNgrams
{
_cnng_context_id
::
!
c
,
_cnng_node_id
::
!
n
,
_cnng_ngrams_id
::
!
ngrams_id
,
_cnng_ngramsType
::
!
ngt
,
_cnng_weight
::
!
w
}
deriving
(
Show
)
type
ContextNodeNgramsWrite
=
ContextNodeNgramsPoly
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlFloat8
)
type
ContextNodeNgramsRead
=
ContextNodeNgramsPoly
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlFloat8
)
type
ContextNodeNgramsReadNull
=
ContextNodeNgramsPoly
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlFloat8
))
$
(
makeAdaptorAndInstance
"pContextNodeNgrams"
''
C
ontextNodeNgramsPoly
)
makeLenses
''
C
ontextNodeNgramsPoly
contextNodeNgramsTable
::
Table
ContextNodeNgramsWrite
ContextNodeNgramsRead
contextNodeNgramsTable
=
Table
"context_node_ngrams"
(
pContextNodeNgrams
ContextNodeNgrams
{
_cnng_context_id
=
requiredTableField
"context_id"
,
_cnng_node_id
=
requiredTableField
"node_id"
,
_cnng_ngrams_id
=
requiredTableField
"ngrams_id"
,
_cnng_ngramsType
=
requiredTableField
"ngrams_type"
,
_cnng_weight
=
requiredTableField
"weight"
}
)
src/Gargantext/Database/Schema/ContextNodeNgrams2.hs
0 → 100644
View file @
156790ff
{-|
Module : Gargantext.Database.Schema.NodeNodeNgrams
Description : TODO: remove this module and table in database
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Database.Schema.ContextNodeNgrams2
where
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Schema.NodeNgrams
(
NodeNgramsId
)
import
Gargantext.Database.Schema.Prelude
import
Prelude
type
ContextNodeNgrams2
=
ContextNodeNgrams2Poly
ContextId
NodeNgramsId
Weight
type
Weight
=
Double
data
ContextNodeNgrams2Poly
context_id
nodengrams_id
w
=
ContextNodeNgrams2
{
_cnng2_context_id
::
!
context_id
,
_cnng2_nodengrams_id
::
!
nodengrams_id
,
_cnng2_weight
::
!
w
}
deriving
(
Show
)
type
ContextNodeNgrams2Write
=
ContextNodeNgrams2Poly
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlFloat8
)
type
ContextNodeNgrams2Read
=
ContextNodeNgrams2Poly
(
Column
SqlInt4
)
(
Column
SqlInt4
)
(
Column
SqlFloat8
)
type
ContextNodeNgrams2ReadNull
=
ContextNodeNgrams2Poly
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlFloat8
))
$
(
makeAdaptorAndInstance
"pContextNodeNgrams2"
''
C
ontextNodeNgrams2Poly
)
makeLenses
''
C
ontextNodeNgrams2Poly
contextNodeNgrams2Table
::
Table
ContextNodeNgrams2Write
ContextNodeNgrams2Read
contextNodeNgrams2Table
=
Table
"context_node_ngrams2"
(
pContextNodeNgrams2
ContextNodeNgrams2
{
_cnng2_context_id
=
requiredTableField
"context_id"
,
_cnng2_nodengrams_id
=
requiredTableField
"nodengrams_id"
,
_cnng2_weight
=
requiredTableField
"weight"
}
)
src/Gargantext/Database/Schema/NgramsPostag.hs
View file @
156790ff
{-|
{-|
Module : Gargantext.Database.Schema.NgramsPostag
Module : Gargantext.Database.Schema.NgramsPostag
Description : Ngram connection to the Database
Description : Ngram
s
connection to the Database
Copyright : (c) CNRS, 2017-Present
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Maintainer : team@gargantext.org
...
@@ -26,6 +26,7 @@ import Gargantext.Database.Schema.Prelude
...
@@ -26,6 +26,7 @@ import Gargantext.Database.Schema.Prelude
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Database.PostgreSQL.Simple
as
PGS
import
qualified
Database.PostgreSQL.Simple
as
PGS
data
NgramsPostagPoly
id
data
NgramsPostagPoly
id
lang_id
lang_id
algo_id
algo_id
...
...
src/Gargantext/Database/Schema/NodeContext.hs
0 → 100644
View file @
156790ff
{-|
Module : Gargantext.Database.Schema.NodeNode
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 FunctionalDependencies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module
Gargantext.Database.Schema.NodeContext
where
import
Gargantext.Core.Types
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Schema.NodeNode
()
-- Just importing some instances
import
Gargantext.Prelude
data
NodeContextPoly
node_id
context_id
score
cat
=
NodeContext
{
_nc_node_id
::
!
node_id
,
_nc_context_id
::
!
context_id
,
_nc_score
::
!
score
,
_nc_category
::
!
cat
}
deriving
(
Show
)
type
NodeContextWrite
=
NodeContextPoly
(
Column
(
SqlInt4
))
(
Column
(
SqlInt4
))
(
Maybe
(
Column
(
SqlFloat8
)))
(
Maybe
(
Column
(
SqlInt4
)))
type
NodeContextRead
=
NodeContextPoly
(
Column
(
SqlInt4
))
(
Column
(
SqlInt4
))
(
Column
(
SqlFloat8
))
(
Column
(
SqlInt4
))
type
NodeContextReadNull
=
NodeContextPoly
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlInt4
))
(
Column
(
Nullable
SqlFloat8
))
(
Column
(
Nullable
SqlInt4
))
type
NodeContext
=
NodeContextPoly
NodeId
NodeId
(
Maybe
Double
)
(
Maybe
Int
)
$
(
makeAdaptorAndInstance
"pNodeContext"
''
N
odeContextPoly
)
makeLenses
''
N
odeContextPoly
nodeContextTable
::
Table
NodeContextWrite
NodeContextRead
nodeContextTable
=
Table
"nodes_contexts"
(
pNodeContext
NodeContext
{
_nc_node_id
=
requiredTableField
"node_id"
,
_nc_context_id
=
requiredTableField
"context_id"
,
_nc_score
=
optionalTableField
"score"
,
_nc_category
=
optionalTableField
"category"
}
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment