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
163
Issues
163
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
d218880c
Commit
d218880c
authored
Feb 21, 2019
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DB] Count documents in corpus.
parent
f57909bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
+22
-4
Count.hs
src/Gargantext/Database/Metrics/Count.hs
+20
-2
Root.hs
src/Gargantext/Database/Root.hs
+2
-2
No files found.
src/Gargantext/Database/Metrics/Count.hs
View file @
d218880c
...
@@ -11,6 +11,7 @@ Count Ngrams by Context
...
@@ -11,6 +11,7 @@ Count Ngrams by Context
-}
-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}
...
@@ -19,14 +20,15 @@ Count Ngrams by Context
...
@@ -19,14 +20,15 @@ Count Ngrams by Context
module
Gargantext.Database.Metrics.Count
where
module
Gargantext.Database.Metrics.Count
where
import
Data.Monoid
(
mempty
)
import
Control.Arrow
(
returnA
)
import
Control.Arrow
(
returnA
)
import
Control.Lens
(
view
)
import
Control.Lens
(
view
)
import
Data.Map.Strict
(
Map
,
fromListWith
,
elems
)
import
Data.Map.Strict
(
Map
,
fromListWith
,
elems
)
import
Data.Monoid
(
mempty
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Gargantext.API.Ngrams
(
NgramsElement
(
..
))
import
Gargantext.API.Ngrams
(
NgramsElement
(
..
))
import
Gargantext.Core.Types.Main
(
listTypeId
,
ListType
(
..
))
import
Gargantext.Core.Types.Main
(
listTypeId
,
ListType
(
..
))
import
Gargantext.Database.Access
import
Gargantext.Database.Config
(
nodeTypeId
)
import
Gargantext.Database.Config
(
nodeTypeId
)
import
Gargantext.Database.Queries.Join
(
leftJoin4
,
leftJoin5
,
leftJoin3
)
import
Gargantext.Database.Queries.Join
(
leftJoin4
,
leftJoin5
,
leftJoin3
)
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Ngrams
...
@@ -39,9 +41,11 @@ import Gargantext.Database.Schema.NodeNodeNgrams
...
@@ -39,9 +41,11 @@ import Gargantext.Database.Schema.NodeNodeNgrams
import
Gargantext.Database.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Types.Node
-- (ListId, CorpusId, NodeId)
import
Gargantext.Database.Utils
import
Gargantext.Database.Utils
import
Gargantext.Database.Utils
(
Cmd
,
runPGSQuery
)
import
Gargantext.Database.Utils
(
Cmd
,
runPGSQuery
)
import
Gargantext.Prelude
import
Gargantext.Prelude
hiding
(
sum
)
import
Gargantext.Text.Metrics.Count
(
Coocs
,
coocOn
)
import
Gargantext.Text.Metrics.Count
(
Coocs
,
coocOn
)
import
Opaleye
import
Opaleye
import
Safe
(
headMay
)
import
qualified
Database.PostgreSQL.Simple
as
PGS
getCoocByDocDev
::
HasNodeError
err
=>
CorpusId
->
ListId
->
Cmd
err
(
Map
([
Text
],
[
Text
])
Int
)
getCoocByDocDev
::
HasNodeError
err
=>
CorpusId
->
ListId
->
Cmd
err
(
Map
([
Text
],
[
Text
])
Int
)
getCoocByDocDev
cId
lId
=
coocOn
(
\
n
->
[
view
(
ngrams
.
ngramsTerms
)
n
])
<$>
getNgramsByDoc
cId
lId
getCoocByDocDev
cId
lId
=
coocOn
(
\
n
->
[
view
(
ngrams
.
ngramsTerms
)
n
])
<$>
getNgramsByDoc
cId
lId
...
@@ -232,4 +236,18 @@ getNgramsWithParentNodeIdJoin = leftJoin3 queryNodeTable queryNodeNgramTable que
...
@@ -232,4 +236,18 @@ getNgramsWithParentNodeIdJoin = leftJoin3 queryNodeTable queryNodeNgramTable que
on2
(
ng
,
(
nng
,
_
))
=
ngrams_id
ng
.==
nng_ngrams_id
nng
on2
(
ng
,
(
nng
,
_
))
=
ngrams_id
ng
.==
nng_ngrams_id
nng
countCorpusDocuments
::
Roles
->
Int
->
Cmd
err
Int
countCorpusDocuments
r
cId
=
maybe
0
identity
<$>
headMay
<$>
map
(
\
(
PGS
.
Only
n
)
->
n
)
<$>
runQuery'
r
cId
where
runQuery'
RoleUser
cId'
=
runPGSQuery
"SELECT count(*) from nodes_nodes nn WHERE nn.node1_id = ?"
(
PGS
.
Only
cId'
)
runQuery'
RoleMaster
cId'
=
runPGSQuery
"SELECT count(*) from nodes n WHERE n.parent_id = ? AND n.typename = ?"
(
cId'
,
nodeTypeId
NodeDocument
)
src/Gargantext/Database/Root.hs
View file @
d218880c
...
@@ -45,8 +45,8 @@ selectRoot :: Username -> Query NodeRead
...
@@ -45,8 +45,8 @@ selectRoot :: Username -> Query NodeRead
selectRoot
username
=
proc
()
->
do
selectRoot
username
=
proc
()
->
do
row
<-
queryNodeTable
-<
()
row
<-
queryNodeTable
-<
()
users
<-
queryUserTable
-<
()
users
<-
queryUserTable
-<
()
restrict
-<
_node_typename
row
.==
(
pgInt4
$
nodeTypeId
NodeUser
)
restrict
-<
_node_typename
row
.==
(
pgInt4
$
nodeTypeId
NodeUser
)
restrict
-<
user_username
users
.==
(
pgStrictText
username
)
restrict
-<
user_username
users
.==
(
pgStrictText
username
)
restrict
-<
_node_userId
row
.==
(
user_id
users
)
restrict
-<
_node_userId
row
.==
(
user_id
users
)
returnA
-<
row
returnA
-<
row
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