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
148
Issues
148
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
a2fd553a
Commit
a2fd553a
authored
Mar 30, 2021
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Order 1 and 2 implemented.
parent
22b6aa97
Pipeline
#1434
failed with stage
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
35 deletions
+36
-35
Update.hs
src/Gargantext/API/Node/Update.hs
+2
-4
Distances.hs
src/Gargantext/Core/Methods/Distances.hs
+3
-3
API.hs
src/Gargantext/Core/Viz/Graph/API.hs
+22
-14
Tools.hs
src/Gargantext/Core/Viz/Graph/Tools.hs
+9
-14
No files found.
src/Gargantext/API/Node/Update.hs
View file @
a2fd553a
...
...
@@ -30,7 +30,7 @@ import Gargantext.API.Admin.Orchestrator.Types (JobLog(..), AsyncJobs)
import
Gargantext.API.Admin.Types
(
HasSettings
)
import
Gargantext.API.Prelude
(
GargServer
,
simuLogs
)
import
Gargantext.Core.Viz.Graph.API
(
recomputeGraph
)
import
Gargantext.Core.Methods.Distances
(
GraphMetric
(
..
)
,
Distance
(
..
)
)
import
Gargantext.Core.Methods.Distances
(
GraphMetric
(
..
))
import
Gargantext.Database.Action.Flow.Pairing
(
pairing
)
import
Gargantext.Database.Action.Flow.Types
(
FlowCmdM
)
import
Gargantext.Database.Admin.Types.Node
...
...
@@ -86,9 +86,7 @@ updateNode uId nId (UpdateNodeParamsGraph metric) logStatus = do
,
_scst_events
=
Just
[]
}
_
<-
case
metric
of
Order1
->
recomputeGraph
uId
nId
Conditional
Order2
->
recomputeGraph
uId
nId
Distributional
_
<-
recomputeGraph
uId
nId
(
Just
metric
)
pure
JobLog
{
_scst_succeeded
=
Just
2
,
_scst_failed
=
Just
0
...
...
src/Gargantext/Core/Methods/Distances.hs
View file @
a2fd553a
...
...
@@ -35,9 +35,9 @@ measure Conditional = measureConditional
measure
Distributional
=
logDistributional
------------------------------------------------------------------------
withMetric
::
GraphMetric
->
Matrix
Int
->
Matrix
Doubl
e
withMetric
Order1
=
measure
Conditional
withMetric
Order2
=
log
Distributional
withMetric
::
GraphMetric
->
Distanc
e
withMetric
Order1
=
Conditional
withMetric
Order2
=
Distributional
------------------------------------------------------------------------
data
GraphMetric
=
Order1
|
Order2
...
...
src/Gargantext/Core/Viz/Graph/API.hs
View file @
a2fd553a
...
...
@@ -18,6 +18,7 @@ module Gargantext.Core.Viz.Graph.API
import
Control.Lens
(
set
,
(
^.
),
_Just
,
(
^?
))
import
Data.Aeson
import
Data.Maybe
(
fromMaybe
)
import
Data.Swagger
import
Data.Text
import
Debug.Trace
(
trace
)
...
...
@@ -26,7 +27,7 @@ import Gargantext.API.Admin.Orchestrator.Types
import
Gargantext.API.Ngrams.Tools
import
Gargantext.API.Ngrams.Types
(
NgramsRepo
,
r_version
)
import
Gargantext.API.Prelude
import
Gargantext.Core.Methods.Distances
(
Distance
(
..
),
GraphMetric
(
..
))
import
Gargantext.Core.Methods.Distances
(
Distance
(
..
),
GraphMetric
(
..
)
,
withMetric
)
import
Gargantext.Core.Types.Main
import
Gargantext.Core.Viz.Graph
import
Gargantext.Core.Viz.Graph.GEXF
()
...
...
@@ -91,9 +92,9 @@ getGraph _uId nId = do
-- TODO Distance in Graph params
case
graph
of
Nothing
->
do
-- graph' <- computeGraph cId Distributional NgramsTerms repo
graph'
<-
computeGraph
cId
Conditional
NgramsTerms
repo
mt
<-
defaultGraphMetadata
cId
"Title"
repo
let
defaultMetric
=
Order1
graph'
<-
computeGraph
cId
(
withMetric
defaultMetric
)
NgramsTerms
repo
mt
<-
defaultGraphMetadata
cId
"Title"
repo
defaultMetric
let
graph''
=
set
graph_metadata
(
Just
mt
)
graph'
hg
=
HyperdataGraphAPI
graph''
camera
...
...
@@ -105,14 +106,17 @@ getGraph _uId nId = do
HyperdataGraphAPI
graph'
camera
recomputeGraph
::
UserId
->
NodeId
->
Distance
->
GargNoServer
Graph
recomputeGraph
_uId
nId
d
=
do
recomputeGraph
::
UserId
->
NodeId
->
Maybe
GraphMetric
->
GargNoServer
Graph
recomputeGraph
_uId
nId
maybeDistance
=
do
nodeGraph
<-
getNodeWith
nId
(
Proxy
::
Proxy
HyperdataGraph
)
let
graph
=
nodeGraph
^.
node_hyperdata
.
hyperdataGraph
camera
=
nodeGraph
^.
node_hyperdata
.
hyperdataCamera
graphMetadata
=
graph
^?
_Just
.
graph_metadata
.
_Just
listVersion
=
graph
^?
_Just
.
graph_metadata
.
_Just
.
gm_list
.
lfg_version
graphMetric
=
case
maybeDistance
of
Nothing
->
graph
^?
_Just
.
graph_metadata
.
_Just
.
gm_metric
_
->
maybeDistance
repo
<-
getRepo
let
...
...
@@ -120,11 +124,14 @@ recomputeGraph _uId nId d = do
cId
=
maybe
(
panic
"[G.V.G.API.recomputeGraph] Node has no parent"
)
identity
$
nodeGraph
^.
node_parentId
similarity
=
case
graphMetric
of
Nothing
->
withMetric
Order2
Just
m
->
withMetric
m
case
graph
of
Nothing
->
do
graph'
<-
computeGraph
cId
d
NgramsTerms
repo
mt
<-
defaultGraphMetadata
cId
"Title"
repo
graph'
<-
computeGraph
cId
similarity
NgramsTerms
repo
mt
<-
defaultGraphMetadata
cId
"Title"
repo
(
fromMaybe
Order1
maybeDistance
)
let
graph''
=
set
graph_metadata
(
Just
mt
)
graph'
_
<-
updateHyperdata
nId
(
HyperdataGraph
(
Just
graph''
)
camera
)
pure
$
trace
"[G.V.G.API.recomputeGraph] Graph empty, computed"
graph''
...
...
@@ -132,7 +139,7 @@ recomputeGraph _uId nId d = do
Just
graph'
->
if
listVersion
==
Just
v
then
pure
graph'
else
do
graph''
<-
computeGraph
cId
d
NgramsTerms
repo
graph''
<-
computeGraph
cId
similarity
NgramsTerms
repo
let
graph'''
=
set
graph_metadata
graphMetadata
graph''
_
<-
updateHyperdata
nId
(
HyperdataGraph
(
Just
graph'''
)
camera
)
pure
$
trace
"[G.V.G.API] Graph exists, recomputing"
graph'''
...
...
@@ -157,7 +164,7 @@ computeGraph cId d nt repo = do
<$>
groupNodesByNgrams
ngs
<$>
getNodesByNgramsOnlyUser
cId
(
lIds
<>
[
lId
])
nt
(
HashMap
.
keys
ngs
)
printDebug
"myCooc"
myCooc
--
printDebug "myCooc" myCooc
graph
<-
liftBase
$
cooc2graphWith
Spinglass
d
0
myCooc
pure
graph
...
...
@@ -167,13 +174,14 @@ defaultGraphMetadata :: HasNodeError err
=>
CorpusId
->
Text
->
NgramsRepo
->
GraphMetric
->
Cmd
err
GraphMetadata
defaultGraphMetadata
cId
t
repo
=
do
defaultGraphMetadata
cId
t
repo
gm
=
do
lId
<-
defaultList
cId
pure
$
GraphMetadata
{
_gm_title
=
t
,
_gm_metric
=
Order1
,
_gm_metric
=
gm
,
_gm_corpusId
=
[
cId
]
,
_gm_legend
=
[
LegendField
1
"#FFF"
"Cluster1"
...
...
@@ -209,7 +217,7 @@ graphRecompute u n logStatus = do
,
_scst_remaining
=
Just
1
,
_scst_events
=
Just
[]
}
_g
<-
trace
(
show
u
)
$
recomputeGraph
u
n
Distributional
_g
<-
trace
(
show
u
)
$
recomputeGraph
u
n
Nothing
pure
JobLog
{
_scst_succeeded
=
Just
1
,
_scst_failed
=
Just
0
,
_scst_remaining
=
Just
0
...
...
@@ -249,7 +257,7 @@ graphVersions nId = do
,
gv_repo
=
v
}
recomputeVersions
::
UserId
->
NodeId
->
GargNoServer
Graph
recomputeVersions
uId
nId
=
recomputeGraph
uId
nId
Distributional
recomputeVersions
uId
nId
=
recomputeGraph
uId
nId
Nothing
------------------------------------------------------------
graphClone
::
UserId
...
...
src/Gargantext/Core/Viz/Graph/Tools.hs
View file @
a2fd553a
...
...
@@ -51,12 +51,13 @@ cooc2graph' distance threshold myCooc
$
mat2map
$
measure
distance
$
case
distance
of
Conditional
->
map2mat
Triangular
0
(
Map
.
size
ti
)
Distributional
->
map2mat
Square
0
(
Map
.
size
ti
)
Conditional
->
map2mat
Triangular
0
tiSize
Distributional
->
map2mat
Square
0
tiSize
$
Map
.
filter
(
>
1
)
myCooc'
where
(
ti
,
_
)
=
createIndices
myCooc
tiSize
=
Map
.
size
ti
myCooc'
=
toIndex
ti
myCooc
...
...
@@ -84,26 +85,18 @@ cooc2graphWith' doPartitions distance threshold myCooc = do
$
HashMap
.
toList
myCooc
(
ti
,
_
)
=
createIndices
theMatrix
tiSize
=
Map
.
size
ti
myCooc'
=
toIndex
ti
theMatrix
matCooc
=
case
distance
of
-- Shape of the Matrix
Conditional
->
map2mat
Triangular
0
(
Map
.
size
ti
)
Distributional
->
map2mat
Square
0
(
Map
.
size
ti
)
Conditional
->
map2mat
Triangular
0
tiSize
Distributional
->
map2mat
Square
0
tiSize
$
case
distance
of
-- Removing the Diagonal ?
Conditional
->
Map
.
filterWithKey
(
\
(
a
,
b
)
_
->
a
/=
b
)
Distributional
->
identity
$
Map
.
filter
(
>
1
)
myCooc'
printDebug
"myCooc'"
myCooc'
printDebug
"ti"
(
Map
.
size
ti
)
let
similarities
=
measure
distance
matCooc
printDebug
"Similarities"
similarities
let
links
=
round
(
let
n
::
Double
=
fromIntegral
(
Map
.
size
ti
)
in
n
*
log
n
)
links
=
round
(
let
n
::
Double
=
fromIntegral
tiSize
in
n
*
log
n
)
distanceMap
=
Map
.
fromList
$
List
.
take
links
$
List
.
sortOn
snd
...
...
@@ -120,6 +113,8 @@ cooc2graphWith' doPartitions distance threshold myCooc = do
n'
=
Set
.
size
$
Set
.
fromList
$
as
<>
bs
ClustersParams
rivers
_level
=
clustersParams
nodesApprox
printDebug
"similarities"
similarities
partitions
<-
if
(
Map
.
size
distanceMap
>
0
)
then
doPartitions
distanceMap
else
panic
"Text.Flow: DistanceMap is empty"
...
...
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