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
158
Issues
158
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
0f6c2e5b
Commit
0f6c2e5b
authored
Oct 25, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-phylo' into dev
parents
706dd25d
148b0dcc
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
363 additions
and
258 deletions
+363
-258
Main.hs
bin/gargantext-adaptative-phylo/Main.hs
+15
-4
Group.hs
src/Gargantext/Core/Text/Group.hs
+25
-24
List.hs
src/Gargantext/Core/Text/List.hs
+5
-4
Social.hs
src/Gargantext/Core/Text/List/Social.hs
+85
-18
Tools.hs
src/Gargantext/Core/Viz/Graph/Tools.hs
+1
-1
Phylo.hs
src/Gargantext/Core/Viz/Phylo.hs
+93
-93
API.hs
src/Gargantext/Core/Viz/Phylo/API.hs
+26
-64
LevelMaker.hs
src/Gargantext/Core/Viz/Phylo/LevelMaker.hs
+45
-23
Main.hs
src/Gargantext/Core/Viz/Phylo/Main.hs
+16
-11
PhyloExport.hs
src/Gargantext/Core/Viz/Phylo/PhyloExport.hs
+15
-10
PhyloMaker.hs
src/Gargantext/Core/Viz/Phylo/PhyloMaker.hs
+19
-6
PhyloTools.hs
src/Gargantext/Core/Viz/Phylo/PhyloTools.hs
+18
-0
No files found.
bin/gargantext-adaptative-phylo/Main.hs
View file @
0f6c2e5b
...
@@ -170,14 +170,25 @@ main = do
...
@@ -170,14 +170,25 @@ main = do
let
sensibility
=
case
(
phyloProximity
config
)
of
let
sensibility
=
case
(
phyloProximity
config
)
of
Hamming
->
undefined
Hamming
->
undefined
WeightedLogJaccard
s
->
(
show
s
)
WeightedLogJaccard
s
->
(
show
s
)
let
sync
=
case
(
phyloSynchrony
config
)
of
ByProximityThreshold
t
_
_
_
->
(
show
t
)
ByProximityDistribution
_
_
->
undefined
-- to be improved
-- let br_length = case (take 1 $ exportFilter config) of
-- ByBranchSize t -> (show t)
let
output
=
(
outputPath
config
)
let
output
=
(
outputPath
config
)
<>
(
unpack
$
phyloName
config
)
<>
(
unpack
$
phyloName
config
)
<>
"-scale_"
<>
(
show
(
_qua_granularity
$
phyloQuality
config
))
<>
"-level_"
<>
(
show
(
phyloLevel
config
))
<>
"-"
<>
clq
<>
"-"
<>
clq
<>
"-sens_"
<>
sensibility
<>
"-level_"
<>
(
show
(
phyloLevel
config
))
<>
"-sens_"
<>
sensibility
-- <> "-lenght_" <> br_length
<>
"-scale_"
<>
(
show
(
_qua_granularity
$
phyloQuality
config
))
<>
"-sync_"
<>
sync
<>
".dot"
<>
".dot"
dotToFile
output
dot
dotToFile
output
dot
src/Gargantext/Core/Text/Group.hs
View file @
0f6c2e5b
...
@@ -20,10 +20,9 @@ import Data.Map (Map)
...
@@ -20,10 +20,9 @@ import Data.Map (Map)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.Core
(
Lang
(
..
))
import
Gargantext.Core
(
Lang
(
..
))
import
Gargantext.Core.Text
(
size
)
import
Gargantext.Core.Text
(
size
)
import
Gargantext.Core.Types
(
ListType
(
..
))
import
Gargantext.Core.Types
(
ListType
(
..
))
-- (MasterCorpusId, UserCorpusId)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
)
import
Gargantext.Core.Text.List.Learn
(
Model
(
..
))
-- import Gargantext.Core.Text.List.Learn (Model(..))
import
Gargantext.Core.Types
(
MasterCorpusId
,
UserCorpusId
)
import
Gargantext.Core.Text.Terms.Mono.Stem
(
stem
)
import
Gargantext.Core.Text.Terms.Mono.Stem
(
stem
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Data.Set
as
Set
import
qualified
Data.Set
as
Set
...
@@ -31,7 +30,7 @@ import qualified Data.Map as Map
...
@@ -31,7 +30,7 @@ import qualified Data.Map as Map
import
qualified
Data.List
as
List
import
qualified
Data.List
as
List
import
qualified
Data.Text
as
Text
import
qualified
Data.Text
as
Text
{-
data NgramsListBuilder = BuilderStepO { stemSize :: !Int
data NgramsListBuilder = BuilderStepO { stemSize :: !Int
, stemX :: !Int
, stemX :: !Int
, stopSize :: !StopSize
, stopSize :: !StopSize
...
@@ -45,6 +44,7 @@ data NgramsListBuilder = BuilderStepO { stemSize :: !Int
...
@@ -45,6 +44,7 @@ data NgramsListBuilder = BuilderStepO { stemSize :: !Int
, nlb_userCorpusId :: !UserCorpusId
, nlb_userCorpusId :: !UserCorpusId
, nlb_masterCorpusId :: !MasterCorpusId
, nlb_masterCorpusId :: !MasterCorpusId
}
}
-}
data
StopSize
=
StopSize
{
unStopSize
::
!
Int
}
data
StopSize
=
StopSize
{
unStopSize
::
!
Int
}
...
@@ -52,19 +52,19 @@ data StopSize = StopSize {unStopSize :: !Int}
...
@@ -52,19 +52,19 @@ data StopSize = StopSize {unStopSize :: !Int}
-- discussed. Main purpose of this is offering
-- discussed. Main purpose of this is offering
-- a first grouping option to user and get some
-- a first grouping option to user and get some
-- enriched data to better learn and improve that algo
-- enriched data to better learn and improve that algo
data
GroupParams
=
GroupParams
{
unGroupParams_lang
::
!
Lang
data
GroupParams
=
GroupParams
{
unGroupParams_lang
::
!
Lang
,
unGroupParams_len
::
!
Int
,
unGroupParams_len
::
!
Int
,
unGroupParams_limit
::
!
Int
,
unGroupParams_limit
::
!
Int
,
unGroupParams_stopSize
::
!
StopSize
,
unGroupParams_stopSize
::
!
StopSize
}
}
|
GroupIdentity
|
GroupIdentity
ngramsGroup
::
GroupParams
ngramsGroup
::
GroupParams
->
Text
->
Text
->
Text
->
Text
ngramsGroup
GroupIdentity
=
identity
ngramsGroup
GroupIdentity
=
identity
ngramsGroup
(
GroupParams
l
_m
_n
_
)
=
Text
.
intercalate
" "
ngramsGroup
(
GroupParams
l
_m
_n
_
)
=
Text
.
intercalate
" "
.
map
(
stem
l
)
.
map
(
stem
l
)
-- . take n
-- . take n
.
List
.
sort
.
List
.
sort
...
@@ -72,12 +72,18 @@ ngramsGroup (GroupParams l _m _n _) = Text.intercalate " "
...
@@ -72,12 +72,18 @@ ngramsGroup (GroupParams l _m _n _) = Text.intercalate " "
.
Text
.
splitOn
" "
.
Text
.
splitOn
" "
.
Text
.
replace
"-"
" "
.
Text
.
replace
"-"
" "
------------------------------------------------------------------------------
------------------------------------------------------------------------
mergeMapParent
::
Map
Text
(
GroupedText
b
)
->
Map
Text
(
Map
Text
Int
)
->
Map
Text
(
GroupedText
b
)
mergeMapParent
=
undefined
------------------------------------------------------------------------
toGroupedText
::
Ord
b
toGroupedText
::
Ord
b
=>
(
Text
->
Text
)
=>
(
Text
->
Text
)
->
(
a
->
b
)
->
(
a
->
b
)
->
(
a
->
Set
Text
)
->
(
a
->
Set
Text
)
->
(
a
->
Set
NodeId
)
->
(
a
->
Set
NodeId
)
->
[(
Text
,
a
)]
->
[(
Text
,
a
)]
->
Map
Stem
(
GroupedText
b
)
->
Map
Stem
(
GroupedText
b
)
toGroupedText
fun_stem
fun_score
fun_texts
fun_nodeIds
from
=
groupStems'
$
map
group
from
toGroupedText
fun_stem
fun_score
fun_texts
fun_nodeIds
from
=
groupStems'
$
map
group
from
...
@@ -108,7 +114,7 @@ groupStems' = Map.fromListWith grouping
...
@@ -108,7 +114,7 @@ groupStems' = Map.fromListWith grouping
gr
=
Set
.
union
group1
group2
gr
=
Set
.
union
group1
group2
nodes
=
Set
.
union
nodes1
nodes2
nodes
=
Set
.
union
nodes1
nodes2
------------------------------------------------------------------------
------
------------------------------------------------------------------------
type
Group
=
Lang
->
Int
->
Int
->
Text
->
Text
type
Group
=
Lang
->
Int
->
Int
->
Text
->
Text
type
Stem
=
Text
type
Stem
=
Text
type
Label
=
Text
type
Label
=
Text
...
@@ -116,15 +122,15 @@ data GroupedText score =
...
@@ -116,15 +122,15 @@ data GroupedText score =
GroupedText
{
_gt_listType
::
!
(
Maybe
ListType
)
GroupedText
{
_gt_listType
::
!
(
Maybe
ListType
)
,
_gt_label
::
!
Label
,
_gt_label
::
!
Label
,
_gt_score
::
!
score
,
_gt_score
::
!
score
,
_gt_
group
::
!
(
Set
Text
)
,
_gt_
children
::
!
(
Set
Text
)
,
_gt_size
::
!
Int
,
_gt_size
::
!
Int
,
_gt_stem
::
!
Stem
,
_gt_stem
::
!
Stem
,
_gt_nodes
::
!
(
Set
NodeId
)
,
_gt_nodes
::
!
(
Set
NodeId
)
}
deriving
Show
}
{-deriving Show--}
{-
--
{-
instance
Show
score
=>
Show
(
GroupedText
score
)
where
instance
Show
score
=>
Show
(
GroupedText
score
)
where
show
(
GroupedText
lt
l
s
_
_
_
_
)
=
show
l
<>
" : "
<>
show
lt
<>
" : "
<>
show
s
show
(
GroupedText
lt
l
s
_
_
_
_
)
=
show
l
<>
" : "
<>
show
lt
<>
" : "
<>
show
s
-}
-
-
}
instance
(
Eq
a
)
=>
Eq
(
GroupedText
a
)
where
instance
(
Eq
a
)
=>
Eq
(
GroupedText
a
)
where
(
==
)
(
GroupedText
_
_
score1
_
_
_
_
)
(
==
)
(
GroupedText
_
_
score1
_
_
_
_
)
...
@@ -137,18 +143,13 @@ instance (Eq a, Ord a) => Ord (GroupedText a) where
...
@@ -137,18 +143,13 @@ instance (Eq a, Ord a) => Ord (GroupedText a) where
-- Lenses Instances
-- Lenses Instances
makeLenses
'G
r
oupedText
makeLenses
'G
r
oupedText
------------------------------------------------------------------------
------
------------------------------------------------------------------------
addListType
::
Map
Text
ListType
->
GroupedText
a
->
GroupedText
a
addListType
::
Map
Text
ListType
->
GroupedText
a
->
GroupedText
a
addListType
m
g
=
set
gt_listType
(
hasListType
m
g
)
g
addListType
m
g
=
set
gt_listType
(
hasListType
m
g
)
g
where
where
hasListType
::
Map
Text
ListType
->
GroupedText
a
->
Maybe
ListType
hasListType
::
Map
Text
ListType
->
GroupedText
a
->
Maybe
ListType
hasListType
m'
(
GroupedText
_
label
_
g'
_
_
_
)
=
hasListType
m'
(
GroupedText
_
label
_
g'
_
_
_
)
=
List
.
foldl'
(
<>
)
Nothing
List
.
foldl'
(
<>
)
Nothing
$
map
(
\
t
->
Map
.
lookup
t
m'
)
$
map
(
\
t
->
Map
.
lookup
t
m'
)
$
Set
.
toList
$
Set
.
toList
$
Set
.
insert
label
g'
$
Set
.
insert
label
g'
src/Gargantext/Core/Text/List.hs
View file @
0f6c2e5b
...
@@ -58,8 +58,8 @@ buildNgramsLists :: ( RepoCmdM env err m
...
@@ -58,8 +58,8 @@ buildNgramsLists :: ( RepoCmdM env err m
buildNgramsLists
user
gp
uCid
mCid
=
do
buildNgramsLists
user
gp
uCid
mCid
=
do
ngTerms
<-
buildNgramsTermsList
user
uCid
mCid
gp
ngTerms
<-
buildNgramsTermsList
user
uCid
mCid
gp
othersTerms
<-
mapM
(
buildNgramsOthersList
user
uCid
(
ngramsGroup
GroupIdentity
))
othersTerms
<-
mapM
(
buildNgramsOthersList
user
uCid
(
ngramsGroup
GroupIdentity
))
[
(
Authors
,
MapListSize
9
)
[
(
Authors
,
MapListSize
9
)
,
(
Sources
,
MapListSize
9
)
,
(
Sources
,
MapListSize
9
)
,
(
Institutes
,
MapListSize
9
)
,
(
Institutes
,
MapListSize
9
)
]
]
...
@@ -83,12 +83,13 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do
...
@@ -83,12 +83,13 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do
ngs
<-
groupNodesByNgramsWith
groupIt
<$>
getNodesByNgramsUser
uCid
nt
ngs
<-
groupNodesByNgramsWith
groupIt
<$>
getNodesByNgramsUser
uCid
nt
let
let
grouped
=
toGroupedText
groupIt
(
Set
.
size
.
snd
)
fst
snd
(
Map
.
toList
$
Map
.
mapWithKey
(
\
k
(
a
,
b
)
->
(
Set
.
delete
k
a
,
b
))
$
ngs
)
grouped
=
toGroupedText
groupIt
(
Set
.
size
.
snd
)
fst
snd
(
Map
.
toList
$
Map
.
mapWithKey
(
\
k
(
a
,
b
)
->
(
Set
.
delete
k
a
,
b
))
$
ngs
)
socialLists
<-
flowSocialList
user
nt
(
Set
.
fromList
$
Map
.
keys
ngs
)
socialLists
<-
flowSocialList
user
nt
(
Set
.
fromList
$
Map
.
keys
ngs
)
let
let
groupedWithList
=
map
(
addListType
(
invertForw
socialLists
))
grouped
groupedWithList
=
map
(
addListType
(
invertForw
socialLists
))
grouped
(
stopTerms
,
tailTerms
)
=
Map
.
partition
(
\
t
->
t
^.
gt_listType
==
Just
StopTerm
)
groupedWithList
(
stopTerms
,
tailTerms
)
=
Map
.
partition
(
\
t
->
t
^.
gt_listType
==
Just
StopTerm
)
groupedWithList
(
mapTerms
,
tailTerms'
)
=
Map
.
partition
(
\
t
->
t
^.
gt_listType
==
Just
MapTerm
)
tailTerms
(
mapTerms
,
tailTerms'
)
=
Map
.
partition
(
\
t
->
t
^.
gt_listType
==
Just
MapTerm
)
tailTerms
...
...
src/Gargantext/Core/Text/List/Social.hs
View file @
0f6c2e5b
...
@@ -35,6 +35,7 @@ import qualified Data.List as List
...
@@ -35,6 +35,7 @@ import qualified Data.List as List
import
qualified
Data.Map
as
Map
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
import
qualified
Data.Set
as
Set
------------------------------------------------------------------------
flowSocialList
::
(
RepoCmdM
env
err
m
flowSocialList
::
(
RepoCmdM
env
err
m
,
CmdM
env
err
m
,
CmdM
env
err
m
,
HasNodeError
err
,
HasNodeError
err
...
@@ -56,7 +57,6 @@ flowSocialList user nt ngrams' = do
...
@@ -56,7 +57,6 @@ flowSocialList user nt ngrams' = do
-- printDebug "* socialLists *: results \n" result
-- printDebug "* socialLists *: results \n" result
pure
result
pure
result
------------------------------------------------------------------------
------------------------------------------------------------------------
unions
::
(
Ord
a
,
Semigroup
a
,
Semigroup
b
,
Ord
b
)
unions
::
(
Ord
a
,
Semigroup
a
,
Semigroup
b
,
Ord
b
)
=>
[
Map
a
(
Set
b
)]
->
Map
a
(
Set
b
)
=>
[
Map
a
(
Set
b
)]
->
Map
a
(
Set
b
)
...
@@ -75,13 +75,12 @@ invertBack = Map.fromListWith (<>)
...
@@ -75,13 +75,12 @@ invertBack = Map.fromListWith (<>)
unions_test
::
Map
ListType
(
Set
Text
)
unions_test
::
Map
ListType
(
Set
Text
)
unions_test
=
unions
[
m1
,
m2
]
unions_test
=
unions
[
m1
,
m2
]
where
where
m1
=
Map
.
fromList
[
(
StopTerm
,
Set
.
singleton
"Candidate"
)]
m1
=
Map
.
fromList
[
(
StopTerm
,
Set
.
singleton
"Candidate"
)]
m2
=
Map
.
fromList
[
(
CandidateTerm
,
Set
.
singleton
"Candidate"
)
m2
=
Map
.
fromList
[
(
CandidateTerm
,
Set
.
singleton
"Candidate"
)
,
(
MapTerm
,
Set
.
singleton
"Candidate"
)
,
(
MapTerm
,
Set
.
singleton
"Candidate"
)
]
]
------------------------------------------------------------------------
------------------------------------------------------------------------
termsByList
::
ListType
->
(
Map
(
Maybe
ListType
)
(
Set
Text
))
->
Set
Text
termsByList
::
ListType
->
(
Map
(
Maybe
ListType
)
(
Set
Text
))
->
Set
Text
termsByList
CandidateTerm
m
=
Set
.
unions
termsByList
CandidateTerm
m
=
Set
.
unions
$
map
(
\
lt
->
fromMaybe
Set
.
empty
$
Map
.
lookup
lt
m
)
$
map
(
\
lt
->
fromMaybe
Set
.
empty
$
Map
.
lookup
lt
m
)
...
@@ -108,7 +107,7 @@ flowSocialListByMode mode user nt ngrams' = do
...
@@ -108,7 +107,7 @@ flowSocialListByMode mode user nt ngrams' = do
-- printDebug "flowSocialListByMode r" r
-- printDebug "flowSocialListByMode r" r
pure
r
pure
r
------------------------------------------------------------------------
---
------------------------------------------------------------------------
-- TODO: maybe use social groups too
-- TODO: maybe use social groups too
toSocialList
::
Map
Text
(
Map
ListType
Int
)
toSocialList
::
Map
Text
(
Map
ListType
Int
)
->
Set
Text
->
Set
Text
...
@@ -141,7 +140,7 @@ toSocialList1_testIsTrue = result == (Just MapTerm, Set.singleton token)
...
@@ -141,7 +140,7 @@ toSocialList1_testIsTrue = result == (Just MapTerm, Set.singleton token)
,
(
StopTerm
,
3
)
,
(
StopTerm
,
3
)
]
]
------------------------------------------------------------------------
---
------------------------------------------------------------------------
-- | [ListId] does not merge the lists (it is for Master and User lists
-- | [ListId] does not merge the lists (it is for Master and User lists
-- here we need UserList only
-- here we need UserList only
countFilterList
::
RepoCmdM
env
err
m
countFilterList
::
RepoCmdM
env
err
m
...
@@ -161,14 +160,83 @@ countFilterList' st nt ls input = do
...
@@ -161,14 +160,83 @@ countFilterList' st nt ls input = do
-- printDebug "countFilterList'" ml
-- printDebug "countFilterList'" ml
pure
$
Set
.
foldl'
(
\
m
t
->
countList
t
ml
m
)
input
st
pure
$
Set
.
foldl'
(
\
m
t
->
countList
t
ml
m
)
input
st
------------------------------------------------------------------------
---
------------------------------------------------------------------------
-- FIXME children have to herit the ListType of the parent
-- FIXME children have to herit the ListType of the parent
toMapTextListType
::
Map
Text
NgramsRepoElement
->
Map
Text
ListType
toMapTextListType
::
Map
Text
NgramsRepoElement
->
Map
Text
ListType
toMapTextListType
m
=
Map
.
fromListWith
(
<>
)
toMapTextListType
m
=
Map
.
fromListWith
(
<>
)
$
List
.
concat
$
List
.
concat
$
(
map
(
toList
m
))
$
map
(
toList
m
)
$
Map
.
toList
m
$
Map
.
toList
m
----------------------
-- | Tools to inherit groupings
----------------------
type
Parent
=
Text
parentUnionsMerge
::
(
Ord
a
,
Ord
b
,
Num
c
)
=>
[
Map
a
(
Map
b
c
)]
->
Map
a
(
Map
b
c
)
parentUnionsMerge
=
Map
.
unionsWith
(
Map
.
unionWith
(
+
))
-- This Parent union is specific
-- [Private, Shared, Public]
-- means the following preferences:
-- Private > Shared > Public
-- if data have not been tagged privately, then use others tags
-- This unions behavior takes first key only and ignore others
parentUnionsExcl
::
Ord
a
=>
[
Map
a
b
]
->
Map
a
b
parentUnionsExcl
=
Map
.
unions
hasParent
::
Text
->
Map
Text
(
Map
Parent
Int
)
->
Maybe
Parent
hasParent
t
m
=
case
Map
.
lookup
t
m
of
Nothing
->
Nothing
Just
m'
->
(
fst
.
fst
)
<$>
Map
.
maxViewWithKey
m'
toMapTextParent
::
Set
Text
->
Map
Text
(
Map
Parent
Int
)
->
[
Map
Text
NgramsRepoElement
]
->
Map
Text
(
Map
Parent
Int
)
toMapTextParent
ts
=
foldl'
(
toMapTextParent'
ts
)
where
toMapTextParent'
::
Set
Text
->
Map
Text
(
Map
Parent
Int
)
->
Map
Text
NgramsRepoElement
->
Map
Text
(
Map
Parent
Int
)
toMapTextParent'
ts'
to
from
=
Set
.
foldl'
(
toMapTextParent''
ts'
from
)
to
ts'
toMapTextParent''
::
Set
Text
->
Map
Text
NgramsRepoElement
->
Map
Text
(
Map
Parent
Int
)
->
Text
->
Map
Text
(
Map
Parent
Int
)
toMapTextParent''
ss
from
to
t
=
case
Map
.
lookup
t
from
of
Nothing
->
to
Just
nre
->
case
_nre_parent
nre
of
Just
(
NgramsTerm
p'
)
->
if
Set
.
member
p'
ss
then
Map
.
alter
(
addParent
p'
)
t
to
else
to
where
addParent
p''
Nothing
=
Just
$
addCountParent
p''
Map
.
empty
addParent
p''
(
Just
ps
)
=
Just
$
addCountParent
p''
ps
addCountParent
::
Parent
->
Map
Parent
Int
->
Map
Parent
Int
addCountParent
p
m
=
Map
.
alter
addCount
p
m
where
addCount
Nothing
=
Just
1
addCount
(
Just
n
)
=
Just
$
n
+
1
_
->
to
------------------------------------------------------------------------
toList
::
Map
Text
NgramsRepoElement
->
(
Text
,
NgramsRepoElement
)
->
[(
Text
,
ListType
)]
toList
::
Map
Text
NgramsRepoElement
->
(
Text
,
NgramsRepoElement
)
->
[(
Text
,
ListType
)]
toList
m
(
t
,
nre
@
(
NgramsRepoElement
_
_
_
_
(
MSet
children
)))
=
toList
m
(
t
,
nre
@
(
NgramsRepoElement
_
_
_
_
(
MSet
children
)))
=
List
.
zip
terms
(
List
.
cycle
[
lt'
])
List
.
zip
terms
(
List
.
cycle
[
lt'
])
...
@@ -184,9 +252,10 @@ listOf m ng = case _nre_parent ng of
...
@@ -184,9 +252,10 @@ listOf m ng = case _nre_parent ng of
Nothing
->
_nre_list
ng
Nothing
->
_nre_list
ng
Just
p
->
case
Map
.
lookup
(
unNgramsTerm
p
)
m
of
Just
p
->
case
Map
.
lookup
(
unNgramsTerm
p
)
m
of
Just
ng'
->
listOf
m
ng'
Just
ng'
->
listOf
m
ng'
Nothing
->
panic
"CandidateTerm -- Should Not happen"
Nothing
->
CandidateTerm
-- panic "[G.C.T.L.Social.listOf] Nothing: Should Not happen"
------------------------------------------------------------------------
---
------------------------------------------------------------------------
countList
::
Text
countList
::
Text
->
Map
Text
ListType
->
Map
Text
ListType
->
Map
Text
(
Map
ListType
Int
)
->
Map
Text
(
Map
ListType
Int
)
...
@@ -195,11 +264,11 @@ countList t m input = case Map.lookup t m of
...
@@ -195,11 +264,11 @@ countList t m input = case Map.lookup t m of
Nothing
->
input
Nothing
->
input
Just
l
->
Map
.
alter
addList
t
input
Just
l
->
Map
.
alter
addList
t
input
where
where
addList
Nothing
=
Just
$
addCount
l
Map
.
empty
addList
Nothing
=
Just
$
addCount
List
l
Map
.
empty
addList
(
Just
lm
)
=
Just
$
addCount
l
lm
addList
(
Just
lm
)
=
Just
$
addCount
List
l
lm
addCount
::
ListType
->
Map
ListType
Int
->
Map
ListType
Int
addCount
List
::
ListType
->
Map
ListType
Int
->
Map
ListType
Int
addCount
l
m
=
Map
.
alter
(
plus
l
)
l
m
addCount
List
l
m
=
Map
.
alter
(
plus
l
)
l
m
where
where
plus
CandidateTerm
Nothing
=
Just
1
plus
CandidateTerm
Nothing
=
Just
1
plus
CandidateTerm
(
Just
x
)
=
Just
$
x
+
1
plus
CandidateTerm
(
Just
x
)
=
Just
$
x
+
1
...
@@ -228,5 +297,3 @@ findNodes' Public r = findNodes Public r $ [NodeFolderPublic ] <> commonNodes
...
@@ -228,5 +297,3 @@ findNodes' Public r = findNodes Public r $ [NodeFolderPublic ] <> commonNodes
commonNodes
::
[
NodeType
]
commonNodes
::
[
NodeType
]
commonNodes
=
[
NodeFolder
,
NodeCorpus
,
NodeList
]
commonNodes
=
[
NodeFolder
,
NodeCorpus
,
NodeList
]
src/Gargantext/Core/Viz/Graph/Tools.hs
View file @
0f6c2e5b
...
@@ -47,7 +47,7 @@ cooc2graph' distance threshold myCooc = distanceMap
...
@@ -47,7 +47,7 @@ cooc2graph' distance threshold myCooc = distanceMap
where
where
(
ti
,
_
)
=
createIndices
myCooc
(
ti
,
_
)
=
createIndices
myCooc
myCooc'
=
toIndex
ti
myCooc
myCooc'
=
toIndex
ti
myCooc
matCooc
=
map2mat
0
(
Map
.
size
ti
)
$
Map
.
filter
(
>
0
)
myCooc'
matCooc
=
map2mat
0
(
Map
.
size
ti
)
$
Map
.
filter
(
>
1
)
myCooc'
distanceMat
=
measure
distance
matCooc
distanceMat
=
measure
distance
matCooc
distanceMap
=
Map
.
filter
(
>
threshold
)
$
mat2map
distanceMat
distanceMap
=
Map
.
filter
(
>
threshold
)
$
mat2map
distanceMat
...
...
src/Gargantext/Core/Viz/Phylo.hs
View file @
0f6c2e5b
This diff is collapsed.
Click to expand it.
src/Gargantext/Core/Viz/Phylo/API.hs
View file @
0f6c2e5b
...
@@ -17,6 +17,7 @@ Portability : POSIX
...
@@ -17,6 +17,7 @@ Portability : POSIX
module
Gargantext.Core.Viz.Phylo.API
module
Gargantext.Core.Viz.Phylo.API
where
where
import
Data.Maybe
(
fromMaybe
)
import
Control.Lens
((
^.
))
import
Control.Lens
((
^.
))
import
Data.String.Conversions
import
Data.String.Conversions
--import Control.Monad.Reader (ask)
--import Control.Monad.Reader (ask)
...
@@ -98,13 +99,13 @@ getPhylo :: PhyloId -> GargServer GetPhylo
...
@@ -98,13 +99,13 @@ getPhylo :: PhyloId -> GargServer GetPhylo
getPhylo
phId
_lId
l
msb
=
do
getPhylo
phId
_lId
l
msb
=
do
phNode
<-
getNodeWith
phId
(
Proxy
::
Proxy
HyperdataPhylo
)
phNode
<-
getNodeWith
phId
(
Proxy
::
Proxy
HyperdataPhylo
)
let
let
level
=
maybe
2
identity
l
level
=
fromMaybe
2
l
branc
=
maybe
2
identity
msb
branc
=
fromMaybe
2
msb
maybePhylo
=
phNode
^.
(
node_hyperdata
.
hp_data
)
maybePhylo
=
phNode
^.
(
node_hyperdata
.
hp_data
)
p
<-
liftBase
$
viewPhylo2Svg
p
<-
liftBase
$
viewPhylo2Svg
$
viewPhylo
level
branc
$
viewPhylo
level
branc
$
maybe
phyloFromQuery
identit
y
maybePhylo
$
fromMaybe
phyloFromQuer
y
maybePhylo
pure
(
SVG
p
)
pure
(
SVG
p
)
------------------------------------------------------------------------
------------------------------------------------------------------------
type
PostPhylo
=
QueryParam
"listId"
ListId
type
PostPhylo
=
QueryParam
"listId"
ListId
...
@@ -112,16 +113,16 @@ type PostPhylo = QueryParam "listId" ListId
...
@@ -112,16 +113,16 @@ type PostPhylo = QueryParam "listId" ListId
:>
(
Post
'[
J
SON
]
NodeId
)
:>
(
Post
'[
J
SON
]
NodeId
)
postPhylo
::
CorpusId
->
UserId
->
GargServer
PostPhylo
postPhylo
::
CorpusId
->
UserId
->
GargServer
PostPhylo
postPhylo
n
userId
_lId
=
do
postPhylo
corpusId
userId
_lId
=
do
-- TODO get Reader settings
-- TODO get Reader settings
-- s <- ask
-- s <- ask
let
--
let
-- _vrs = Just ("1" :: Text)
-- _vrs = Just ("1" :: Text)
-- _sft = Just (Software "Gargantext" "4")
-- _sft = Just (Software "Gargantext" "4")
-- _prm = initPhyloParam vrs sft (Just q)
-- _prm = initPhyloParam vrs sft (Just q)
phy
<-
flowPhylo
n
phy
<-
flowPhylo
corpusId
-- params
p
Id
<-
insertNodes
[
node
NodePhylo
"Phylo"
(
HyperdataPhylo
Nothing
(
Just
phy
))
(
Just
n
)
userId
]
p
hyloId
<-
insertNodes
[
node
NodePhylo
"Phylo"
(
HyperdataPhylo
Nothing
(
Just
phy
))
(
Just
corpusId
)
userId
]
pure
$
NodeId
(
fromIntegral
pId
)
pure
$
NodeId
(
fromIntegral
p
hylo
Id
)
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | DELETE Phylo == delete a node
-- | DELETE Phylo == delete a node
...
@@ -136,64 +137,25 @@ putPhylo = undefined
...
@@ -136,64 +137,25 @@ putPhylo = undefined
-- | Instances
-- | Instances
instance
Arbitrary
PhyloView
instance
Arbitrary
Phylo
where
arbitrary
=
elements
[
phylo
]
where
instance
Arbitrary
PhyloGroup
where
arbitrary
=
elements
[]
arbitrary
=
elements
[
phyloView
]
instance
Arbitrary
PhyloView
where
arbitrary
=
elements
[
phyloView
]
instance
FromHttpApiData
DisplayMode
where
parseUrlPiece
=
readTextData
-- | TODO add phyloGroup ex
instance
FromHttpApiData
ExportMode
where
parseUrlPiece
=
readTextData
instance
Arbitrary
PhyloGroup
instance
FromHttpApiData
Filiation
where
parseUrlPiece
=
readTextData
where
instance
FromHttpApiData
Metric
where
parseUrlPiece
=
readTextData
arbitrary
=
elements
[]
instance
FromHttpApiData
Order
where
parseUrlPiece
=
readTextData
instance
FromHttpApiData
Sort
where
parseUrlPiece
=
readTextData
instance
Arbitrary
Phylo
instance
FromHttpApiData
Tagger
where
parseUrlPiece
=
readTextData
where
instance
FromHttpApiData
[
Metric
]
where
parseUrlPiece
=
readTextData
arbitrary
=
elements
[
phylo
]
instance
FromHttpApiData
[
Tagger
]
where
parseUrlPiece
=
readTextData
instance
ToSchema
Order
instance
ToParamSchema
Order
instance
FromHttpApiData
Order
where
parseUrlPiece
=
readTextData
instance
ToParamSchema
Metric
instance
FromHttpApiData
[
Metric
]
where
parseUrlPiece
=
readTextData
instance
FromHttpApiData
Metric
where
parseUrlPiece
=
readTextData
instance
ToParamSchema
DisplayMode
instance
ToParamSchema
DisplayMode
instance
FromHttpApiData
DisplayMode
where
parseUrlPiece
=
readTextData
instance
ToParamSchema
ExportMode
instance
ToParamSchema
ExportMode
instance
FromHttpApiData
ExportMode
where
parseUrlPiece
=
readTextData
instance
FromHttpApiData
Sort
where
parseUrlPiece
=
readTextData
instance
ToParamSchema
Sort
instance
FromHttpApiData
[
Tagger
]
where
parseUrlPiece
=
readTextData
instance
FromHttpApiData
Tagger
where
parseUrlPiece
=
readTextData
instance
ToParamSchema
Tagger
instance
FromHttpApiData
Filiation
where
parseUrlPiece
=
readTextData
instance
ToParamSchema
Filiation
instance
ToParamSchema
Filiation
instance
ToParamSchema
Tagger
instance
ToParamSchema
Metric
instance
ToParamSchema
Order
instance
ToParamSchema
Sort
instance
ToSchema
Order
src/Gargantext/Core/Viz/Phylo/LevelMaker.hs
View file @
0f6c2e5b
...
@@ -44,7 +44,6 @@ import Numeric.Statistics (percentile)
...
@@ -44,7 +44,6 @@ import Numeric.Statistics (percentile)
-- | PhyloLevelMaker | --
-- | PhyloLevelMaker | --
-------------------------
-------------------------
-- | A typeClass for polymorphic PhyloLevel functions
-- | A typeClass for polymorphic PhyloLevel functions
class
PhyloLevelMaker
aggregate
class
PhyloLevelMaker
aggregate
where
where
...
@@ -105,11 +104,15 @@ instance PhyloLevelMaker Document
...
@@ -105,11 +104,15 @@ instance PhyloLevelMaker Document
addPhyloLevel'
::
PhyloLevelMaker
a
=>
Level
->
Map
(
Date
,
Date
)
[
a
]
->
Phylo
->
Phylo
addPhyloLevel'
::
PhyloLevelMaker
a
=>
Level
->
Map
(
Date
,
Date
)
[
a
]
->
Phylo
->
Phylo
addPhyloLevel'
lvl
m
p
=
alterPhyloPeriods
addPhyloLevel'
lvl
m
p
=
alterPhyloPeriods
(
\
period
->
let
pId
=
_phylo_periodId
period
(
\
period
->
let
pId
=
_phylo_periodId
period
in
over
(
phylo_periodLevels
)
in
over
phylo_periodLevels
(
\
phyloLevels
->
(
\
phyloLevels
->
let
groups
=
toPhyloGroups
lvl
pId
(
m
!
pId
)
m
p
let
groups
=
toPhyloGroups
lvl
pId
(
m
!
pId
)
m
p
in
trace
(
show
(
length
groups
)
<>
" groups for "
<>
show
(
pId
)
)
$
phyloLevels
++
[
PhyloLevel
(
pId
,
lvl
)
groups
]
in
trace
(
show
(
length
groups
)
)
period
)
p
<>
" groups for "
<>
show
(
pId
)
)
$
phyloLevels
++
[
PhyloLevel
(
pId
,
lvl
)
groups
]
)
period
)
p
----------------------
----------------------
...
@@ -118,7 +121,14 @@ addPhyloLevel' lvl m p = alterPhyloPeriods
...
@@ -118,7 +121,14 @@ addPhyloLevel' lvl m p = alterPhyloPeriods
-- | To transform a Clique into a PhyloGroup
-- | To transform a Clique into a PhyloGroup
cliqueToGroup
::
PhyloPeriodId
->
Level
->
Int
->
Text
->
PhyloFis
->
Map
Date
(
Map
(
Int
,
Int
)
Double
)
->
Vector
Ngrams
->
PhyloGroup
cliqueToGroup
::
PhyloPeriodId
->
Level
->
Int
->
Text
->
PhyloFis
->
Map
Date
(
Map
(
Int
,
Int
)
Double
)
->
Vector
Ngrams
->
PhyloGroup
cliqueToGroup
prd
lvl
idx
lbl
fis
cooc'
root
=
PhyloGroup
((
prd
,
lvl
),
idx
)
lbl
ngrams
cliqueToGroup
prd
lvl
idx
lbl
fis
cooc'
root
=
PhyloGroup
((
prd
,
lvl
),
idx
)
lbl
ngrams
(
getNgramsMeta
cooc
ngrams
)
(
getNgramsMeta
cooc
ngrams
)
-- empty
-- empty
...
@@ -142,10 +152,17 @@ cliqueToGroup prd lvl idx lbl fis cooc' root = PhyloGroup ((prd, lvl), idx) lbl
...
@@ -142,10 +152,17 @@ cliqueToGroup prd lvl idx lbl fis cooc' root = PhyloGroup ((prd, lvl), idx) lbl
-- | To transform a Cluster into a Phylogroup
-- | To transform a Cluster into a Phylogroup
clusterToGroup
::
PhyloPeriodId
->
Level
->
Int
->
Text
->
PhyloCluster
->
Map
(
Date
,
Date
)
[
PhyloCluster
]
->
Phylo
->
PhyloGroup
clusterToGroup
::
PhyloPeriodId
->
Level
->
Int
->
Text
->
PhyloCluster
->
Map
(
Date
,
Date
)
[
PhyloCluster
]
->
Phylo
->
PhyloGroup
clusterToGroup
prd
lvl
idx
lbl
groups
_m
p
=
clusterToGroup
prd
lvl
idx
lbl
groups
_m
p
=
PhyloGroup
((
prd
,
lvl
),
idx
)
lbl
ngrams
PhyloGroup
((
prd
,
lvl
),
idx
)
lbl
ngrams
(
getNgramsMeta
cooc
ngrams
)
(
getNgramsMeta
cooc
ngrams
)
-- empty
-- empty
empty
empty
Nothing
Nothing
...
@@ -154,12 +171,14 @@ clusterToGroup prd lvl idx lbl groups _m p =
...
@@ -154,12 +171,14 @@ clusterToGroup prd lvl idx lbl groups _m p =
where
where
--------------------------------------
--------------------------------------
cooc
::
Map
(
Int
,
Int
)
Double
cooc
::
Map
(
Int
,
Int
)
Double
cooc
=
getMiniCooc
(
listToFullCombi
ngrams
)
(
periodsToYears
[
prd
])
(
getPhyloCooc
p
)
cooc
=
getMiniCooc
(
listToFullCombi
ngrams
)
(
periodsToYears
[
prd
]
)
(
getPhyloCooc
p
)
--------------------------------------
--------------------------------------
childs
::
[
Pointer
]
childs
::
[
Pointer
]
childs
=
map
(
\
g
->
(
getGroupId
g
,
1
))
groups
childs
=
map
(
\
g
->
(
getGroupId
g
,
1
))
groups
ascLink
=
concat
$
map
getGroupPeriodParents
groups
ascLink
=
concat
$
map
getGroupPeriodParents
groups
desLink
=
concat
$
map
getGroupPeriodChilds
groups
desLink
=
concat
$
map
getGroupPeriodChilds
groups
--------------------------------------
--------------------------------------
ngrams
::
[
Int
]
ngrams
::
[
Int
]
ngrams
=
(
sort
.
nub
.
concat
)
$
map
getGroupNgrams
groups
ngrams
=
(
sort
.
nub
.
concat
)
$
map
getGroupNgrams
groups
...
@@ -195,9 +214,13 @@ toPhylo q c termList fis = toNthLevel (getNthLevel q) (getInterTemporalMatching
...
@@ -195,9 +214,13 @@ toPhylo q c termList fis = toNthLevel (getNthLevel q) (getInterTemporalMatching
phyloDocs
=
groupDocsByPeriod
date
(
getPhyloPeriods
phyloBase
)
c
phyloDocs
=
groupDocsByPeriod
date
(
getPhyloPeriods
phyloBase
)
c
--------------------------------------
--------------------------------------
phyloBase
::
Phylo
phyloBase
::
Phylo
phyloBase
=
tracePhyloBase
phyloBase
=
tracePhyloBase
$
toPhyloBase
q
(
initPhyloParam
(
Just
defaultPhyloVersion
)
(
Just
defaultSoftware
)
(
Just
q
))
c
termList
fis
$
toPhyloBase
q
init
c
termList
fis
--------------------------------------
where
init
=
initPhyloParam
(
Just
defaultPhyloVersion
)
(
Just
defaultSoftware
)
(
Just
q
)
---------------------------------------
-- | To incrementally add new Levels to a Phylo by making all the linking and aggregation tasks
-- | To incrementally add new Levels to a Phylo by making all the linking and aggregation tasks
...
@@ -205,17 +228,16 @@ toNthLevel :: Level -> Proximity -> Cluster -> Phylo -> Phylo
...
@@ -205,17 +228,16 @@ toNthLevel :: Level -> Proximity -> Cluster -> Phylo -> Phylo
toNthLevel
lvlMax
prox
clus
p
toNthLevel
lvlMax
prox
clus
p
|
lvl
>=
lvlMax
=
p
|
lvl
>=
lvlMax
=
p
|
otherwise
=
toNthLevel
lvlMax
prox
clus
|
otherwise
=
toNthLevel
lvlMax
prox
clus
$
traceBranches
(
lvl
+
1
)
$
traceBranches
(
lvl
+
1
)
$
setPhyloBranches
(
lvl
+
1
)
$
setPhyloBranches
(
lvl
+
1
)
-- \$ transposePeriodLinks (lvl + 1)
-- \$ transposePeriodLinks (lvl + 1)
$
traceTranspose
(
lvl
+
1
)
Descendant
$
traceTranspose
(
lvl
+
1
)
Descendant
$
transposeLinks
(
lvl
+
1
)
Descendant
$
transposeLinks
(
lvl
+
1
)
Descendant
$
traceTranspose
(
lvl
+
1
)
Ascendant
$
traceTranspose
(
lvl
+
1
)
Ascendant
$
transposeLinks
(
lvl
+
1
)
Ascendant
$
transposeLinks
(
lvl
+
1
)
Ascendant
$
tracePhyloN
(
lvl
+
1
)
$
tracePhyloN
(
lvl
+
1
)
$
setLevelLinks
(
lvl
,
lvl
+
1
)
$
setLevelLinks
(
lvl
,
lvl
+
1
)
$
addPhyloLevel
(
lvl
+
1
)
$
addPhyloLevel
(
lvl
+
1
)
(
clusters
)
p
(
clusters
)
p
where
where
--------------------------------------
--------------------------------------
clusters
::
Map
(
Date
,
Date
)
[
PhyloCluster
]
clusters
::
Map
(
Date
,
Date
)
[
PhyloCluster
]
...
...
src/Gargantext/Core/Viz/Phylo/Main.hs
View file @
0f6c2e5b
...
@@ -35,12 +35,14 @@ import Gargantext.Database.Schema.Ngrams (NgramsType(..))
...
@@ -35,12 +35,14 @@ import Gargantext.Database.Schema.Ngrams (NgramsType(..))
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Core.Text.Context
(
TermList
)
import
Gargantext.Core.Text.Context
(
TermList
)
import
Gargantext.Core.Text.Terms.WithList
import
Gargantext.Core.Text.Terms.WithList
import
Gargantext.Core.Viz.Phylo
hiding
(
Svg
,
Dot
)
import
Gargantext.Core.Viz.Phylo
hiding
(
Svg
,
Dot
)
import
Gargantext.Core.Viz.Phylo.LevelMaker
import
Gargantext.Core.Viz.Phylo.LevelMaker
(
toPhylo
)
import
Gargantext.Core.Viz.Phylo.Tools
import
Gargantext.Core.Viz.Phylo.Tools
import
Gargantext.Core.Viz.Phylo.View.Export
import
Gargantext.Core.Viz.Phylo.View.Export
import
Gargantext.Core.Viz.Phylo.View.ViewMaker
-- TODO Just Maker is fine
import
Gargantext.Core.Viz.Phylo.View.ViewMaker
-- TODO Just Maker is fine
type
MinSizeBranch
=
Int
type
MinSizeBranch
=
Int
flowPhylo
::
FlowCmdM
env
err
m
flowPhylo
::
FlowCmdM
env
err
m
...
@@ -48,14 +50,14 @@ flowPhylo :: FlowCmdM env err m
...
@@ -48,14 +50,14 @@ flowPhylo :: FlowCmdM env err m
->
m
Phylo
->
m
Phylo
flowPhylo
cId
=
do
flowPhylo
cId
=
do
list
<-
defaultList
cId
list
<-
defaultList
cId
termList
<-
Map
.
toList
<$>
getTermsWith
Text
.
words
[
list
]
NgramsTerms
MapTerm
termList
<-
Map
.
toList
<$>
getTermsWith
Text
.
words
[
list
]
NgramsTerms
MapTerm
docs'
<-
catMaybes
docs'
<-
catMaybes
<$>
map
(
\
h
->
(,)
<$>
_hd_publication_year
h
<$>
map
(
\
h
->
(,)
<$>
_hd_publication_year
h
<*>
_hd_abstract
h
<*>
_hd_abstract
h
)
)
<$>
selectDocs
cId
<$>
selectDocs
cId
let
let
patterns
=
buildPatterns
termList
patterns
=
buildPatterns
termList
...
@@ -65,10 +67,13 @@ flowPhylo cId = do
...
@@ -65,10 +67,13 @@ flowPhylo cId = do
where
where
--------------------------------------
--------------------------------------
termsInText
::
Patterns
->
Text
->
[
Text
]
termsInText
::
Patterns
->
Text
->
[
Text
]
termsInText
pats
txt
=
List
.
nub
$
List
.
concat
$
map
(
map
Text
.
unwords
)
$
extractTermsWithList
pats
txt
termsInText
pats
txt
=
List
.
nub
$
List
.
concat
$
map
(
map
Text
.
unwords
)
$
extractTermsWithList
pats
txt
--------------------------------------
--------------------------------------
docs
=
map
(
(
\
(
y
,
t
)
->
Document
y
t
)
.
filterTerms
patterns
)
docs'
docs
=
map
((
\
(
y
,
t
)
->
Document
y
t
)
.
filterTerms
patterns
)
docs'
--liftBase $ flowPhylo' (List.sortOn date docs) termList l m fp
--liftBase $ flowPhylo' (List.sortOn date docs) termList l m fp
pure
$
buildPhylo
(
List
.
sortOn
date
docs
)
termList
pure
$
buildPhylo
(
List
.
sortOn
date
docs
)
termList
...
@@ -76,9 +81,9 @@ flowPhylo cId = do
...
@@ -76,9 +81,9 @@ flowPhylo cId = do
-- TODO SortedList Document
-- TODO SortedList Document
flowPhylo'
::
[
Document
]
->
TermList
-- ^Build
flowPhylo'
::
[
Document
]
->
TermList
-- ^Build
->
Level
->
MinSizeBranch
-- ^View
->
Level
->
MinSizeBranch
-- ^View
->
FilePath
->
FilePath
->
IO
FilePath
->
IO
FilePath
flowPhylo'
corpus
terms
l
m
fp
=
do
flowPhylo'
corpus
terms
l
m
fp
=
do
let
let
phylo
=
buildPhylo
corpus
terms
phylo
=
buildPhylo
corpus
terms
...
...
src/Gargantext/Core/Viz/Phylo/PhyloExport.hs
View file @
0f6c2e5b
...
@@ -142,6 +142,7 @@ groupToDotNode fdt g bId =
...
@@ -142,6 +142,7 @@ groupToDotNode fdt g bId =
,
toAttr
"lbl"
(
pack
$
show
(
ngramsToLabel
fdt
(
g
^.
phylo_groupNgrams
)))
,
toAttr
"lbl"
(
pack
$
show
(
ngramsToLabel
fdt
(
g
^.
phylo_groupNgrams
)))
,
toAttr
"foundation"
(
pack
$
show
(
idxToLabel
(
g
^.
phylo_groupNgrams
)))
,
toAttr
"foundation"
(
pack
$
show
(
idxToLabel
(
g
^.
phylo_groupNgrams
)))
,
toAttr
"role"
(
pack
$
show
(
idxToLabel'
((
g
^.
phylo_groupMeta
)
!
"dynamics"
)))
,
toAttr
"role"
(
pack
$
show
(
idxToLabel'
((
g
^.
phylo_groupMeta
)
!
"dynamics"
)))
,
toAttr
"frequence"
(
pack
$
show
(
idxToLabel'
((
g
^.
phylo_groupMeta
)
!
"frequence"
)))
])
])
...
@@ -192,7 +193,7 @@ exportToDot phylo export =
...
@@ -192,7 +193,7 @@ exportToDot phylo export =
,(
toAttr
(
fromStrict
"phyloPeriods"
)
$
pack
$
show
(
length
$
elems
$
phylo
^.
phylo_periods
))
,(
toAttr
(
fromStrict
"phyloPeriods"
)
$
pack
$
show
(
length
$
elems
$
phylo
^.
phylo_periods
))
,(
toAttr
(
fromStrict
"phyloBranches"
)
$
pack
$
show
(
length
$
export
^.
export_branches
))
,(
toAttr
(
fromStrict
"phyloBranches"
)
$
pack
$
show
(
length
$
export
^.
export_branches
))
,(
toAttr
(
fromStrict
"phyloGroups"
)
$
pack
$
show
(
length
$
export
^.
export_groups
))
,(
toAttr
(
fromStrict
"phyloGroups"
)
$
pack
$
show
(
length
$
export
^.
export_groups
))
,(
toAttr
(
fromStrict
"phyloTermsFreq"
)
$
pack
$
show
(
toList
$
_phylo_lastTermFreq
phylo
))
--
,(toAttr (fromStrict "phyloTermsFreq") $ pack $ show (toList $ _phylo_lastTermFreq phylo))
])
])
{-
{-
...
@@ -201,7 +202,7 @@ exportToDot phylo export =
...
@@ -201,7 +202,7 @@ exportToDot phylo export =
-- 2) create a layer for the branches labels -}
-- 2) create a layer for the branches labels -}
subgraph
(
Str
"Branches peaks"
)
$
do
subgraph
(
Str
"Branches peaks"
)
$
do
graphAttrs
[
Rank
SameRank
]
--
graphAttrs [Rank SameRank]
{-
{-
-- 3) group the branches by hierarchy
-- 3) group the branches by hierarchy
-- mapM (\branches ->
-- mapM (\branches ->
...
@@ -368,8 +369,8 @@ inclusion m l i = ( (sum $ map (\j -> conditional m j i) l)
...
@@ -368,8 +369,8 @@ inclusion m l i = ( (sum $ map (\j -> conditional m j i) l)
+
(
sum
$
map
(
\
j
->
conditional
m
i
j
)
l
))
/
(
fromIntegral
$
(
length
l
)
+
1
)
+
(
sum
$
map
(
\
j
->
conditional
m
i
j
)
l
))
/
(
fromIntegral
$
(
length
l
)
+
1
)
ngramsMetrics
::
PhyloExport
->
PhyloExport
ngramsMetrics
::
Phylo
->
Phylo
Export
->
PhyloExport
ngramsMetrics
export
=
ngramsMetrics
phylo
export
=
over
(
export_groups
over
(
export_groups
.
traverse
)
.
traverse
)
(
\
g
->
g
&
phylo_groupMeta
%~
insert
"genericity"
(
\
g
->
g
&
phylo_groupMeta
%~
insert
"genericity"
...
@@ -378,6 +379,8 @@ ngramsMetrics export =
...
@@ -378,6 +379,8 @@ ngramsMetrics export =
(
map
(
\
n
->
specificity
(
g
^.
phylo_groupCooc
)
((
g
^.
phylo_groupNgrams
)
\\
[
n
])
n
)
$
g
^.
phylo_groupNgrams
)
(
map
(
\
n
->
specificity
(
g
^.
phylo_groupCooc
)
((
g
^.
phylo_groupNgrams
)
\\
[
n
])
n
)
$
g
^.
phylo_groupNgrams
)
&
phylo_groupMeta
%~
insert
"inclusion"
&
phylo_groupMeta
%~
insert
"inclusion"
(
map
(
\
n
->
inclusion
(
g
^.
phylo_groupCooc
)
((
g
^.
phylo_groupNgrams
)
\\
[
n
])
n
)
$
g
^.
phylo_groupNgrams
)
(
map
(
\
n
->
inclusion
(
g
^.
phylo_groupCooc
)
((
g
^.
phylo_groupNgrams
)
\\
[
n
])
n
)
$
g
^.
phylo_groupNgrams
)
&
phylo_groupMeta
%~
insert
"frequence"
(
map
(
\
n
->
getInMap
n
(
phylo
^.
phylo_lastTermFreq
))
$
g
^.
phylo_groupNgrams
)
)
export
)
export
...
@@ -397,9 +400,9 @@ branchDating export =
...
@@ -397,9 +400,9 @@ branchDating export =
&
branch_meta
%~
insert
"age"
[
fromIntegral
age
]
&
branch_meta
%~
insert
"age"
[
fromIntegral
age
]
&
branch_meta
%~
insert
"size"
[
fromIntegral
$
length
periods
]
)
export
&
branch_meta
%~
insert
"size"
[
fromIntegral
$
length
periods
]
)
export
processMetrics
::
PhyloExport
->
PhyloExport
processMetrics
::
Phylo
->
Phylo
Export
->
PhyloExport
processMetrics
export
=
ngramsMetrics
processMetrics
phylo
export
=
ngramsMetrics
phylo
$
branchDating
export
$
branchDating
export
-----------------
-----------------
...
@@ -598,8 +601,10 @@ toHorizon phylo =
...
@@ -598,8 +601,10 @@ toHorizon phylo =
mapGroups
::
[[
PhyloGroup
]]
mapGroups
::
[[
PhyloGroup
]]
mapGroups
=
map
(
\
prd
->
mapGroups
=
map
(
\
prd
->
let
groups
=
getGroupsFromLevelPeriods
level
[
prd
]
phylo
let
groups
=
getGroupsFromLevelPeriods
level
[
prd
]
phylo
childs
=
getPreviousChildIds
level
frame
prd
periods
phylo
childs
=
getPreviousChildIds
level
frame
prd
periods
phylo
heads
=
filter
(
\
g
->
null
(
g
^.
phylo_groupPeriodParents
)
&&
(
notElem
(
getGroupId
g
)
childs
))
groups
-- maybe add a better filter for non isolated ancestors
heads
=
filter
(
\
g
->
(
not
.
null
)
$
(
g
^.
phylo_groupPeriodChilds
))
$
filter
(
\
g
->
null
(
g
^.
phylo_groupPeriodParents
)
&&
(
notElem
(
getGroupId
g
)
childs
))
groups
noHeads
=
groups
\\
heads
noHeads
=
groups
\\
heads
nbDocs
=
sum
$
elems
$
filterDocs
(
phylo
^.
phylo_timeDocs
)
[
prd
]
nbDocs
=
sum
$
elems
$
filterDocs
(
phylo
^.
phylo_timeDocs
)
[
prd
]
diago
=
reduceDiagos
$
filterDiago
(
phylo
^.
phylo_timeCooc
)
[
prd
]
diago
=
reduceDiagos
$
filterDiago
(
phylo
^.
phylo_timeCooc
)
[
prd
]
...
@@ -630,7 +635,7 @@ toPhyloExport phylo = exportToDot phylo
...
@@ -630,7 +635,7 @@ toPhyloExport phylo = exportToDot phylo
$
processFilters
(
exportFilter
$
getConfig
phylo
)
(
phyloQuality
$
getConfig
phylo
)
$
processFilters
(
exportFilter
$
getConfig
phylo
)
(
phyloQuality
$
getConfig
phylo
)
$
processSort
(
exportSort
$
getConfig
phylo
)
(
getSeaElevation
phylo
)
$
processSort
(
exportSort
$
getConfig
phylo
)
(
getSeaElevation
phylo
)
$
processLabels
(
exportLabel
$
getConfig
phylo
)
(
getRoots
phylo
)
(
_phylo_lastTermFreq
phylo
)
$
processLabels
(
exportLabel
$
getConfig
phylo
)
(
getRoots
phylo
)
(
_phylo_lastTermFreq
phylo
)
$
processMetrics
export
$
processMetrics
phylo
export
where
where
export
::
PhyloExport
export
::
PhyloExport
export
=
PhyloExport
groups
branches
export
=
PhyloExport
groups
branches
...
...
src/Gargantext/Core/Viz/Phylo/PhyloMaker.hs
View file @
0f6c2e5b
...
@@ -37,6 +37,17 @@ import qualified Data.Set as Set
...
@@ -37,6 +37,17 @@ import qualified Data.Set as Set
-- | To Phylo | --
-- | To Phylo | --
------------------
------------------
{-
-- TODO AD
data Phylo' = PhyloBase { _phylo'_phyloBase :: Phylo}
| PhyloN { _phylo'_phylo1 :: Phylo}
toPhylo' :: Phylo' -> [Document] -> TermList -> Config -> Phylo
toPhylo' (PhyloN phylo) = toPhylo'
toPhylo' (PhyloBase phylo) = toPhylo
-}
toPhylo
::
[
Document
]
->
TermList
->
Config
->
Phylo
toPhylo
::
[
Document
]
->
TermList
->
Config
->
Phylo
toPhylo
docs
lst
conf
=
trace
(
"# phylo1 groups "
<>
show
(
length
$
getGroupsFromLevel
1
phylo1
))
toPhylo
docs
lst
conf
=
trace
(
"# phylo1 groups "
<>
show
(
length
$
getGroupsFromLevel
1
phylo1
))
...
@@ -48,9 +59,11 @@ toPhylo docs lst conf = trace ("# phylo1 groups " <> show(length $ getGroupsFrom
...
@@ -48,9 +59,11 @@ toPhylo docs lst conf = trace ("# phylo1 groups " <> show(length $ getGroupsFrom
--------------------------------------
--------------------------------------
phylo1
::
Phylo
phylo1
::
Phylo
phylo1
=
toPhylo1
docs
phyloBase
phylo1
=
toPhylo1
docs
phyloBase
-- > AD to db here
--------------------------------------
--------------------------------------
phyloBase
::
Phylo
phyloBase
::
Phylo
phyloBase
=
toPhyloBase
docs
lst
conf
phyloBase
=
toPhyloBase
docs
lst
conf
-- > AD to db here
--------------------------------------
--------------------------------------
...
@@ -202,7 +215,7 @@ toPhyloClique phylo phyloDocs = case (clique $ getConfig phylo) of
...
@@ -202,7 +215,7 @@ toPhyloClique phylo phyloDocs = case (clique $ getConfig phylo) of
$
foldl
sumCooc
empty
$
foldl
sumCooc
empty
$
map
listToMatrix
$
map
listToMatrix
$
map
(
\
d
->
ngramsToIdx
(
text
d
)
(
getRoots
phylo
))
docs
$
map
(
\
d
->
ngramsToIdx
(
text
d
)
(
getRoots
phylo
))
docs
in
(
prd
,
map
(
\
cl
->
PhyloClique
cl
0
prd
)
$
getMaxCliques
Conditional
0.01
cooc
))
in
(
prd
,
map
(
\
cl
->
PhyloClique
cl
0
prd
)
$
getMaxCliques
Conditional
0.0
0
1
cooc
))
$
toList
phyloDocs
$
toList
phyloDocs
mcl'
=
mcl
`
using
`
parList
rdeepseq
mcl'
=
mcl
`
using
`
parList
rdeepseq
in
fromList
mcl'
in
fromList
mcl'
...
@@ -232,9 +245,9 @@ docsToTimeScaleCooc docs fdt =
...
@@ -232,9 +245,9 @@ docsToTimeScaleCooc docs fdt =
-----------------------
-----------------------
-- | to Phylo Base | --
-- | to Phylo Base | --
-----------------------
-----------------------
-- TODO anoe
groupDocsByPeriodRec
::
(
NFData
doc
,
Ord
date
,
Enum
date
)
=>
(
doc
->
date
)
->
[(
date
,
date
)]
->
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
groupDocsByPeriodRec
::
(
NFData
doc
,
Ord
date
,
Enum
date
)
=>
(
doc
->
date
)
->
[(
date
,
date
)]
->
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
groupDocsByPeriodRec
f
prds
docs
acc
=
groupDocsByPeriodRec
f
prds
docs
acc
=
if
((
null
prds
)
||
(
null
docs
))
if
((
null
prds
)
||
(
null
docs
))
then
acc
then
acc
else
else
...
@@ -245,7 +258,7 @@ groupDocsByPeriodRec f prds docs acc =
...
@@ -245,7 +258,7 @@ groupDocsByPeriodRec f prds docs acc =
-- To group a list of Documents by fixed periods
-- To group a list of Documents by fixed periods
groupDocsByPeriod'
::
(
NFData
doc
,
Ord
date
,
Enum
date
)
=>
(
doc
->
date
)
->
[(
date
,
date
)]
->
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
groupDocsByPeriod'
::
(
NFData
doc
,
Ord
date
,
Enum
date
)
=>
(
doc
->
date
)
->
[(
date
,
date
)]
->
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
groupDocsByPeriod'
f
pds
docs
=
groupDocsByPeriod'
f
pds
docs
=
let
docs'
=
groupBy
(
\
d
d'
->
f
d
==
f
d'
)
$
sortOn
f
docs
let
docs'
=
groupBy
(
\
d
d'
->
f
d
==
f
d'
)
$
sortOn
f
docs
periods
=
map
(
inPeriode
f
docs'
)
pds
periods
=
map
(
inPeriode
f
docs'
)
pds
periods'
=
periods
`
using
`
parList
rdeepseq
periods'
=
periods
`
using
`
parList
rdeepseq
...
@@ -262,7 +275,7 @@ groupDocsByPeriod' f pds docs =
...
@@ -262,7 +275,7 @@ groupDocsByPeriod' f pds docs =
-- To group a list of Documents by fixed periods
-- To group a list of Documents by fixed periods
groupDocsByPeriod
::
(
NFData
doc
,
Ord
date
,
Enum
date
)
=>
(
doc
->
date
)
->
[(
date
,
date
)]
->
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
groupDocsByPeriod
::
(
NFData
doc
,
Ord
date
,
Enum
date
)
=>
(
doc
->
date
)
->
[(
date
,
date
)]
->
[
doc
]
->
Map
(
date
,
date
)
[
doc
]
groupDocsByPeriod
_
_
[]
=
panic
"[ERR][Viz.Phylo.PhyloMaker] Empty [Documents] can not have any periods"
groupDocsByPeriod
_
_
[]
=
panic
"[ERR][Viz.Phylo.PhyloMaker] Empty [Documents] can not have any periods"
groupDocsByPeriod
f
pds
es
=
groupDocsByPeriod
f
pds
es
=
let
periods
=
map
(
inPeriode
f
es
)
pds
let
periods
=
map
(
inPeriode
f
es
)
pds
periods'
=
periods
`
using
`
parList
rdeepseq
periods'
=
periods
`
using
`
parList
rdeepseq
...
...
src/Gargantext/Core/Viz/Phylo/PhyloTools.hs
View file @
0f6c2e5b
...
@@ -19,6 +19,8 @@ import Data.Map (Map, elems, fromList, unionWith, keys, member, (!), filterWithK
...
@@ -19,6 +19,8 @@ import Data.Map (Map, elems, fromList, unionWith, keys, member, (!), filterWithK
import
Data.String
(
String
)
import
Data.String
(
String
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Prelude
(
floor
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Core.Viz.AdaptativePhylo
import
Gargantext.Core.Viz.AdaptativePhylo
import
Text.Printf
import
Text.Printf
...
@@ -56,6 +58,22 @@ printIOComment cmt =
...
@@ -56,6 +58,22 @@ printIOComment cmt =
-- | Misc | --
-- | Misc | --
--------------
--------------
-- truncate' :: Double -> Int -> Double
-- truncate' x n = (fromIntegral (floor (x * t))) / t
-- where t = 10^n
truncate'
::
Double
->
Int
->
Double
truncate'
x
n
=
(
fromIntegral
$
(
floor
(
x
*
t
)
::
Int
))
/
t
where
--------------
t
::
Double
t
=
10
^
n
getInMap
::
Int
->
Map
Int
Double
->
Double
getInMap
k
m
=
if
(
member
k
m
)
then
m
!
k
else
0
roundToStr
::
(
PrintfArg
a
,
Floating
a
)
=>
Int
->
a
->
String
roundToStr
::
(
PrintfArg
a
,
Floating
a
)
=>
Int
->
a
->
String
roundToStr
=
printf
"%0.*f"
roundToStr
=
printf
"%0.*f"
...
...
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