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 NoImplicitPrelude #-}
23 {-# LANGUAGE TemplateHaskell #-}
25 module Gargantext.Types.Phylo where
27 import Data.Aeson.TH (deriveJSON)
28 import Data.Maybe (Maybe)
29 import Data.Text (Text)
30 import Data.Time.Clock.POSIX (POSIXTime)
32 import GHC.Generics (Generic)
34 import Gargantext.Prelude
35 import Gargantext.Utils.Prefix (unPrefix)
37 ------------------------------------------------------------------------
38 -- | Phylo datatype descriptor of a phylomemy
39 -- Duration : time Segment of the whole phylomemy in UTCTime format (start,end)
40 -- Ngrams : list of all (possible) terms contained in the phylomemy (with their id)
41 -- Steps : list of all steps to build the phylomemy
42 data Phylo = Phylo { _phyloDuration :: (Start, End)
43 , _phyloNgrams :: [Ngram]
44 , _phyloPeriods :: [PhyloPeriod]
47 -- | UTCTime in seconds since UNIX epoch
48 type Start = POSIXTime
51 type Ngram = (NgramId, Text)
54 -- | PhyloStep : steps of phylomemy on temporal axis
55 -- Period: tuple (start date, end date) of the step of the phylomemy
56 -- Levels: levels of granularity
57 data PhyloPeriod = PhyloPeriod { _phyloPeriodId :: PhyloPeriodId
58 , _phyloPeriodLevels :: [PhyloLevel]
61 type PhyloPeriodId = (Start, End)
63 -- | PhyloLevel : levels of phylomemy on level axis
64 -- Levels description:
65 -- Level -1: Ngram equals itself (by identity) == _phyloNgrams
66 -- Level 0: Group of synonyms (by stems + by qualitative expert meaning)
67 -- Level 1: First level of clustering
68 -- Level N: Nth level of clustering
69 data PhyloLevel = PhyloLevel { _phyloLevelId :: PhyloLevelId
70 , _phyloLevelGroups :: [PhyloGroup]
73 type PhyloLevelId = (PhyloPeriodId, Int)
75 -- | PhyloGroup : group of ngrams at each level and step
76 -- Label : maybe has a label as text
77 -- Ngrams: set of terms that build the group
78 -- Period Parents|Childs: weighted link to Parents|Childs (Temporal Period axis)
79 -- Level Parents|Childs: weighted link to Parents|Childs (Level Granularity axis)
80 data PhyloGroup = PhyloGroup { _phyloGroupId :: PhyloGroupId
81 , _phyloGroupLabel :: Maybe Text
82 , _phyloGroupNgrams :: [NgramId]
84 , _phyloGroupPeriodParents :: [Edge]
85 , _phyloGroupPeriodChilds :: [Edge]
87 , _phyloGroupLevelParents :: [Edge]
88 , _phyloGroupLevelChilds :: [Edge]
91 type PhyloGroupId = (PhyloLevelId, Int)
92 type Edge = (PhyloGroupId, Weight)
96 $(deriveJSON (unPrefix "_phylo" ) ''Phylo )
97 $(deriveJSON (unPrefix "_phyloPeriod" ) ''PhyloPeriod )
98 $(deriveJSON (unPrefix "_phyloLevel" ) ''PhyloLevel )
99 $(deriveJSON (unPrefix "_phyloGroup" ) ''PhyloGroup )