Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
haskell-gargantext
Commits
4e3342db
Commit
4e3342db
authored
Jan 17, 2022
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] Counts in NgramsTable and context_node_ngrams insertion
parent
25b81234
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
53 deletions
+37
-53
schema.sql
devops/postgres/schema.sql
+3
-3
Flow.hs
src/Gargantext/Database/Action/Flow.hs
+2
-5
Utils.hs
src/Gargantext/Database/Action/Flow/Utils.hs
+15
-28
NodesNodes.hs
src/Gargantext/Database/Admin/Trigger/NodesNodes.hs
+9
-9
Add.hs
src/Gargantext/Database/Query/Table/Node/Document/Add.hs
+8
-8
No files found.
devops/postgres/schema.sql
View file @
4e3342db
...
@@ -147,9 +147,9 @@ ALTER TABLE public.nodes_contexts OWNER TO gargantua;
...
@@ -147,9 +147,9 @@ ALTER TABLE public.nodes_contexts OWNER TO gargantua;
---------------------------------------------------------------
---------------------------------------------------------------
CREATE
TABLE
public
.
context_node_ngrams
(
CREATE
TABLE
public
.
context_node_ngrams
(
context_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
context_id
INTEGER
NOT
NULL
REFERENCES
public
.
contexts
(
id
)
ON
DELETE
CASCADE
,
node_id
INTEGER
NOT
NULL
REFERENCES
public
.
contexts
(
id
)
ON
DELETE
CASCADE
,
node_id
INTEGER
NOT
NULL
REFERENCES
public
.
nodes
(
id
)
ON
DELETE
CASCADE
,
ngrams_id
INTEGER
NOT
NULL
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
,
ngrams_id
INTEGER
NOT
NULL
REFERENCES
public
.
ngrams
(
id
)
ON
DELETE
CASCADE
,
ngrams_type
INTEGER
,
ngrams_type
INTEGER
,
weight
double
precision
,
weight
double
precision
,
PRIMARY
KEY
(
context_id
,
node_id
,
ngrams_id
,
ngrams_type
)
PRIMARY
KEY
(
context_id
,
node_id
,
ngrams_id
,
ngrams_type
)
...
...
src/Gargantext/Database/Action/Flow.hs
View file @
4e3342db
...
@@ -321,9 +321,6 @@ saveDocNgramsWith lId mapNgramsDocs' = do
...
@@ -321,9 +321,6 @@ saveDocNgramsWith lId mapNgramsDocs' = do
terms2id
<-
insertExtractedNgrams
$
HashMap
.
keys
mapNgramsDocs'
terms2id
<-
insertExtractedNgrams
$
HashMap
.
keys
mapNgramsDocs'
let
mapNgramsDocs
=
HashMap
.
mapKeys
extracted2ngrams
mapNgramsDocs'
let
mapNgramsDocs
=
HashMap
.
mapKeys
extracted2ngrams
mapNgramsDocs'
-- to be removed
let
indexedNgrams
=
HashMap
.
mapKeys
(
indexNgrams
terms2id
)
mapNgramsDocs
-- new
-- new
mapCgramsId
<-
listInsertDb
lId
toNodeNgramsW'
mapCgramsId
<-
listInsertDb
lId
toNodeNgramsW'
$
map
(
first
_ngramsTerms
.
second
Map
.
keys
)
$
map
(
first
_ngramsTerms
.
second
Map
.
keys
)
...
@@ -341,7 +338,7 @@ saveDocNgramsWith lId mapNgramsDocs' = do
...
@@ -341,7 +338,7 @@ saveDocNgramsWith lId mapNgramsDocs' = do
]
]
-- to be removed
-- to be removed
_
<-
insertDocNgrams
lId
indexedNgram
s
_
<-
insertDocNgrams
lId
$
HashMap
.
mapKeys
(
indexNgrams
terms2id
)
mapNgramsDoc
s
pure
()
pure
()
...
@@ -355,7 +352,7 @@ insertDocs :: ( FlowCmdM env err m
...
@@ -355,7 +352,7 @@ insertDocs :: ( FlowCmdM env err m
=>
UserId
=>
UserId
->
CorpusId
->
CorpusId
->
[
a
]
->
[
a
]
->
m
([
DocId
],
[
Indexed
Node
Id
a
])
->
m
([
ContextId
],
[
Indexed
Context
Id
a
])
insertDocs
uId
cId
hs
=
do
insertDocs
uId
cId
hs
=
do
let
docs
=
map
addUniqId
hs
let
docs
=
map
addUniqId
hs
newIds
<-
insertDb
uId
cId
docs
newIds
<-
insertDb
uId
cId
docs
...
...
src/Gargantext/Database/Action/Flow/Utils.hs
View file @
4e3342db
...
@@ -21,6 +21,7 @@ import Gargantext.Database.Query.Table.ContextNodeNgrams
...
@@ -21,6 +21,7 @@ import Gargantext.Database.Query.Table.ContextNodeNgrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Types
import
Gargantext.Database.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Control.Lens
((
^.
))
import
qualified
Data.Map
as
DM
import
qualified
Data.Map
as
DM
import
qualified
Data.HashMap.Strict
as
HashMap
import
qualified
Data.HashMap.Strict
as
HashMap
...
@@ -31,35 +32,21 @@ data DocumentIdWithNgrams a b =
...
@@ -31,35 +32,21 @@ data DocumentIdWithNgrams a b =
,
documentNgrams
::
HashMap
b
(
Map
NgramsType
Int
)
,
documentNgrams
::
HashMap
b
(
Map
NgramsType
Int
)
}
deriving
(
Show
)
}
deriving
(
Show
)
docNgrams2contextNodeNgrams
::
ListId
insertDocNgrams
::
ListId
->
DocNgrams
->
HashMap
(
Indexed
NgramsId
Ngrams
)
(
Map
NgramsType
(
Map
DocId
Int
))
->
ContextNodeNgrams
->
Cmd
err
Int
docNgrams2contextNodeNgrams
lId
(
DocNgrams
d
n
nt
w
)
=
insertDocNgrams
lId
m
=
insertContextNodeNgrams
ns
ContextNodeNgrams
d
lId
n
nt
w
where
ns
=
[
ContextNodeNgrams
docId
lId
(
ng
^.
index
)
(
ngramsTypeId
t
)
(
fromIntegral
i
)
|
(
ng
,
t2n2i
)
<-
HashMap
.
toList
m
,
(
t
,
n2i
)
<-
DM
.
toList
t2n2i
,
(
docId
,
i
)
<-
DM
.
toList
n2i
]
data
DocNgrams
=
DocNgrams
{
dn_doc_id
::
DocId
,
dn_ngrams_id
::
Int
,
dn_ngrams_type
::
NgramsTypeId
,
dn_weight
::
Double
}
insertDocNgramsOn
::
ListId
->
[
DocNgrams
]
->
Cmd
err
Int
insertDocNgramsOn
cId
dn
=
insertContextNodeNgrams
$
(
map
(
docNgrams2contextNodeNgrams
cId
)
dn
)
insertDocNgrams
::
ListId
->
HashMap
(
Indexed
Int
Ngrams
)
(
Map
NgramsType
(
Map
DocId
Int
))
->
Cmd
err
Int
insertDocNgrams
cId
m
=
insertDocNgramsOn
cId
[
DocNgrams
{
dn_doc_id
=
n
,
dn_ngrams_id
=
_index
ng
,
dn_ngrams_type
=
ngramsTypeId
t
,
dn_weight
=
fromIntegral
i
}
|
(
ng
,
t2n2i
)
<-
HashMap
.
toList
m
,
(
t
,
n2i
)
<-
DM
.
toList
t2n2i
,
(
n
,
i
)
<-
DM
.
toList
n2i
]
src/Gargantext/Database/Admin/Trigger/NodesNodes.hs
View file @
4e3342db
...
@@ -66,16 +66,16 @@ triggerUpdateAdd lId = execPGSQuery query (lId, nodeTypeId NodeList)
...
@@ -66,16 +66,16 @@ triggerUpdateAdd lId = execPGSQuery query (lId, nodeTypeId NodeList)
CREATE OR REPLACE FUNCTION set_update_ngrams_add() RETURNS trigger AS $$
CREATE OR REPLACE FUNCTION set_update_ngrams_add() RETURNS trigger AS $$
BEGIN
BEGIN
UPDATE node_node_ngrams nnn0 SET weight = weight + d.fix_count
UPDATE node_node_ngrams nnn0 SET weight = weight + d.fix_count
FROM ( SELECT lists.parent_id
as
node1_id
FROM ( SELECT lists.parent_id
AS
node1_id
, lists.id
as
node2_id
, lists.id
AS
node2_id
,
nnn.ngrams_id as
ngrams_id
,
cnn.ngrams_id AS
ngrams_id
,
nnn.ngrams_type as
ngrams_type
,
cnn.ngrams_type AS
ngrams_type
, count(*)
as
fix_count
, count(*)
AS
fix_count
FROM NEW as new1
FROM NEW as new1
INNER JOIN contexts doc ON doc.id = new1.context_id
INNER JOIN contexts doc ON doc.id
= new1.context_id
INNER JOIN nodes lists ON
lists.id = new1.node
_id
INNER JOIN nodes lists ON
new1.node_id = lists.parent
_id
INNER JOIN context_node_ngrams
nnn ON nnn.context_id
= doc.id
INNER JOIN context_node_ngrams
cnn ON cnn.context_id
= doc.id
WHERE
nnn.node_
id in (?, lists.id) -- (masterList_id, userLists)
WHERE
lists.
id in (?, lists.id) -- (masterList_id, userLists)
AND lists.typename = ?
AND lists.typename = ?
GROUP BY node1_id, node2_id, ngrams_id, ngrams_type
GROUP BY node1_id, node2_id, ngrams_id, ngrams_type
) as d
) as d
...
...
src/Gargantext/Database/Query/Table/Node/Document/Add.hs
View file @
4e3342db
...
@@ -33,13 +33,13 @@ import Gargantext.Prelude
...
@@ -33,13 +33,13 @@ import Gargantext.Prelude
---------------------------------------------------------------------------
---------------------------------------------------------------------------
add
::
ParentId
->
[
Node
Id
]
->
Cmd
err
[
Only
Int
]
add
::
CorpusId
->
[
Context
Id
]
->
Cmd
err
[
Only
Int
]
add
pId
ns
=
runPGSQuery
queryAdd
(
Only
$
Values
fields
inputData
)
add
pId
ns
=
runPGSQuery
queryAdd
(
Only
$
Values
fields
inputData
)
where
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
inputSqlTypes
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
inputSqlTypes
inputData
=
prepare
pId
ns
inputData
=
prepare
pId
ns
add_debug
::
ParentId
->
[
Node
Id
]
->
Cmd
err
ByteString
add_debug
::
CorpusId
->
[
Context
Id
]
->
Cmd
err
ByteString
add_debug
pId
ns
=
formatPGSQuery
queryAdd
(
Only
$
Values
fields
inputData
)
add_debug
pId
ns
=
formatPGSQuery
queryAdd
(
Only
$
Values
fields
inputData
)
where
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
inputSqlTypes
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
inputSqlTypes
...
@@ -62,19 +62,19 @@ queryAdd = [sql|
...
@@ -62,19 +62,19 @@ queryAdd = [sql|
;
;
|]
|]
prepare
::
ParentId
->
[
Node
Id
]
->
[
InputData
]
prepare
::
ParentId
->
[
Context
Id
]
->
[
InputData
]
prepare
pId
ns
=
map
(
\
nId
->
InputData
pId
n
Id
)
ns
prepare
pId
ns
=
map
(
\
cId
->
InputData
pId
c
Id
)
ns
------------------------------------------------------------------------
------------------------------------------------------------------------
-- * Main Types used
-- * Main Types used
data
InputData
=
InputData
{
inNode
1_id
::
NodeId
data
InputData
=
InputData
{
inNode
_id
::
NodeId
,
in
Node2_id
::
Node
Id
,
in
Context_id
::
Context
Id
}
deriving
(
Show
,
Generic
,
Typeable
)
}
deriving
(
Show
,
Generic
,
Typeable
)
instance
ToRow
InputData
where
instance
ToRow
InputData
where
toRow
inputData
=
[
toField
(
inNode
1_id
inputData
)
toRow
inputData
=
[
toField
(
inNode
_id
inputData
)
,
toField
(
in
Node2
_id
inputData
)
,
toField
(
in
Context
_id
inputData
)
,
toField
(
1
::
Int
)
,
toField
(
1
::
Int
)
]
]
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