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
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
8
Merge Requests
8
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
26109754
Commit
26109754
authored
Feb 18, 2019
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT DB] get ngrams by node with join to NodeNodeNgrams.
parent
10ebe017
Pipeline
#199
canceled with stage
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
107 deletions
+78
-107
Facet.hs
src/Gargantext/Database/Facet.hs
+6
-6
Count.hs
src/Gargantext/Database/Metrics/Count.hs
+57
-3
NodeNode.hs
src/Gargantext/Database/Schema/NodeNode.hs
+10
-10
NodeNodeNgram.hs
src/Gargantext/Database/Schema/NodeNodeNgram.hs
+0
-83
TextSearch.hs
src/Gargantext/Database/TextSearch.hs
+5
-5
No files found.
src/Gargantext/Database/Facet.hs
View file @
26109754
...
...
@@ -215,8 +215,8 @@ viewAuthorsDoc cId _ nt = proc () -> do
(
doc
,(
_
,(
_
,(
_
,
contact
))))
<-
queryAuthorsDoc
-<
()
{-nn <- queryNodeNodeTable -< ()
restrict -< n
odeNode
_node1_id nn .== _node_id doc
-- restrict -< n
odeNode
_delete nn .== (pgBool t)
restrict -< n
n
_node1_id nn .== _node_id doc
-- restrict -< n
n
_delete nn .== (pgBool t)
-}
restrict
-<
_node_id
contact
.==
(
toNullable
$
pgNodeId
cId
)
...
...
@@ -254,11 +254,11 @@ viewDocuments :: CorpusId -> Trash -> NodeTypeId -> Query FacetDocRead
viewDocuments
cId
t
ntId
=
proc
()
->
do
n
<-
queryNodeTable
-<
()
nn
<-
queryNodeNodeTable
-<
()
restrict
-<
_node_id
n
.==
n
odeNode
_node2_id
nn
restrict
-<
n
odeNode
_node1_id
nn
.==
(
pgNodeId
cId
)
restrict
-<
_node_id
n
.==
n
n
_node2_id
nn
restrict
-<
n
n
_node1_id
nn
.==
(
pgNodeId
cId
)
restrict
-<
_node_typename
n
.==
(
pgInt4
ntId
)
restrict
-<
n
odeNode
_delete
nn
.==
(
pgBool
t
)
returnA
-<
FacetDoc
(
_node_id
n
)
(
_node_date
n
)
(
_node_name
n
)
(
_node_hyperdata
n
)
(
n
odeNode
_favorite
nn
)
(
pgInt4
1
)
restrict
-<
n
n
_delete
nn
.==
(
pgBool
t
)
returnA
-<
FacetDoc
(
_node_id
n
)
(
_node_date
n
)
(
_node_name
n
)
(
_node_hyperdata
n
)
(
n
n
_favorite
nn
)
(
pgInt4
1
)
------------------------------------------------------------------------
...
...
src/Gargantext/Database/Metrics/Count.hs
View file @
26109754
...
...
@@ -25,13 +25,14 @@ import Data.Map.Strict (Map, fromListWith, elems)
import
Data.Text
(
Text
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Gargantext.Core.Types.Main
(
listTypeId
,
ListType
(
..
))
import
Gargantext.Database.Queries.Join
(
leftJoin4
)
import
Gargantext.Database.Queries.Join
(
leftJoin4
,
leftJoin5
)
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Ngrams
(
NgramsId
,
NgramsType
(
..
),
ngramsTypeId
,
Ngrams
(
..
),
NgramsIndexed
(
..
),
ngrams
,
ngramsTerms
)
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Schema.Node
(
HasNodeError
(
..
))
import
Gargantext.Database.Schema.NodeNgram
import
Gargantext.Database.Schema.NodeNode
import
Gargantext.Database.Schema.NodeNodeNgrams
import
Gargantext.Database.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Utils
import
Gargantext.Database.Utils
(
Cmd
,
runPGSQuery
)
...
...
@@ -106,14 +107,14 @@ getNgramsByNodeIndexedJoin = leftJoin4 queryNodeTable
c1
c2
c3
where
c1
::
(
NodeNodeRead
,
NodeRead
)
->
Column
PGBool
c1
(
nn
,
n
)
=
n
odeNode
_node1_id
nn
.==
_node_id
n
c1
(
nn
,
n
)
=
n
n
_node1_id
nn
.==
_node_id
n
c2
::
(
NodeNgramRead
,
(
NodeNodeRead
,
NodeReadNull
)
)
->
Column
PGBool
c2
(
nng
,(
nn'
,
_
))
=
(
_nn_node_id
nng
)
.==
n
odeNode
_node2_id
nn'
c2
(
nng
,(
nn'
,
_
))
=
(
_nn_node_id
nng
)
.==
n
n
_node2_id
nn'
c3
::
(
NgramsRead
,
(
NodeNgramRead
...
...
@@ -124,5 +125,58 @@ getNgramsByNodeIndexedJoin = leftJoin4 queryNodeTable
)
->
Column
PGBool
c3
(
ng
,(
nng'
,(
_
,
_
)))
=
(
ngrams_id
ng
)
.==
_nn_ngrams_id
nng'
getNgramsByNodeIndexedJoin'
::
Query
(
NodeNodeNgramsRead
,
(
NgramsReadNull
,
(
NodeNgramReadNull
,
(
NodeNodeReadNull
,
NodeReadNull
)
)
)
)
getNgramsByNodeIndexedJoin'
=
leftJoin5
queryNodeTable
queryNodeNodeTable
queryNodeNgramTable
queryNgramsTable
queryNodeNodeNgramsTable
c1
c2
c3
c4
where
c1
::
(
NodeNodeRead
,
NodeRead
)
->
Column
PGBool
c1
(
nn
,
n
)
=
nn_node1_id
nn
.==
_node_id
n
c2
::
(
NodeNgramRead
,
(
NodeNodeRead
,
NodeReadNull
)
)
->
Column
PGBool
c2
(
nng
,(
nn'
,
_
))
=
(
_nn_node_id
nng
)
.==
nn_node2_id
nn'
c3
::
(
NgramsRead
,
(
NodeNgramRead
,
(
NodeNodeReadNull
,
NodeReadNull
)
)
)
->
Column
PGBool
c3
(
ng
,(
nng'
,(
_
,
_
)))
=
(
ngrams_id
ng
)
.==
_nn_ngrams_id
nng'
c4
::
(
NodeNodeNgramsRead
,
(
NgramsRead
,
(
NodeNgramReadNull
,
(
NodeNodeReadNull
,
NodeReadNull
)
)
)
)
->
Column
PGBool
c4
(
nnng
,(
_
,(
_
,(
nn
,
_
))))
=
(
toNullable
$
nnng_node1_id
nnng
)
.==
(
nn_node1_id
nn
)
.&&
(
toNullable
$
nnng_node2_id
nnng
)
.==
(
nn_node2_id
nn
)
--}
src/Gargantext/Database/Schema/NodeNode.hs
View file @
26109754
...
...
@@ -38,11 +38,11 @@ import Opaleye
data
NodeNodePoly
node1_id
node2_id
score
fav
del
=
NodeNode
{
n
odeNode
_node1_id
::
node1_id
,
n
odeNode
_node2_id
::
node2_id
,
n
odeNode
_score
::
score
,
n
odeNode
_favorite
::
fav
,
n
odeNode
_delete
::
del
=
NodeNode
{
n
n
_node1_id
::
node1_id
,
n
n
_node2_id
::
node2_id
,
n
n
_score
::
score
,
n
n
_favorite
::
fav
,
n
n
_delete
::
del
}
deriving
(
Show
)
type
NodeNodeWrite
=
NodeNodePoly
(
Column
(
PGInt4
))
...
...
@@ -70,11 +70,11 @@ $(makeLensesWith abbreviatedFields ''NodeNodePoly)
nodeNodeTable
::
Table
NodeNodeWrite
NodeNodeRead
nodeNodeTable
=
Table
"nodes_nodes"
(
pNodeNode
NodeNode
{
n
odeNode
_node1_id
=
required
"node1_id"
,
n
odeNode
_node2_id
=
required
"node2_id"
,
n
odeNode
_score
=
optional
"score"
,
n
odeNode
_favorite
=
optional
"favorite"
,
n
odeNode
_delete
=
optional
"delete"
NodeNode
{
n
n
_node1_id
=
required
"node1_id"
,
n
n
_node2_id
=
required
"node2_id"
,
n
n
_score
=
optional
"score"
,
n
n
_favorite
=
optional
"favorite"
,
n
n
_delete
=
optional
"delete"
}
)
...
...
src/Gargantext/Database/Schema/NodeNodeNgram.hs
deleted
100644 → 0
View file @
10ebe017
{-|
Module : Gargantext.Database.Schema.NodeNodeNgram
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
-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE Arrows #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module
Gargantext.Database.Schema.NodeNodeNgram
where
import
Prelude
import
Data.Maybe
(
Maybe
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Control.Lens.TH
(
makeLensesWith
,
abbreviatedFields
)
import
Gargantext.Database.Utils
(
Cmd
,
runOpaQuery
)
import
Opaleye
data
NodeNodeNgramPoly
node1_id
node2_id
ngram_id
score
=
NodeNodeNgram
{
nodeNodeNgram_node1_id
::
node1_id
,
nodeNodeNgram_node2_id
::
node2_id
,
nodeNodeNgram_ngram_id
::
ngram_id
,
nodeNodeNgram_score
::
score
}
deriving
(
Show
)
type
NodeNodeNgramWrite
=
NodeNodeNgramPoly
(
Column
PGInt4
)
(
Column
PGInt4
)
(
Column
PGInt4
)
(
Maybe
(
Column
PGFloat8
))
type
NodeNodeNgramRead
=
NodeNodeNgramPoly
(
Column
PGInt4
)
(
Column
PGInt4
)
(
Column
PGInt4
)
(
Column
PGFloat8
)
type
NodeNodeNgramReadNull
=
NodeNodeNgramPoly
(
Column
(
Nullable
PGInt4
))
(
Column
(
Nullable
PGInt4
))
(
Column
(
Nullable
PGInt4
))
(
Column
(
Nullable
PGFloat8
))
type
NodeNodeNgram
=
NodeNodeNgramPoly
Int
Int
Int
(
Maybe
Double
)
$
(
makeAdaptorAndInstance
"pNodeNodeNgram"
''
N
odeNodeNgramPoly
)
$
(
makeLensesWith
abbreviatedFields
''
N
odeNodeNgramPoly
)
nodeNodeNgramTable
::
Table
NodeNodeNgramWrite
NodeNodeNgramRead
nodeNodeNgramTable
=
Table
"nodes_nodes_ngrams"
(
pNodeNodeNgram
NodeNodeNgram
{
nodeNodeNgram_node1_id
=
required
"node1_id"
,
nodeNodeNgram_node2_id
=
required
"node2_id"
,
nodeNodeNgram_ngram_id
=
required
"ngram_id"
,
nodeNodeNgram_score
=
optional
"score"
}
)
queryNodeNodeNgramTable
::
Query
NodeNodeNgramRead
queryNodeNodeNgramTable
=
queryTable
nodeNodeNgramTable
-- | not optimized (get all ngrams without filters)
nodeNodeNgrams
::
Cmd
err
[
NodeNodeNgram
]
nodeNodeNgrams
=
runOpaQuery
queryNodeNodeNgramTable
instance
QueryRunnerColumnDefault
PGFloat8
(
Maybe
Double
)
where
queryRunnerColumnDefault
=
fieldQueryRunnerColumn
src/Gargantext/Database/TextSearch.hs
View file @
26109754
...
...
@@ -64,7 +64,7 @@ searchInCorpus cId q o l order = runOpaQuery (filterWith o l order $ queryInCorp
queryInCorpus
::
CorpusId
->
Text
->
O
.
Query
FacetDocRead
queryInCorpus
cId
q
=
proc
()
->
do
(
n
,
nn
)
<-
joinInCorpus
-<
()
restrict
-<
(
n
odeNode
_node1_id
nn
)
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
(
n
n
_node1_id
nn
)
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
(
_ns_search
n
)
@@
(
pgTSQuery
(
unpack
q
))
restrict
-<
(
_ns_typename
n
)
.==
(
pgInt4
$
nodeTypeId
NodeDocument
)
returnA
-<
FacetDoc
(
_ns_id
n
)
(
_ns_date
n
)
(
_ns_name
n
)
(
_ns_hyperdata
n
)
(
pgBool
True
)
(
pgInt4
1
)
...
...
@@ -73,7 +73,7 @@ joinInCorpus :: O.Query (NodeSearchRead, NodeNodeReadNull)
joinInCorpus
=
leftJoin
queryNodeSearchTable
queryNodeNodeTable
cond
where
cond
::
(
NodeSearchRead
,
NodeNodeRead
)
->
Column
PGBool
cond
(
n
,
nn
)
=
n
odeNode
_node2_id
nn
.==
_ns_id
n
cond
(
n
,
nn
)
=
n
n
_node2_id
nn
.==
_ns_id
n
------------------------------------------------------------------------
type
AuthorName
=
Text
...
...
@@ -103,7 +103,7 @@ queryInCorpusWithContacts cId q _ _ _ = proc () -> do
(
docs
,
(
corpusDoc
,
(
docNgrams
,
(
ngrams'
,
(
_
,
contacts
)))))
<-
joinInCorpusWithContacts
-<
()
restrict
-<
(
_ns_search
docs
)
@@
(
pgTSQuery
$
unpack
q
)
restrict
-<
(
_ns_typename
docs
)
.==
(
pgInt4
$
nodeTypeId
NodeDocument
)
restrict
-<
(
n
odeNode
_node1_id
corpusDoc
)
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
(
n
n
_node1_id
corpusDoc
)
.==
(
toNullable
$
pgNodeId
cId
)
restrict
-<
(
_nn_listType
docNgrams
)
.==
(
toNullable
$
pgNgramsType
Authors
)
restrict
-<
(
_node_typename
contacts
)
.==
(
toNullable
$
pgInt4
$
nodeTypeId
NodeContact
)
-- let contact_id = ifThenElse (isNull $ _node_id contacts) (toNullable $ pgInt4 0) (_node_id contacts)
...
...
@@ -122,10 +122,10 @@ joinInCorpusWithContacts = leftJoin6 queryNodeTable queryNodeNgramTable queryNgr
cond34
(
nng
,
(
ng
,
(
_
,
_
)))
=
ngrams_id
ng
.==
_nn_ngrams_id
nng
cond45
::
(
NodeNodeRead
,
(
NodeNgramRead
,
(
NgramsReadNull
,
(
NodeNgramReadNull
,
NodeReadNull
))))
->
Column
PGBool
cond45
(
nn
,
(
nng
,
(
_
,(
_
,
_
))))
=
_nn_node_id
nng
.==
n
odeNode
_node2_id
nn
cond45
(
nn
,
(
nng
,
(
_
,(
_
,
_
))))
=
_nn_node_id
nng
.==
n
n
_node2_id
nn
cond56
::
(
NodeSearchRead
,
(
NodeNodeRead
,
(
NodeNgramReadNull
,
(
NgramsReadNull
,
(
NodeNgramReadNull
,
NodeReadNull
)))))
->
Column
PGBool
cond56
(
n
,
(
nn
,
(
_
,(
_
,(
_
,
_
)))))
=
_ns_id
n
.==
n
odeNode
_node2_id
nn
cond56
(
n
,
(
nn
,
(
_
,(
_
,(
_
,
_
)))))
=
_ns_id
n
.==
n
n
_node2_id
nn
{-
...
...
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