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
175
Issues
175
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
039194f2
Commit
039194f2
authored
Mar 07, 2019
by
Quentin Lobbé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the branches detection
parent
0e08f8b0
Pipeline
#261
failed with stage
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
33 deletions
+58
-33
Example.hs
src/Gargantext/Viz/Phylo/Example.hs
+48
-33
Tools.hs
src/Gargantext/Viz/Phylo/Tools.hs
+10
-0
No files found.
src/Gargantext/Viz/Phylo/Example.hs
View file @
039194f2
...
@@ -30,7 +30,7 @@ module Gargantext.Viz.Phylo.Example where
...
@@ -30,7 +30,7 @@ module Gargantext.Viz.Phylo.Example where
import
Control.Lens
hiding
(
makeLenses
,
both
,
Level
)
import
Control.Lens
hiding
(
makeLenses
,
both
,
Level
)
import
Data.Bool
(
Bool
,
not
)
import
Data.Bool
(
Bool
,
not
)
import
Data.List
(
concat
,
union
,
intersect
,
tails
,
tail
,
head
,
last
,
null
,
zip
,
sort
,
length
,
any
,
(
++
),
(
!!
),
nub
,
sortOn
,
reverse
,
splitAt
,
take
,
delete
)
import
Data.List
(
concat
,
union
,
intersect
,
tails
,
tail
,
head
,
last
,
null
,
zip
,
sort
,
length
,
any
,
(
++
),
(
!!
),
nub
,
sortOn
,
reverse
,
splitAt
,
take
,
delete
,
init
)
import
Data.Map
(
Map
,
elems
,
member
,
adjust
,
singleton
,
empty
,
(
!
),
keys
,
restrictKeys
,
mapWithKey
,
filterWithKey
,
mapKeys
,
intersectionWith
,
unionWith
)
import
Data.Map
(
Map
,
elems
,
member
,
adjust
,
singleton
,
empty
,
(
!
),
keys
,
restrictKeys
,
mapWithKey
,
filterWithKey
,
mapKeys
,
intersectionWith
,
unionWith
)
import
Data.Semigroup
(
Semigroup
)
import
Data.Semigroup
(
Semigroup
)
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
...
@@ -65,44 +65,58 @@ import qualified Data.Vector as Vector
...
@@ -65,44 +65,58 @@ import qualified Data.Vector as Vector
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | STEP 12 | -- Find the Branches
-- | STEP 12 | -- Find the Branches
initPhyloBranch
::
(
Int
,
Int
)
->
Text
->
[
PhyloGroupId
]
->
PhyloBranch
initPhyloBranch
(
lvl
,
idx
)
lbl
l
=
PhyloBranch
(
lvl
,
idx
)
lbl
l
addPhyloBranch
::
(
Int
,
Int
)
->
Text
->
[
PhyloGroupId
]
->
[
PhyloBranch
]
->
[
PhyloBranch
]
-- | To add a PhyloGroupId to list of Branches with conditions
addPhyloBranch
(
lvl
,
idx
)
lbl
ids
b
=
b
++
[
initPhyloBranch
(
lvl
,
idx
)
lbl
ids
]
addToBranches
::
(
Int
,
Int
)
->
PhyloGroupId
->
[
PhyloBranch
]
->
[
PhyloBranch
]
addToBranches
(
lvl
,
idx
)
id
branches
|
null
branches
=
[
newBranch
]
-- cur : current PhyloGroup
|
idx
==
lastIdx
=
(
init
branches
)
++
[
addGroupIdToBranch
id
(
last
branches
)]
-- rst : rest of the initial list of PhyloGroups
|
otherwise
=
branches
++
[
newBranch
]
-- nxt : next PhyloGroups to be added in the current Branch
where
-- nbr : direct neighbours (Childs & Parents) of cur
--------------------------------------
-- ids : PhyloGroupIds allready added in the current Branch
newBranch
::
PhyloBranch
-- mem : memory of the allready created Branches
newBranch
=
PhyloBranch
(
lvl
,
idx
)
""
[
id
]
--------------------------------------
getGroupPairs
::
PhyloGroup
->
Phylo
->
[
PhyloGroup
]
lastIdx
::
Int
getGroupPairs
g
p
=
(
getGroupChilds
g
p
)
++
(
getGroupParents
g
p
)
lastIdx
=
(
snd
.
_phylo_branchId
.
last
)
branches
--------------------------------------
groupsToBranchs
::
(
Int
,
Int
)
->
PhyloGroup
->
[
PhyloGroup
]
->
[
PhyloGroup
]
->
[
PhyloGroupId
]
->
[
PhyloBranch
]
->
Phylo
->
[
PhyloBranch
]
-- | To transform a list of PhyloGroups into a list of PhyloBranches where :
groupsToBranchs
(
lvl
,
idx
)
curr
rest
next
memId
mem
p
-- curr = the current PhyloGroup
|
null
rest
&&
null
next
=
addPhyloBranch
(
lvl
,
idx
)
""
(
memId
++
[
getGroupId
curr
])
mem
-- rest = the rest of the initial list of PhyloGroups
|
(
not
.
null
)
next
=
groupsToBranchs
(
lvl
,
idx
)
(
head
next'
)
rest'
(
tail
next'
)
(
memId
++
[
getGroupId
curr
])
mem
p
-- next = the next PhyloGroups to be added in the current Branch
|
otherwise
=
groupsToBranchs
(
lvl
,
idx
+
1
)
(
head
rest'
)
(
tail
rest'
)
[]
[]
(
addPhyloBranch
(
lvl
,
idx
)
""
(
memId
++
[
getGroupId
curr
])
mem
)
p
-- memo = the memory of the allready created Branches, the last one is the current one
groupsToBranches
::
(
Int
,
Int
)
->
PhyloGroup
->
[
PhyloGroup
]
->
[
PhyloGroup
]
->
[
PhyloBranch
]
->
Phylo
->
[
PhyloBranch
]
groupsToBranches
(
lvl
,
idx
)
curr
rest
next
memo
p
|
null
rest'
&&
null
next'
=
memo'
|
(
not
.
null
)
next'
=
groupsToBranches
(
lvl
,
idx
)
(
head
next'
)
rest'
(
tail
next'
)
memo'
p
|
otherwise
=
groupsToBranches
(
lvl
,
idx
+
1
)
(
head
rest'
)
(
tail
rest'
)
[]
memo'
p
where
where
next'
=
nub
$
next
++
(
getGroupPairs
curr
p
)
--------------------------------------
done
::
[
PhyloGroups
]
done
=
getGroupsFromIds
(
concat
$
map
(
_phylo_branchGroups
)
memo
)
p
--------------------------------------
memo'
::
[
PhyloBranch
]
memo'
=
addToBranches
(
lvl
,
idx
)
(
getGroupId
curr
)
memo
--------------------------------------
next'
::
[
PhyloGroups
]
next'
=
filter
(
\
x
->
not
$
elem
x
done
)
$
nub
$
next
++
(
getGroupPairs
curr
p
)
--------------------------------------
rest'
::
[
PhyloGroups
]
rest'
=
filter
(
\
x
->
not
$
elem
x
next'
)
rest
rest'
=
filter
(
\
x
->
not
$
elem
x
next'
)
rest
--------------------------------------
-- | To set all the PhyloBranches for a given Level in a Phylo
setPhyloBranches
::
Level
->
Phylo
->
Phylo
setPhyloBranches
::
Level
->
Phylo
->
Phylo
setPhyloBranches
lvl
p
=
alterPhyloBranches
(
\
branches
setPhyloBranches
lvl
p
=
alterPhyloBranches
->
branches
++
(
groupsToBranch
s
(
\
branches
->
branches
++
(
groupsToBranche
s
(
getLevelValue
lvl
,
0
)
(
getLevelValue
lvl
,
0
)
(
head
groups
)
(
head
groups
)
(
tail
groups
)
(
tail
groups
)
[]
[]
[]
p
))
p
[]
[]
p
)
)
p
where
where
--------------------------------------
--------------------------------------
groups
::
[
PhyloGroup
]
groups
::
[
PhyloGroup
]
...
@@ -112,6 +126,7 @@ setPhyloBranches lvl p = alterPhyloBranches (\branches
...
@@ -112,6 +126,7 @@ setPhyloBranches lvl p = alterPhyloBranches (\branches
phyloWithBranches_1
=
setPhyloBranches
(
initLevel
1
Level_1
)
phyloWithPair_1_Childs
phyloWithBranches_1
=
setPhyloBranches
(
initLevel
1
Level_1
)
phyloWithPair_1_Childs
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | STEP 11 | -- Link the PhyloGroups of level 1 through the Periods
-- | STEP 11 | -- Link the PhyloGroups of level 1 through the Periods
...
...
src/Gargantext/Viz/Phylo/Tools.hs
View file @
039194f2
...
@@ -36,6 +36,11 @@ import qualified Data.Set as Set
...
@@ -36,6 +36,11 @@ import qualified Data.Set as Set
-- | Tools | --
-- | Tools | --
-- | To add a new PhyloGroupId to a PhyloBranch
addGroupIdToBranch
::
PhyloGroupId
->
PhyloBranch
->
PhyloBranch
addGroupIdToBranch
id
b
=
over
(
phylo_branchGroups
)
(
++
[
id
])
b
-- | To add a PhyloLevel at the end of a list of PhyloLevels
-- | To add a PhyloLevel at the end of a list of PhyloLevels
addPhyloLevel
::
PhyloLevel
->
[
PhyloLevel
]
->
[
PhyloLevel
]
addPhyloLevel
::
PhyloLevel
->
[
PhyloLevel
]
->
[
PhyloLevel
]
addPhyloLevel
lvl
l
=
l
++
[
lvl
]
addPhyloLevel
lvl
l
=
l
++
[
lvl
]
...
@@ -137,6 +142,11 @@ getGroupNgrams :: PhyloGroup -> [Int]
...
@@ -137,6 +142,11 @@ getGroupNgrams :: PhyloGroup -> [Int]
getGroupNgrams
=
_phylo_groupNgrams
getGroupNgrams
=
_phylo_groupNgrams
-- | To get the list of pairs (Childs & Parents) of a PhyloGroup
getGroupPairs
::
PhyloGroup
->
Phylo
->
[
PhyloGroup
]
getGroupPairs
g
p
=
(
getGroupChilds
g
p
)
++
(
getGroupParents
g
p
)
-- | To get the PhyloGroups Parents of a PhyloGroup
-- | To get the PhyloGroups Parents of a PhyloGroup
getGroupParents
::
PhyloGroup
->
Phylo
->
[
PhyloGroup
]
getGroupParents
::
PhyloGroup
->
Phylo
->
[
PhyloGroup
]
getGroupParents
g
p
=
getGroupsFromIds
(
map
fst
$
_phylo_groupPeriodParents
g
)
p
getGroupParents
g
p
=
getGroupsFromIds
(
map
fst
$
_phylo_groupPeriodParents
g
)
p
...
...
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