2 Module : Gargantext.Types.Phylo
3 Description : Main Types for Phylomemy
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Specifications of Phylomemy format.
12 Phylomemy can be described as a Temporal Graph with different scale of
13 granularity of group of ngrams (terms and multi-terms).
15 The main type is Phylo which is synonym of Phylomemy (only difference is
18 Phylomemy was first described in [REF].
21 {-# LANGUAGE DeriveGeneric #-}
22 {-# LANGUAGE TemplateHaskell #-}
24 module Gargantext.Types.Phylo where
26 import Data.Aeson.TH (deriveJSON)
27 import Data.Maybe (Maybe)
28 import Data.Text (Text)
29 import Data.Time.Clock.POSIX (POSIXTime)
31 import GHC.Generics (Generic)
33 import Gargantext.Prelude
34 import Gargantext.Utils.Prefix (unPrefix)
36 ------------------------------------------------------------------------
37 -- | Phylo datatype descriptor of a phylomemy
38 -- Duration : time Segment of the whole phylomemy in UTCTime format (start,end)
39 -- Ngrams : list of all (possible) terms contained in the phylomemy (with their id)
40 -- Steps : list of all steps to build the phylomemy
41 data Phylo = Phylo { _phyloDuration :: (Start, End)
42 , _phyloNgrams :: [Ngram]
43 , _phyloPeriods :: [PhyloPeriod]
46 -- | UTCTime in seconds since UNIX epoch
47 type Start = POSIXTime
50 type Ngram = (NgramId, Text)
53 -- | PhyloStep : steps of phylomemy on temporal axis
54 -- Period: tuple (start date, end date) of the step of the phylomemy
55 -- Levels: levels of granularity
56 data PhyloPeriod = PhyloPeriod { _phyloPeriodId :: PhyloPeriodId
57 , _phyloPeriodLevels :: [PhyloLevel]
60 type PhyloPeriodId = (Start, End)
62 -- | PhyloLevel : levels of phylomemy on level axis
63 -- Levels description:
64 -- Level -1: Ngram equals itself (by identity) == _phyloNgrams
65 -- Level 0: Group of synonyms (by stems + by qualitative expert meaning)
66 -- Level 1: First level of clustering
67 -- Level N: Nth level of clustering
68 data PhyloLevel = PhyloLevel { _phyloLevelId :: PhyloLevelId
69 , _phyloLevelGroups :: [PhyloGroup]
72 type PhyloLevelId = (PhyloPeriodId, Int)
74 -- | PhyloGroup : group of ngrams at each level and step
75 -- Label : maybe has a label as text
76 -- Ngrams: set of terms that build the group
77 -- Period Parents|Childs: weighted link to Parents|Childs (Temporal Period axis)
78 -- Level Parents|Childs: weighted link to Parents|Childs (Level Granularity axis)
79 data PhyloGroup = PhyloGroup { _phyloGroupId :: PhyloGroupId
80 , _phyloGroupLabel :: Maybe Text
81 , _phyloGroupNgrams :: [NgramId]
83 , _phyloGroupPeriodParents :: [Edge]
84 , _phyloGroupPeriodChilds :: [Edge]
86 , _phyloGroupLevelParents :: [Edge]
87 , _phyloGroupLevelChilds :: [Edge]
90 type PhyloGroupId = (PhyloLevelId, Int)
91 type Edge = (PhyloGroupId, Weight)
95 $(deriveJSON (unPrefix "_phylo" ) ''Phylo )
96 $(deriveJSON (unPrefix "_phyloPeriod" ) ''PhyloPeriod )
97 $(deriveJSON (unPrefix "_phyloLevel" ) ''PhyloLevel )
98 $(deriveJSON (unPrefix "_phyloGroup" ) ''PhyloGroup )