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
147
Issues
147
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
c9512dee
Commit
c9512dee
authored
Mar 11, 2019
by
Quentin Lobbé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring
parent
f6f6d304
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 @
c9512dee
...
@@ -138,14 +138,28 @@ data PhyloBranch =
...
@@ -138,14 +138,28 @@ data PhyloBranch =
}
}
deriving
(
Generic
,
Show
)
deriving
(
Generic
,
Show
)
-- | PhyloPeriodId : A period of time framed by a starting Date and an ending Date
type
PhyloPeriodId
=
(
Start
,
End
)
type
PhyloPeriodId
=
(
Start
,
End
)
type
PhyloLevelId
=
(
PhyloPeriodId
,
Int
)
-- | Level : A level of aggregation (-1 = Txt, 0 = Ngrams, 1 = Fis, [2..] = Cluster)
type
PhyloGroupId
=
(
PhyloLevelId
,
Int
)
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
Pointer
=
(
PhyloGroupId
,
Weight
)
type
Weight
=
Double
type
Weight
=
Double
type
PhyloBranchId
=
(
Int
,
Int
)
-- | Ngrams : a contiguous sequence of n terms
-- | Ngrams : a contiguous sequence of n terms
...
@@ -159,24 +173,9 @@ type Clique = Set Ngrams
...
@@ -159,24 +173,9 @@ type Clique = Set Ngrams
-- | Support : Number of Documents where a Clique occurs
-- | Support : Number of Documents where a Clique occurs
type
Support
=
Int
type
Support
=
Int
-- | Fis : Frequent Items Set (ie: the association between a Clique and a Support)
-- | Fis : Frequent Items Set (ie: the association between a Clique and a Support)
type
Fis
=
Map
Clique
Support
type
Fis
=
(
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
)
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
-- | Document : a piece of Text linked to a Date
data
Document
=
Document
data
Document
=
Document
...
@@ -184,6 +183,9 @@ data Document = Document
...
@@ -184,6 +183,9 @@ data Document = Document
,
text
::
Text
,
text
::
Text
}
deriving
(
Show
)
}
deriving
(
Show
)
data
PhyloError
=
LevelDoesNotExist
data
PhyloError
=
LevelDoesNotExist
|
LevelUnassigned
|
LevelUnassigned
deriving
(
Show
)
deriving
(
Show
)
...
@@ -209,8 +211,6 @@ makeLenses ''Software
...
@@ -209,8 +211,6 @@ makeLenses ''Software
makeLenses
''
P
hyloGroup
makeLenses
''
P
hyloGroup
makeLenses
''
P
hyloLevel
makeLenses
''
P
hyloLevel
makeLenses
''
P
hyloPeriod
makeLenses
''
P
hyloPeriod
makeLenses
''
L
evel
makeLenses
''
L
evelLink
makeLenses
''
P
hyloBranch
makeLenses
''
P
hyloBranch
-- | JSON instances
-- | JSON instances
...
...
src/Gargantext/Viz/Phylo/Example.hs
View file @
c9512dee
This diff is collapsed.
Click to expand it.
src/Gargantext/Viz/Phylo/Tools.hs
View file @
c9512dee
...
@@ -21,7 +21,7 @@ import Control.Lens hiding (both, Level)
...
@@ -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.List
(
filter
,
intersect
,
(
++
),
sort
,
null
,
head
,
tail
,
last
,
tails
,
delete
,
nub
)
import
Data.Map
(
Map
,
mapKeys
,
member
)
import
Data.Map
(
Map
,
mapKeys
,
member
)
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
,
toLower
)
import
Data.Tuple.Extra
import
Data.Tuple.Extra
import
Data.Vector
(
Vector
,
elemIndex
)
import
Data.Vector
(
Vector
,
elemIndex
)
import
Gargantext.Prelude
hiding
(
head
)
import
Gargantext.Prelude
hiding
(
head
)
...
@@ -30,6 +30,7 @@ import Gargantext.Viz.Phylo
...
@@ -30,6 +30,7 @@ import Gargantext.Viz.Phylo
import
qualified
Data.List
as
List
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
import
qualified
Data.Vector
as
Vector
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -201,30 +202,19 @@ getIdx x v = case (elemIndex x v) of
...
@@ -201,30 +202,19 @@ getIdx x v = case (elemIndex x v) of
Just
i
->
i
Just
i
->
i
-- | To get the label of a Level
-- | To get the good pair of keys (x,y) or (y,x) in a given Map (a,b) c
getLevelLabel
::
Level
->
LevelLabel
getKeyPair
::
(
Int
,
Int
)
->
Map
(
Int
,
Int
)
a
->
(
Int
,
Int
)
getLevelLabel
lvl
=
_levelLabel
lvl
getKeyPair
(
x
,
y
)
m
=
case
findPair
(
x
,
y
)
m
of
Nothing
->
panic
"[ERR][Viz.Phylo.Example.getKeyPair] Nothing"
Just
i
->
i
-- | To get the value of a Level
where
getLevelValue
::
Level
->
Int
--------------------------------------
getLevelValue
lvl
=
_levelValue
lvl
findPair
::
(
Int
,
Int
)
->
Map
(
Int
,
Int
)
a
->
Maybe
(
Int
,
Int
)
findPair
(
x
,
y
)
m
|
member
(
x
,
y
)
m
=
Just
(
x
,
y
)
-- | To get the label of a LevelLink based on a Direction
|
member
(
y
,
x
)
m
=
Just
(
y
,
x
)
getLevelLinkLabel
::
Direction
->
LevelLink
->
LevelLabel
|
otherwise
=
Nothing
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 neighbours (directed/undirected) of a PhyloGroup from a list of PhyloEdges
-- | 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
...
@@ -268,14 +258,14 @@ initGroup ngrams lbl idx lvl from to p = PhyloGroup
[]
[]
[]
[]
[]
[]
[]
[]
-- | To
create a Level
-- | To
init a PhyloNgrams as a Vector of Ngrams
init
Level
::
Int
->
LevelLabel
->
Level
init
Ngrams
::
[
Ngrams
]
->
PhyloNgrams
init
Level
lvl
lbl
=
Level
lbl
lv
l
init
Ngrams
l
=
Vector
.
fromList
$
map
toLower
l
-- | To
create a LevelLink
-- | To
init a Phylomemy
init
LevelLink
::
Level
->
Level
->
LevelLink
init
Phylo
::
[
Document
]
->
PhyloNgrams
->
Phylo
init
LevelLink
lvl
lvl'
=
LevelLink
lvl
lvl'
init
Phylo
docs
ngrams
=
Phylo
(
both
date
$
(
last
&&&
head
)
docs
)
ngrams
[]
[]
-- | To create a PhyloLevel
-- | To create a PhyloLevel
...
@@ -288,6 +278,13 @@ initPhyloPeriod :: PhyloPeriodId -> [PhyloLevel] -> PhyloPeriod
...
@@ -288,6 +278,13 @@ initPhyloPeriod :: PhyloPeriodId -> [PhyloLevel] -> PhyloPeriod
initPhyloPeriod
id
l
=
PhyloPeriod
id
l
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
-- | To get all combinations of a list
listToDirectedCombi
::
Eq
a
=>
[
a
]
->
[(
a
,
a
)]
listToDirectedCombi
::
Eq
a
=>
[
a
]
->
[(
a
,
a
)]
listToDirectedCombi
l
=
[(
x
,
y
)
|
x
<-
l
,
y
<-
l
,
x
/=
y
]
listToDirectedCombi
l
=
[(
x
,
y
)
|
x
<-
l
,
y
<-
l
,
x
/=
y
]
...
@@ -322,16 +319,11 @@ setPhyloLevelId lvl' (PhyloLevel (id, lvl) groups)
...
@@ -322,16 +319,11 @@ setPhyloLevelId lvl' (PhyloLevel (id, lvl) groups)
-- | To choose a LevelLink strategy based an a given Level
-- | To choose a LevelLink strategy based an a given Level
shouldLink
::
LevelLink
->
[
Int
]
->
[
Int
]
->
Bool
shouldLink
::
(
Level
,
Level
)
->
[
Int
]
->
[
Int
]
->
Bool
shouldLink
lvl
l
l'
shouldLink
(
lvl
,
lvl'
)
l
l'
|
from
<=
1
=
doesContainsOrd
l
l'
|
lvl
<=
1
=
doesContainsOrd
l
l'
|
from
>
1
=
undefined
|
lvl
>
1
=
undefined
|
otherwise
=
panic
(
"[ERR][Viz.Phylo.Tools.shouldLink] LevelLink not defined"
)
|
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)
-- | 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