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
154
Issues
154
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
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
45ec425e
Commit
45ec425e
authored
Mar 11, 2019
by
Quentin Lobbé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring
parent
3bf1b44c
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
234 deletions
+131
-234
Phylo.hs
src/Gargantext/Viz/Phylo.hs
+21
-21
Example.hs
src/Gargantext/Viz/Phylo/Example.hs
+75
-170
Tools.hs
src/Gargantext/Viz/Phylo/Tools.hs
+35
-43
No files found.
src/Gargantext/Viz/Phylo.hs
View file @
45ec425e
...
...
@@ -138,14 +138,28 @@ data PhyloBranch =
}
deriving
(
Generic
,
Show
)
-- | PhyloPeriodId : A period of time framed by a starting Date and an ending Date
type
PhyloPeriodId
=
(
Start
,
End
)
type
PhyloLevelId
=
(
PhyloPeriodId
,
Int
)
type
PhyloGroupId
=
(
PhyloLevelId
,
Int
)
-- | Level : A level of aggregation (-1 = Txt, 0 = Ngrams, 1 = Fis, [2..] = Cluster)
type
Level
=
Int
-- | Index : A generic index of an element (PhyloGroup, PhyloBranch, etc) in a given List
type
Index
=
Int
type
PhyloLevelId
=
(
PhyloPeriodId
,
Level
)
type
PhyloGroupId
=
(
PhyloLevelId
,
Index
)
type
PhyloBranchId
=
(
Level
,
Index
)
type
Pointer
=
(
PhyloGroupId
,
Weight
)
type
Weight
=
Double
type
PhyloBranchId
=
(
Int
,
Int
)
-- | Ngrams : a contiguous sequence of n terms
...
...
@@ -159,24 +173,9 @@ type Clique = Set Ngrams
-- | Support : Number of Documents where a Clique occurs
type
Support
=
Int
-- | Fis : Frequent Items Set (ie: the association between a Clique and a Support)
type
Fis
=
Map
Clique
Support
data
Direction
=
From
|
To
deriving
(
Show
,
Eq
)
data
LevelLabel
=
Level_m1
|
Level_0
|
Level_1
|
Level_mN
|
Level_N
|
Level_pN
deriving
(
Show
,
Eq
,
Enum
,
Bounded
)
type
Fis
=
(
Clique
,
Support
)
data
Level
=
Level
{
_levelLabel
::
LevelLabel
,
_levelValue
::
Int
}
deriving
(
Show
,
Eq
)
data
LevelLink
=
LevelLink
{
_levelFrom
::
Level
,
_levelTo
::
Level
}
deriving
(
Show
)
-- | Document : a piece of Text linked to a Date
data
Document
=
Document
...
...
@@ -184,6 +183,9 @@ data Document = Document
,
text
::
Text
}
deriving
(
Show
)
data
PhyloError
=
LevelDoesNotExist
|
LevelUnassigned
deriving
(
Show
)
...
...
@@ -209,8 +211,6 @@ makeLenses ''Software
makeLenses
''
P
hyloGroup
makeLenses
''
P
hyloLevel
makeLenses
''
P
hyloPeriod
makeLenses
''
L
evel
makeLenses
''
L
evelLink
makeLenses
''
P
hyloBranch
-- | JSON instances
...
...
src/Gargantext/Viz/Phylo/Example.hs
View file @
45ec425e
This diff is collapsed.
Click to expand it.
src/Gargantext/Viz/Phylo/Tools.hs
View file @
45ec425e
...
...
@@ -21,7 +21,7 @@ import Control.Lens hiding (both, Level)
import
Data.List
(
filter
,
intersect
,
(
++
),
sort
,
null
,
head
,
tail
,
last
,
tails
,
delete
,
nub
)
import
Data.Map
(
Map
,
mapKeys
,
member
)
import
Data.Set
(
Set
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
,
toLower
)
import
Data.Tuple.Extra
import
Data.Vector
(
Vector
,
elemIndex
)
import
Gargantext.Prelude
hiding
(
head
)
...
...
@@ -30,6 +30,7 @@ import Gargantext.Viz.Phylo
import
qualified
Data.List
as
List
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
import
qualified
Data.Vector
as
Vector
------------------------------------------------------------------------
...
...
@@ -201,30 +202,19 @@ getIdx x v = case (elemIndex x v) of
Just
i
->
i
-- | To get the label of a Level
getLevelLabel
::
Level
->
LevelLabel
getLevelLabel
lvl
=
_levelLabel
lvl
-- | To get the value of a Level
getLevelValue
::
Level
->
Int
getLevelValue
lvl
=
_levelValue
lvl
-- | To get the label of a LevelLink based on a Direction
getLevelLinkLabel
::
Direction
->
LevelLink
->
LevelLabel
getLevelLinkLabel
dir
link
=
case
dir
of
From
->
view
(
levelFrom
.
levelLabel
)
link
To
->
view
(
levelTo
.
levelLabel
)
link
_
->
panic
"[ERR][Viz.Phylo.Tools.getLevelLinkLabel] Wrong direction"
-- | To get the value of a LevelLink based on a Direction
getLevelLinkValue
::
Direction
->
LevelLink
->
Int
getLevelLinkValue
dir
link
=
case
dir
of
From
->
view
(
levelFrom
.
levelValue
)
link
To
->
view
(
levelTo
.
levelValue
)
link
_
->
panic
"[ERR][Viz.Phylo.Tools.getLevelLinkValue] Wrong direction"
-- | To get the good pair of keys (x,y) or (y,x) in a given Map (a,b) c
getKeyPair
::
(
Int
,
Int
)
->
Map
(
Int
,
Int
)
a
->
(
Int
,
Int
)
getKeyPair
(
x
,
y
)
m
=
case
findPair
(
x
,
y
)
m
of
Nothing
->
panic
"[ERR][Viz.Phylo.Example.getKeyPair] Nothing"
Just
i
->
i
where
--------------------------------------
findPair
::
(
Int
,
Int
)
->
Map
(
Int
,
Int
)
a
->
Maybe
(
Int
,
Int
)
findPair
(
x
,
y
)
m
|
member
(
x
,
y
)
m
=
Just
(
x
,
y
)
|
member
(
y
,
x
)
m
=
Just
(
y
,
x
)
|
otherwise
=
Nothing
--------------------------------------
-- | To get the neighbours (directed/undirected) of a PhyloGroup from a list of PhyloEdges
...
...
@@ -268,14 +258,14 @@ initGroup ngrams lbl idx lvl from to p = PhyloGroup
[]
[]
[]
[]
-- | To
create a Level
init
Level
::
Int
->
LevelLabel
->
Level
init
Level
lvl
lbl
=
Level
lbl
lv
l
-- | To
init a PhyloNgrams as a Vector of Ngrams
init
Ngrams
::
[
Ngrams
]
->
PhyloNgrams
init
Ngrams
l
=
Vector
.
fromList
$
map
toLower
l
-- | To
create a LevelLink
init
LevelLink
::
Level
->
Level
->
LevelLink
init
LevelLink
lvl
lvl'
=
LevelLink
lvl
lvl'
-- | To
init a Phylomemy
init
Phylo
::
[
Document
]
->
PhyloNgrams
->
Phylo
init
Phylo
docs
ngrams
=
Phylo
(
both
date
$
(
last
&&&
head
)
docs
)
ngrams
[]
[]
-- | To create a PhyloLevel
...
...
@@ -288,6 +278,13 @@ initPhyloPeriod :: PhyloPeriodId -> [PhyloLevel] -> PhyloPeriod
initPhyloPeriod
id
l
=
PhyloPeriod
id
l
-- | To filter Fis with small Support but by keeping non empty Periods
keepFilled
::
(
Int
->
[
a
]
->
[
a
])
->
Int
->
[
a
]
->
[
a
]
keepFilled
f
thr
l
=
if
(
null
$
f
thr
l
)
&&
(
not
$
null
l
)
then
keepFilled
f
(
thr
-
1
)
l
else
f
thr
l
-- | To get all combinations of a list
listToDirectedCombi
::
Eq
a
=>
[
a
]
->
[(
a
,
a
)]
listToDirectedCombi
l
=
[(
x
,
y
)
|
x
<-
l
,
y
<-
l
,
x
/=
y
]
...
...
@@ -322,16 +319,11 @@ setPhyloLevelId lvl' (PhyloLevel (id, lvl) groups)
-- | To choose a LevelLink strategy based an a given Level
shouldLink
::
LevelLink
->
[
Int
]
->
[
Int
]
->
Bool
shouldLink
lvl
l
l'
|
from
<=
1
=
doesContainsOrd
l
l'
|
from
>
1
=
undefined
shouldLink
::
(
Level
,
Level
)
->
[
Int
]
->
[
Int
]
->
Bool
shouldLink
(
lvl
,
lvl'
)
l
l'
|
lvl
<=
1
=
doesContainsOrd
l
l'
|
lvl
>
1
=
undefined
|
otherwise
=
panic
(
"[ERR][Viz.Phylo.Tools.shouldLink] LevelLink not defined"
)
where
--------------------------------------
from
::
Int
from
=
getLevelLinkValue
From
lvl
--------------------------------------
-- | To unify the keys (x,y) that Map 1 share with Map 2 such as: (x,y) <=> (y,x)
...
...
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