]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Phylo/Tools.hs
[PHYLO] Code Review + Tools start.
[gargantext.git] / src / Gargantext / Viz / Phylo / Tools.hs
1 {-|
2 Module : Gargantext.Viz.Phylo.Tools
3 Description : Phylomemy Tools to build/manage it
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10
11 -}
12
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE OverloadedStrings #-}
16
17 module Gargantext.Viz.Phylo.Tools
18 where
19
20 import Control.Lens hiding (both)
21 import Data.Tuple.Extra
22 import Gargantext.Prelude hiding (head)
23 import Gargantext.Viz.Phylo
24 import qualified Data.List as List
25
26
27
28 -- | To get Ngrams out of a Gargantext.Viz.Phylo.PhyloGroup
29 getNgrams :: PhyloGroup -> [Int]
30 getNgrams = _phylo_groupNgrams
31
32 getGroups :: Phylo -> [PhyloGroup]
33 getGroups = view (phylo_periods . traverse . phylo_periodLevels . traverse . phylo_levelGroups)
34
35 getGroupId :: PhyloGroup -> PhyloGroupId
36 getGroupId = view (phylo_groupId)
37
38 getGroupLvl :: PhyloGroup -> Int
39 getGroupLvl = snd . fst . getGroupId
40
41 getGroupPeriod :: PhyloGroup -> (Date,Date)
42 getGroupPeriod = fst . fst . getGroupId
43
44 getGroupsByLevelAndPeriod :: Int -> (Date,Date) -> Phylo -> [PhyloGroup]
45 getGroupsByLevelAndPeriod lvl period p = List.filter testGroup (getGroups p)
46 where
47 testGroup group = (getGroupLvl group == lvl )
48 && (getGroupPeriod group == period)
49
50