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
149
Issues
149
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
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
1f5ceb16
Commit
1f5ceb16
authored
Jan 08, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
[MERGE] Ngrams repos fixes
parents
3774aa22
5b92dcdf
Pipeline
#674
failed with stage
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
36 deletions
+42
-36
Tools.hs
src/Gargantext/API/Ngrams/Tools.hs
+25
-21
Metrics.hs
src/Gargantext/Database/Metrics.hs
+2
-2
Chart.hs
src/Gargantext/Viz/Chart.hs
+3
-3
API.hs
src/Gargantext/Viz/Graph/API.hs
+12
-10
No files found.
src/Gargantext/API/Ngrams/Tools.hs
View file @
1f5ceb16
...
...
@@ -33,24 +33,28 @@ import qualified Data.Set as Set
type
RootTerm
=
Text
-- TODO-ACCESS: We want to do the security check before entering here.
-- Add a static capability parameter would be nice.
-- Ideally this is the access to `repoVar` which needs to
-- be properly guarded.
getListNgrams
::
RepoCmdM
env
err
m
=>
[
ListId
]
->
NgramsType
->
m
(
Map
Text
NgramsRepoElement
)
getListNgrams
nodeIds
ngramsType
=
do
v
<-
view
repoVar
repo
<-
liftIO
$
readMVar
v
let
getRepo
::
RepoCmdM
env
err
m
=>
m
NgramsRepo
getRepo
=
do
v
<-
view
repoVar
liftIO
$
readMVar
v
listNgramsFromRepo
::
[
ListId
]
->
NgramsType
->
NgramsRepo
->
Map
Text
NgramsRepoElement
listNgramsFromRepo
nodeIds
ngramsType
repo
=
ngrams
where
ngramsMap
=
repo
^.
r_state
.
at
ngramsType
.
_Just
ngrams
=
Map
.
unionsWith
mergeNgramsElement
[
ngramsMap
^.
at
nodeId
.
_Just
|
nodeId
<-
nodeIds
]
pure
ngrams
-- TODO-ACCESS: We want to do the security check before entering here.
-- Add a static capability parameter would be nice.
-- Ideally this is the access to `repoVar` which needs to
-- be properly guarded.
getListNgrams
::
RepoCmdM
env
err
m
=>
[
ListId
]
->
NgramsType
->
m
(
Map
Text
NgramsRepoElement
)
getListNgrams
nodeIds
ngramsType
=
listNgramsFromRepo
nodeIds
ngramsType
<$>
getRepo
getTermsWith
::
(
RepoCmdM
env
err
m
,
Ord
a
)
=>
(
Text
->
a
)
->
[
ListId
]
...
...
@@ -61,19 +65,19 @@ getTermsWith f ls ngt lt = Map.fromListWith (<>)
<$>
Map
.
toList
<$>
Map
.
filter
(
\
f'
->
(
fst
f'
)
==
lt
)
<$>
mapTermListRoot
ls
ngt
<$>
getRepo
where
toTreeWith
f''
(
t
,
(
_lt
,
maybeRoot
))
=
case
maybeRoot
of
Nothing
->
(
f''
t
,
[]
)
Just
r
->
(
f''
r
,
map
f''
[
t
])
mapTermListRoot
::
RepoCmdM
env
err
m
=>
[
ListId
]
->
NgramsType
->
m
(
Map
Text
(
ListType
,
(
Maybe
Text
)))
mapTermListRoot
nodeIds
ngramsType
=
do
ngrams
<-
getListNgrams
nodeIds
ngramsType
pure
$
Map
.
fromList
[
(
t
,
(
_nre_list
nre
,
_nre_root
nre
))
|
(
t
,
nre
)
<-
Map
.
toList
ngrams
]
mapTermListRoot
::
[
ListId
]
->
NgramsType
->
NgramsRepo
->
Map
Text
(
ListType
,
(
Maybe
Text
))
mapTermListRoot
nodeIds
ngramsType
repo
=
Map
.
fromList
[
(
t
,
(
_nre_list
nre
,
_nre_root
nre
))
|
(
t
,
nre
)
<-
Map
.
toList
ngrams
]
where
ngrams
=
listNgramsFromRepo
nodeIds
ngramsType
repo
filterListWithRoot
::
ListType
->
Map
Text
(
ListType
,
Maybe
Text
)
->
Map
Text
(
Maybe
RootTerm
)
...
...
src/Gargantext/Database/Metrics.hs
View file @
1f5ceb16
...
...
@@ -21,7 +21,7 @@ module Gargantext.Database.Metrics
import
Data.Map
(
Map
)
import
Data.Text
(
Text
)
import
Gargantext.API.Ngrams
(
TabType
(
..
),
ngramsTypeFromTabType
)
import
Gargantext.API.Ngrams.Tools
(
filterListWithRoot
,
groupNodesByNgrams
,
Diagonal
(
..
),
getCoocByNgrams
,
mapTermListRoot
,
RootTerm
)
import
Gargantext.API.Ngrams.Tools
(
filterListWithRoot
,
groupNodesByNgrams
,
Diagonal
(
..
),
getCoocByNgrams
,
mapTermListRoot
,
RootTerm
,
getRepo
)
import
Gargantext.Core.Types
(
ListType
(
..
),
Limit
,
NodeType
(
..
))
import
Gargantext.Database.Flow
(
FlowCmdM
)
import
Gargantext.Database.Metrics.NgramsByNode
(
getNodesByNgramsOnlyUser
{-, getTficfWith-}
)
...
...
@@ -76,7 +76,7 @@ getNgrams cId maybeListId tabType = do
Nothing
->
defaultList
cId
Just
lId'
->
pure
lId'
lists
<-
mapTermListRoot
[
lId
]
(
ngramsTypeFromTabType
tabType
)
lists
<-
mapTermListRoot
[
lId
]
(
ngramsTypeFromTabType
tabType
)
<$>
getRepo
let
maybeSyn
=
Map
.
unions
$
map
(
\
t
->
filterListWithRoot
t
lists
)
[
GraphTerm
,
StopTerm
,
CandidateTerm
]
pure
(
lists
,
maybeSyn
)
...
...
src/Gargantext/Viz/Chart.hs
View file @
1f5ceb16
...
...
@@ -72,7 +72,7 @@ pieData :: FlowCmdM env err m
pieData
cId
nt
lt
=
do
ls'
<-
selectNodesWithUsername
NodeList
userMaster
ls
<-
map
(
_node_id
)
<$>
getListsWithParentId
cId
ts
<-
mapTermListRoot
ls
nt
ts
<-
mapTermListRoot
ls
nt
<$>
getRepo
let
dico
=
filterListWithRoot
lt
ts
terms
=
catMaybes
$
List
.
concat
$
map
(
\
(
a
,
b
)
->
[
Just
a
,
b
])
$
Map
.
toList
dico
...
...
@@ -94,7 +94,7 @@ treeData :: FlowCmdM env err m
treeData
cId
nt
lt
=
do
ls'
<-
selectNodesWithUsername
NodeList
userMaster
ls
<-
map
(
_node_id
)
<$>
getListsWithParentId
cId
ts
<-
mapTermListRoot
ls
nt
ts
<-
mapTermListRoot
ls
nt
<$>
getRepo
let
dico
=
filterListWithRoot
lt
ts
...
...
@@ -112,7 +112,7 @@ treeData' :: FlowCmdM env ServerError m
treeData'
cId
nt
lt
=
do
ls'
<-
selectNodesWithUsername
NodeList
userMaster
ls
<-
map
(
_node_id
)
<$>
getListsWithParentId
cId
ts
<-
mapTermListRoot
ls
nt
ts
<-
mapTermListRoot
ls
nt
<$>
getRepo
let
dico
=
filterListWithRoot
lt
ts
...
...
src/Gargantext/Viz/Graph/API.hs
View file @
1f5ceb16
...
...
@@ -28,7 +28,7 @@ import Debug.Trace (trace)
import
Control.Lens
(
set
,
(
^.
),
_Just
,
(
^?
))
import
Control.Monad.IO.Class
(
liftIO
)
import
Data.Maybe
(
Maybe
(
..
))
import
Gargantext.API.Ngrams
(
currentV
ersion
)
import
Gargantext.API.Ngrams
(
NgramsRepo
,
r_v
ersion
)
import
Gargantext.API.Ngrams.Tools
import
Gargantext.API.Types
import
Gargantext.Core.Types.Main
...
...
@@ -36,9 +36,10 @@ import Gargantext.Database.Config
import
Gargantext.Database.Metrics.NgramsByNode
(
getNodesByNgramsOnlyUser
)
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Node.Select
import
Gargantext.Database.Schema.Node
(
getNodeWith
,
defaultList
,
insertGraph
)
import
Gargantext.Database.Schema.Node
(
getNodeWith
,
defaultList
,
insertGraph
,
HasNodeError
)
import
Gargantext.Database.Types.Node
hiding
(
node_id
)
-- (GraphId, ListId, CorpusId, NodeId)
import
Gargantext.Database.Node.UpdateOpaleye
(
updateHyperdata
)
import
Gargantext.Database.Utils
(
Cmd
)
import
Gargantext.Prelude
import
Gargantext.Viz.Graph
import
Gargantext.Viz.Graph.Tools
-- (cooc2graph)
...
...
@@ -71,7 +72,8 @@ getGraph uId nId = do
.
gm_list
.
lfg_version
v
<-
currentVersion
repo
<-
getRepo
let
v
=
repo
^.
r_version
nodeUser
<-
getNodeWith
(
NodeId
uId
)
HyperdataUser
let
uId'
=
nodeUser
^.
node_userId
...
...
@@ -79,36 +81,36 @@ getGraph uId nId = do
let
cId
=
maybe
(
panic
"[ERR:G.V.G.API] Node has no parent"
)
identity
$
nodeGraph
^.
node_parentId
g
<-
case
graph
of
Nothing
->
do
graph'
<-
computeGraph
cId
NgramsTerms
v
graph'
<-
computeGraph
cId
NgramsTerms
repo
_
<-
insertGraph
cId
uId'
(
HyperdataGraph
$
Just
graph'
)
pure
graph'
Just
graph'
->
if
listVersion
==
Just
v
then
pure
graph'
else
do
graph''
<-
computeGraph
cId
NgramsTerms
v
graph''
<-
computeGraph
cId
NgramsTerms
repo
_
<-
updateHyperdata
nId
(
HyperdataGraph
$
Just
graph''
)
pure
graph''
pure
$
trace
(
"salut"
<>
show
g
)
$
g
-- TODO use Database Monad only here ?
computeGraph
::
CorpusId
->
NgramsType
->
Int
->
GargServer
(
Get
'[
J
SON
]
Graph
)
computeGraph
cId
nt
v
=
do
computeGraph
::
HasNodeError
err
=>
CorpusId
->
NgramsType
->
NgramsRepo
->
Cmd
err
Graph
computeGraph
cId
nt
repo
=
do
lId
<-
defaultList
cId
let
metadata
=
GraphMetadata
"Title"
[
cId
]
[
LegendField
1
"#FFF"
"Cluster"
,
LegendField
2
"#FFF"
"Cluster"
]
(
ListForGraph
lId
v
)
(
ListForGraph
lId
(
repo
^.
r_version
)
)
-- (map (\n -> LegendField n "#FFFFFF" (pack $ show n)) [1..10])
lIds
<-
selectNodesWithUsername
NodeList
userMaster
ngs
<-
filterListWithRoot
GraphTerm
<$>
mapTermListRoot
[
lId
]
nt
let
ngs
=
filterListWithRoot
GraphTerm
$
mapTermListRoot
[
lId
]
nt
repo
myCooc
<-
Map
.
filter
(
>
1
)
<$>
getCoocByNgrams
(
Diagonal
True
)
...
...
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