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
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE OverloadedStrings #-}
17 module Gargantext.Viz.Phylo.Aggregates.Document
20 import Data.List (last)
22 import Data.Text (Text)
23 import Data.Tuple (fst)
24 import Data.Vector (Vector)
25 import Gargantext.Prelude
26 import Gargantext.Text.Terms.Mono (monoTexts)
27 import Gargantext.Viz.Phylo
28 import qualified Data.List as List
29 import qualified Data.Map as Map
30 import qualified Data.Vector as Vector
33 -- | To init a list of Periods framed by a starting Date and an ending Date
34 initPeriods :: (Eq date, Enum date) => Grain -> Step -> (date, date) -> [(date, date)]
35 initPeriods g s (start,end) = map (\l -> (head' "Doc" l, last l))
36 $ chunkAlong g s [start .. end]
39 -- | To group a list of Documents by fixed periods
40 groupDocsByPeriod :: (Ord date, Enum date) => (doc -> date) -> [(date,date)] -> [doc] -> Map (date, date) [doc]
41 groupDocsByPeriod _ _ [] = panic "[ERR][Viz.Phylo.Example.docsToPeriods] Empty [Documents] can not have any periods"
42 groupDocsByPeriod f pds es = Map.fromList $ zip pds $ map (inPeriode f es) pds
44 --------------------------------------
45 inPeriode :: Ord b => (t -> b) -> [t] -> (b, b) -> [t]
46 inPeriode f' h (start,end) =
47 fst $ List.partition (\d -> f' d >= start && f' d <= end) h
48 --------------------------------------
51 -- | To parse a list of Documents by filtering on a Vector of Ngrams
52 parseDocs :: Vector Ngrams -> [(Date,Text)] -> [Document]
53 parseDocs roots c = map (\(d,t)
54 -> Document d ( filter (\x -> Vector.elem x roots)