]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Phylo/Aggregates/Fis.hs
[PHYLO] cLouvain in IO Monad fix.
[gargantext.git] / src / Gargantext / Viz / Phylo / Aggregates / Fis.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.Aggregates.Fis
18 where
19
20 import Data.List (last,head)
21 import Data.Map (Map)
22 import Data.Text (Text, unwords, toLower, words)
23 import Data.Tuple (fst, snd)
24 import Data.Tuple.Extra
25 import Data.Vector (Vector)
26
27 import Gargantext.Prelude hiding (head)
28 import Gargantext.Text.Metrics.FrequentItemSet (fisWithSizePolyMap, Size(..))
29 import Gargantext.Text.Terms.Mono (monoTexts)
30 import Gargantext.Viz.Phylo
31 import Gargantext.Viz.Phylo.Tools
32
33 import qualified Data.List as List
34 import qualified Data.Map as Map
35 import qualified Data.Vector as Vector
36
37
38 -- | To Filter Fis by support
39 filterFisBySupport :: Bool -> Int -> Map (Date, Date) [Fis] -> Map (Date, Date) [Fis]
40 filterFisBySupport empty min m = case empty of
41 True -> Map.map (\l -> filterMinorFis min l) m
42 False -> Map.map (\l -> keepFilled (filterMinorFis) min l) m
43
44
45 -- | To filter Fis with small Support, to preserve nonempty periods please use : filterFisBySupport False
46 filterMinorFis :: Int -> [Fis] -> [Fis]
47 filterMinorFis min l = filter (\fis -> snd fis > min) l
48
49
50 -- | To filter nested Fis
51 filterFisByNested :: Map (Date, Date) [Fis] -> Map (Date, Date) [Fis]
52 filterFisByNested = map (\l -> let cliqueMax = filterNestedSets (head $ map fst l) (map fst l) []
53 in filter (\fis -> elem (fst fis) cliqueMax) l)
54
55
56 -- | To transform a list of Documents into a Frequent Items Set
57 docsToFis :: Map (Date, Date) [Document] -> Map (Date, Date) [Fis]
58 docsToFis docs = map (\d -> Map.toList
59 $ fisWithSizePolyMap (Segment 1 20) 1 (map (words . text) d)) docs