2 Module : Gargantext.Viz.AdaptativePhylo
3 Description : Phylomemy definitions and types.
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Specifications of Phylomemy export 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
19 Chavalarias, D., Cointet, J.-P., 2013. Phylomemetic patterns
20 in science evolution — the rise and fall of scientific fields. PloS
24 {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
25 {-# LANGUAGE NoImplicitPrelude #-}
26 {-# LANGUAGE TemplateHaskell #-}
27 {-# LANGUAGE MultiParamTypeClasses #-}
29 module Gargantext.Viz.AdaptativePhylo where
32 import Data.Aeson.TH (deriveJSON)
33 import Data.Text (Text, pack)
34 import Data.Vector (Vector)
38 import Gargantext.Core.Utils.Prefix (unPrefix)
39 import Gargantext.Prelude
40 import Gargantext.Text.Context (TermList)
43 import GHC.IO (FilePath)
44 import Control.DeepSeq (NFData)
45 import Control.Lens (makeLenses)
47 import qualified Data.Text.Lazy as TextLazy
56 Wos {_wos_limit :: Int}
57 | Csv {_csv_limit :: Int}
58 deriving (Show,Generic,Eq)
63 { _wlj_sensibility :: Double
64 , _wlj_thresholdInit :: Double
65 , _wlj_thresholdStep :: Double }
67 deriving (Show,Generic,Eq)
74 , _year_matchingFrame :: Int }
75 deriving (Show,Generic,Eq)
82 deriving (Show,Generic,Eq)
86 Config { corpusPath :: FilePath
87 , listPath :: FilePath
88 , outputPath :: FilePath
89 , corpusParser :: CorpusParser
92 , phyloProximity :: Proximity
93 , timeUnit :: TimeUnit
94 , contextualUnit :: ContextualUnit
96 } deriving (Show,Generic,Eq)
99 defaultConfig :: Config
101 Config { corpusPath = ""
104 , corpusParser = Csv 1000
105 , phyloName = pack "Default Phylo"
107 , phyloProximity = WeightedLogJaccard 10 0 0.2
108 , timeUnit = Year 3 1 5
109 , contextualUnit = Fis 2 4
113 instance FromJSON Config
114 instance ToJSON Config
115 instance FromJSON CorpusParser
116 instance ToJSON CorpusParser
117 instance FromJSON Proximity
118 instance ToJSON Proximity
119 instance FromJSON TimeUnit
120 instance ToJSON TimeUnit
121 instance FromJSON ContextualUnit
122 instance ToJSON ContextualUnit
125 -- | Software parameters
127 Software { _software_name :: Text
128 , _software_version :: Text
129 } deriving (Generic, Show, Eq)
131 defaultSoftware :: Software
133 Software { _software_name = pack "Gargantext"
134 , _software_version = pack "v4" }
137 -- | Global parameters of a Phylo
139 PhyloParam { _phyloParam_version :: Text
140 , _phyloParam_software :: Software
141 , _phyloParam_config :: Config
142 } deriving (Generic, Show, Eq)
144 defaultPhyloParam :: PhyloParam
146 PhyloParam { _phyloParam_version = pack "v2.adaptative"
147 , _phyloParam_software = defaultSoftware
148 , _phyloParam_config = defaultConfig }
156 -- | Date : a simple Integer
159 -- | Ngrams : a contiguous sequence of n terms
162 -- | Document : a piece of Text linked to a Date
163 data Document = Document
166 } deriving (Eq,Show,Generic,NFData)
174 -- | The Foundations of a Phylo created from a given TermList
175 data PhyloFoundations = PhyloFoundations
176 { _foundations_roots :: !(Vector Ngrams)
177 , _foundations_mapList :: TermList
178 } deriving (Generic, Show, Eq)
181 ---------------------------
182 -- | Coocurency Matrix | --
183 ---------------------------
186 -- | Cooc : a coocurency matrix between two ngrams
187 type Cooc = Map (Int,Int) Double
195 -- | Phylo datatype of a phylomemy
196 -- foundations : the foundations of the phylo
197 -- timeCooc : a Map of coocurency by minimal unit of time (ex: by year)
198 -- timeDocs : a Map with the numbers of docs by minimal unit of time (ex: by year)
199 -- param : the parameters of the phylomemy (with the user's configuration)
200 -- periods : the temporal steps of a phylomemy
202 Phylo { _phylo_foundations :: PhyloFoundations
203 , _phylo_timeCooc :: !(Map Date Cooc)
204 , _phylo_timeDocs :: !(Map Date Double)
205 , _phylo_param :: PhyloParam
206 , _phylo_periods :: Map PhyloPeriodId PhyloPeriod
208 deriving (Generic, Show, Eq)
211 -- | PhyloPeriodId : the id of a given period
212 type PhyloPeriodId = (Date,Date)
214 -- | PhyloPeriod : steps of a phylomemy on a temporal axis
215 -- id: tuple (start date, end date) of the temporal step of the phylomemy
216 -- levels: levels of granularity
218 PhyloPeriod { _phylo_periodPeriod :: (Date,Date)
219 , _phylo_periodLevels :: Map PhyloLevelId PhyloLevel
220 } deriving (Generic, Show, Eq)
223 -- | Level : a level of clustering
226 -- | PhyloLevelId : the id of a level of clustering in a given period
227 type PhyloLevelId = (PhyloPeriodId,Level)
229 -- | PhyloLevel : levels of phylomemy on a synchronic axis
230 -- Levels description:
231 -- Level 0: The foundations and the base of the phylo
232 -- Level 1: First level of clustering (the Fis)
233 -- Level [2..N]: Nth level of synchronic clustering (cluster of Fis)
235 PhyloLevel { _phylo_levelPeriod :: (Date,Date)
236 , _phylo_levelLevel :: Level
237 , _phylo_levelGroups :: Map PhyloGroupId PhyloGroup
239 deriving (Generic, Show, Eq)
242 type PhyloGroupId = (PhyloLevelId, Int)
244 -- | BranchId : (a level, a sequence of branch index)
245 -- the sequence is a path of heritage from the most to the less specific branch
246 type PhyloBranchId = (Level, [Int])
248 -- | PhyloGroup : group of ngrams at each level and period
250 PhyloGroup { _phylo_groupPeriod :: (Date,Date)
251 , _phylo_groupLevel :: Level
252 , _phylo_groupIndex :: Int
253 , _phylo_groupSupport :: Support
254 , _phylo_groupNgrams :: [Int]
255 , _phylo_groupCooc :: !(Cooc)
256 , _phylo_groupBranchId :: PhyloBranchId
257 , _phylo_groupLevelParents :: [Pointer]
258 , _phylo_groupLevelChilds :: [Pointer]
259 , _phylo_groupPeriodParents :: [Pointer]
260 , _phylo_groupPeriodChilds :: [Pointer]
261 , _phylo_groupGhostPointers :: [Pointer]
263 deriving (Generic, Show, Eq)
265 -- | Weight : A generic mesure that can be associated with an Id
268 -- | Pointer : A weighted pointer to a given PhyloGroup
269 type Pointer = (PhyloGroupId, Weight)
271 type Link = ((PhyloGroupId, PhyloGroupId), Weight)
273 data Filiation = ToParents | ToChilds deriving (Generic, Show)
274 data PointerType = TemporalPointer | LevelPointer deriving (Generic, Show)
277 ---------------------------
278 -- | Frequent Item Set | --
279 ---------------------------
281 -- | Clique : Set of ngrams cooccurring in the same Document
282 type Clique = Set Ngrams
284 -- | Support : Number of Documents where a Clique occurs
287 -- | Fis : Frequent Items Set (ie: the association between a Clique and a Support)
288 data PhyloFis = PhyloFis
289 { _phyloFis_clique :: Clique
290 , _phyloFis_support :: Support
291 , _phyloFis_period :: (Date,Date)
292 } deriving (Generic,NFData,Show,Eq)
299 type DotId = TextLazy.Text
306 makeLenses ''Proximity
307 makeLenses ''ContextualUnit
308 makeLenses ''TimeUnit
309 makeLenses ''PhyloFoundations
310 makeLenses ''PhyloFis
312 makeLenses ''PhyloPeriod
313 makeLenses ''PhyloLevel
314 makeLenses ''PhyloGroup
315 makeLenses ''PhyloParam
317 ------------------------
318 -- | JSON instances | --
319 ------------------------
322 $(deriveJSON (unPrefix "_foundations_" ) ''PhyloFoundations)