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
164
Issues
164
List
Board
Labels
Milestones
Merge Requests
10
Merge Requests
10
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
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
Count.hs
src/Gargantext/Database/Metrics/Count.hs
+20
-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
)
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