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 FlexibleContexts #-}
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16 {-# LANGUAGE RankNTypes #-}
17 {-# LANGUAGE ViewPatterns #-}
19 module Gargantext.Viz.Phylo.Tools
22 import Control.Lens hiding (both, Level, Empty)
23 import Data.List (filter, intersect, (++), sort, null, head, tail, last, tails, delete, nub, concat, sortOn)
24 import Data.Maybe (mapMaybe,fromMaybe)
25 import Data.Map (Map, mapKeys, member, (!))
27 import Data.Text (Text, toLower)
28 import Data.Tuple.Extra
29 import Data.Vector (Vector,elemIndex)
30 import Gargantext.Prelude hiding (head)
31 import Gargantext.Viz.Phylo
32 import qualified Data.Map as Map
33 import qualified Data.Set as Set
34 import qualified Data.Vector as Vector
42 -- | Define a default value
43 def :: a -> Maybe a -> a
47 -- | Does a List of Sets contains at least one Set of an other List
48 doesAnySetContains :: Eq a => Set a -> [Set a] -> [Set a] -> Bool
49 doesAnySetContains h l l' = any (\c -> doesContains (Set.toList c) (Set.toList h)) (l' ++ l)
52 -- | Does a list of A contains an other list of A
53 doesContains :: Eq a => [a] -> [a] -> Bool
56 | length l' > length l = False
57 | elem (head l') l = doesContains l (tail l')
61 -- | Does a list of ordered A contains an other list of ordered A
62 doesContainsOrd :: Eq a => Ord a => [a] -> [a] -> Bool
65 | last l < head l' = False
66 | head l' `elem` l = True
67 | otherwise = doesContainsOrd l (tail l')
70 -- | To filter nested Sets of a
71 filterNestedSets :: Eq a => Set a -> [Set a] -> [Set a] -> [Set a]
72 filterNestedSets h l l'
73 | null l = if doesAnySetContains h l l'
76 | doesAnySetContains h l l' = filterNestedSets (head l) (tail l) l'
77 | otherwise = filterNestedSets (head l) (tail l) (h : l')
81 -- | To get the good pair of keys (x,y) or (y,x) in a given Map (a,b) c
82 getKeyPair :: (Int,Int) -> Map (Int,Int) a -> (Int,Int)
83 getKeyPair (x,y) m = case findPair (x,y) m of
84 Nothing -> panic "[ERR][Viz.Phylo.Example.getKeyPair] Nothing"
87 --------------------------------------
88 findPair :: (Int,Int) -> Map (Int,Int) a -> Maybe (Int,Int)
90 | member (x',y') m' = Just (x',y')
91 | member (y',x') m' = Just (y',x')
93 --------------------------------------
96 -- | To filter Fis with small Support but by keeping non empty Periods
97 keepFilled :: (Int -> [a] -> [a]) -> Int -> [a] -> [a]
98 keepFilled f thr l = if (null $ f thr l) && (not $ null l)
99 then keepFilled f (thr - 1) l
103 -- | To get all combinations of a list
104 listToDirectedCombi :: Eq a => [a] -> [(a,a)]
105 listToDirectedCombi l = [(x,y) | x <- l, y <- l, x /= y]
108 -- | To get all combinations of a list and apply a function to the resulting list of pairs
109 listToDirectedCombiWith :: Eq a => forall b. (a -> b) -> [a] -> [(b,b)]
110 listToDirectedCombiWith f l = [(f x,f y) | x <- l, y <- l, x /= y]
113 -- | To get all combinations of a list with no repetition
114 listToUnDirectedCombi :: [a] -> [(a,a)]
115 listToUnDirectedCombi l = [ (x,y) | (x:rest) <- tails l, y <- rest ]
118 -- | To get all combinations of a list with no repetition and apply a function to the resulting list of pairs
119 listToUnDirectedCombiWith :: forall a b. (a -> b) -> [a] -> [(b,b)]
120 listToUnDirectedCombiWith f l = [ (f x, f y) | (x:rest) <- tails l, y <- rest ]
123 -- | To unify the keys (x,y) that Map 1 share with Map 2 such as: (x,y) <=> (y,x)
124 unifySharedKeys :: Eq a => Ord a => Map (a,a) b -> Map (a,a) b -> Map (a,a) b
125 unifySharedKeys m1 m2 = mapKeys (\(x,y) -> if member (y,x) m2
135 -- | An analyzer ingests a Ngrams and generates a modified version of it
136 phyloAnalyzer :: Ngrams -> Ngrams
137 phyloAnalyzer n = toLower n
139 -- | To init the foundation of the Phylo as a Vector of Ngrams
140 initFoundations :: [Ngrams] -> Vector Ngrams
141 initFoundations l = Vector.fromList $ map phyloAnalyzer l
143 -- | To init the base of a Phylo from a List of Periods and Foundations
144 initPhyloBase :: [(Date, Date)] -> Vector Ngrams -> PhyloPeaks -> PhyloParam -> Phylo
145 initPhyloBase pds fds pks prm = Phylo ((fst . head) pds, (snd . last) pds) fds pks (map (\pd -> initPhyloPeriod pd []) pds) prm
147 -- | To init the param of a Phylo
148 initPhyloParam :: Maybe Text -> Maybe Software -> Maybe PhyloQueryBuild -> PhyloParam
149 initPhyloParam (def defaultPhyloVersion -> v) (def defaultSoftware -> s) (def defaultQuery -> q) = PhyloParam v s q
151 -- | To get the foundations of a Phylo
152 getFoundations :: Phylo -> Vector Ngrams
153 getFoundations = _phylo_foundations
155 -- | To get the Index of a Ngrams in the Foundations of a Phylo
156 getIdxInFoundations :: Ngrams -> Phylo -> Int
157 getIdxInFoundations n p = case (elemIndex n (getFoundations p)) of
158 Nothing -> panic "[ERR][Viz.Phylo.Tools.getIdxInFoundations] Ngrams not in Foundations"
162 -- | To get the last computed Level in a Phylo
163 getLastLevel :: Phylo -> Level
164 getLastLevel p = (last . sort)
165 $ map (snd . getPhyloLevelId)
166 $ view ( phylo_periods
168 . phylo_periodLevels ) p
175 -- | To apply a fonction to each label of a Ngrams Tree
176 alterLabels :: (Ngrams -> Ngrams) -> Tree Ngrams -> Tree Ngrams
177 alterLabels f (Node lbl ns) = Node (f lbl) (map (\n -> alterLabels f n) ns)
178 alterLabels _ Empty = panic "[ERR][Viz.Phylo.Tools.alterLabels] Empty"
180 -- | To transform a forest of trees into a map (node,root)
181 forestToMap :: [Tree Ngrams] -> Map Ngrams Ngrams
182 forestToMap trees = Map.fromList $ concat $ map treeToTuples' trees
184 treeToTuples' (Node lbl ns) = treeToTuples (Node lbl ns) lbl
185 treeToTuples' Empty = panic "[ERR][Viz.Phylo.Tools.forestToMap] Empty"
187 -- | To get the foundationsPeaks of a Phylo
188 getPeaks :: Phylo -> PhyloPeaks
189 getPeaks = _phylo_foundationsPeaks
191 -- | To get the peaksLabels of a Phylo
192 getPeaksLabels :: Phylo -> Vector Ngrams
193 getPeaksLabels p = (getPeaks p) ^. phylo_peaksLabels
195 -- | To get the Index of a Ngrams in the foundationsPeaks of a Phylo
196 getIdxInPeaks :: Ngrams -> Phylo -> Int
197 getIdxInPeaks n p = case (elemIndex n (getPeaksLabels p)) of
198 Nothing -> panic "[ERR][Viz.Phylo.Tools.getIdxInPeaks] Ngrams not in foundationsPeaks"
201 -- | To init the PhyloPeaks of a Phylo
202 initPeaks :: [Tree Ngrams] -> Vector Ngrams -> PhyloPeaks
203 initPeaks trees ns = PhyloPeaks labels trees
205 --------------------------------------
206 labels :: Vector Ngrams
207 labels = Vector.fromList
210 $ map (\n -> if member n mTrees
213 --------------------------------------
214 mTrees :: Map Ngrams Ngrams
215 mTrees = forestToMap trees
216 --------------------------------------
218 -- | To transform a Ngrams Tree into a list of (node,root)
219 treeToTuples :: Tree Ngrams -> Ngrams -> [(Ngrams,Ngrams)]
220 treeToTuples (Node lbl ns) root = [(lbl,root)] ++ (concat $ map (\n -> treeToTuples n root) ns)
221 treeToTuples Empty _ = panic "[ERR][Viz.Phylo.Tools.treeToTuples] Empty"
228 -- | To alter a PhyloGroup matching a given Level
229 alterGroupWithLevel :: (PhyloGroup -> PhyloGroup) -> Level -> Phylo -> Phylo
230 alterGroupWithLevel f lvl p = over ( phylo_periods
236 ) (\g -> if getGroupLevel g == lvl
241 -- | To alter each list of PhyloGroups following a given function
242 alterPhyloGroups :: ([PhyloGroup] -> [PhyloGroup]) -> Phylo -> Phylo
243 alterPhyloGroups f p = over ( phylo_periods
251 -- | To filter the PhyloGroup of a Phylo according to a function and a value
252 filterGroups :: Eq a => (PhyloGroup -> a) -> a -> [PhyloGroup] -> [PhyloGroup]
253 filterGroups f x l = filter (\g -> (f g) == x) l
256 -- | To maybe get the PhyloBranchId of a PhyloGroup
257 getGroupBranchId :: PhyloGroup -> Maybe PhyloBranchId
258 getGroupBranchId = _phylo_groupBranchId
261 -- | To get the PhyloGroups Childs of a PhyloGroup
262 getGroupChilds :: PhyloGroup -> Phylo -> [PhyloGroup]
263 getGroupChilds g p = getGroupsFromIds (getGroupPeriodChildsId g) p
266 -- | To get the id of a PhyloGroup
267 getGroupId :: PhyloGroup -> PhyloGroupId
268 getGroupId = _phylo_groupId
271 -- | To get the Cooc Matrix of a PhyloGroup
272 getGroupCooc :: PhyloGroup -> Map (Int,Int) Double
273 getGroupCooc = _phylo_groupCooc
276 -- | To get the level out of the id of a PhyloGroup
277 getGroupLevel :: PhyloGroup -> Int
278 getGroupLevel = snd . fst . getGroupId
281 -- | To get the level child pointers of a PhyloGroup
282 getGroupLevelChilds :: PhyloGroup -> [Pointer]
283 getGroupLevelChilds = _phylo_groupLevelChilds
286 -- | To get the PhyloGroups Level Childs Ids of a PhyloGroup
287 getGroupLevelChildsId :: PhyloGroup -> [PhyloGroupId]
288 getGroupLevelChildsId g = map fst $ getGroupLevelChilds g
291 -- | To get the level parent pointers of a PhyloGroup
292 getGroupLevelParents :: PhyloGroup -> [Pointer]
293 getGroupLevelParents = _phylo_groupLevelParents
296 -- | To get the PhyloGroups Level Parents Ids of a PhyloGroup
297 getGroupLevelParentsId :: PhyloGroup -> [PhyloGroupId]
298 getGroupLevelParentsId g = map fst $ getGroupLevelParents g
301 -- | To get the Ngrams of a PhyloGroup
302 getGroupNgrams :: PhyloGroup -> [Int]
303 getGroupNgrams = _phylo_groupNgrams
306 -- | To get the list of pairs (Childs & Parents) of a PhyloGroup
307 getGroupPairs :: PhyloGroup -> Phylo -> [PhyloGroup]
308 getGroupPairs g p = (getGroupChilds g p) ++ (getGroupParents g p)
311 -- | To get the PhyloGroups Parents of a PhyloGroup
312 getGroupParents :: PhyloGroup -> Phylo -> [PhyloGroup]
313 getGroupParents g p = getGroupsFromIds (getGroupPeriodParentsId g) p
316 -- | To get the period out of the id of a PhyloGroup
317 getGroupPeriod :: PhyloGroup -> (Date,Date)
318 getGroupPeriod = fst . fst . getGroupId
321 -- | To get the period child pointers of a PhyloGroup
322 getGroupPeriodChilds :: PhyloGroup -> [Pointer]
323 getGroupPeriodChilds = _phylo_groupPeriodChilds
326 -- | To get the PhyloGroups Period Parents Ids of a PhyloGroup
327 getGroupPeriodChildsId :: PhyloGroup -> [PhyloGroupId]
328 getGroupPeriodChildsId g = map fst $ getGroupPeriodChilds g
331 -- | To get the period parent pointers of a PhyloGroup
332 getGroupPeriodParents :: PhyloGroup -> [Pointer]
333 getGroupPeriodParents = _phylo_groupPeriodParents
336 -- | To get the PhyloGroups Period Parents Ids of a PhyloGroup
337 getGroupPeriodParentsId :: PhyloGroup -> [PhyloGroupId]
338 getGroupPeriodParentsId g = map fst $ getGroupPeriodParents g
341 -- | To get all the PhyloGroup of a Phylo
342 getGroups :: Phylo -> [PhyloGroup]
343 getGroups = view ( phylo_periods
351 -- | To get all PhyloGroups matching a list of PhyloGroupIds in a Phylo
352 getGroupsFromIds :: [PhyloGroupId] -> Phylo -> [PhyloGroup]
353 getGroupsFromIds ids p = filter (\g -> elem (getGroupId g) ids) $ getGroups p
356 -- | To get the corresponding list of PhyloGroups from a list of PhyloNodes
357 getGroupsFromNodes :: [PhyloNode] -> Phylo -> [PhyloGroup]
358 getGroupsFromNodes ns p = getGroupsFromIds (map getNodeId ns) p
361 -- | To get all the PhyloGroup of a Phylo with a given level and period
362 getGroupsWithFilters :: Int -> (Date,Date) -> Phylo -> [PhyloGroup]
363 getGroupsWithFilters lvl prd p = (getGroupsWithLevel lvl p)
365 (getGroupsWithPeriod prd p)
368 -- | To get all the PhyloGroup of a Phylo with a given Level
369 getGroupsWithLevel :: Int -> Phylo -> [PhyloGroup]
370 getGroupsWithLevel lvl p = filterGroups getGroupLevel lvl (getGroups p)
373 -- | To get all the PhyloGroup of a Phylo with a given Period
374 getGroupsWithPeriod :: (Date,Date) -> Phylo -> [PhyloGroup]
375 getGroupsWithPeriod prd p = filterGroups getGroupPeriod prd (getGroups p)
378 -- | To create a PhyloGroup in a Phylo out of a list of Ngrams and a set of parameters
379 initGroup :: [Ngrams] -> Text -> Int -> Int -> Int -> Int -> Phylo -> PhyloGroup
380 initGroup ngrams lbl idx lvl from' to' p = PhyloGroup
381 (((from', to'), lvl), idx)
383 (sort $ map (\x -> getIdxInPeaks x p) ngrams)
390 ---------------------
391 -- | PhyloPeriod | --
392 ---------------------
395 -- | To alter each PhyloPeriod of a Phylo following a given function
396 alterPhyloPeriods :: (PhyloPeriod -> PhyloPeriod) -> Phylo -> Phylo
397 alterPhyloPeriods f p = over ( phylo_periods
401 -- | To append a list of PhyloPeriod to a Phylo
402 appendToPhyloPeriods :: [PhyloPeriod] -> Phylo -> Phylo
403 appendToPhyloPeriods l p = over (phylo_periods) (++ l) p
406 -- | To get all the PhyloPeriodIds of a Phylo
407 getPhyloPeriods :: Phylo -> [PhyloPeriodId]
408 getPhyloPeriods p = map _phylo_periodId
409 $ view (phylo_periods) p
412 -- | To get the id of a given PhyloPeriod
413 getPhyloPeriodId :: PhyloPeriod -> PhyloPeriodId
414 getPhyloPeriodId prd = _phylo_periodId prd
417 -- | To create a PhyloPeriod
418 initPhyloPeriod :: PhyloPeriodId -> [PhyloLevel] -> PhyloPeriod
419 initPhyloPeriod id l = PhyloPeriod id l
427 -- | To alter a list of PhyloLevels following a given function
428 alterPhyloLevels :: ([PhyloLevel] -> [PhyloLevel]) -> Phylo -> Phylo
429 alterPhyloLevels f p = over ( phylo_periods
431 . phylo_periodLevels) f p
434 -- | To get the PhylolevelId of a given PhyloLevel
435 getPhyloLevelId :: PhyloLevel -> PhyloLevelId
436 getPhyloLevelId = _phylo_levelId
439 -- | To get all the Phylolevels of a given PhyloPeriod
440 getPhyloLevels :: PhyloPeriod -> [PhyloLevel]
441 getPhyloLevels = view (phylo_periodLevels)
444 -- | To create a PhyloLevel
445 initPhyloLevel :: PhyloLevelId -> [PhyloGroup] -> PhyloLevel
446 initPhyloLevel id groups = PhyloLevel id groups
449 -- | To set the LevelId of a PhyloLevel and of all its PhyloGroups
450 setPhyloLevelId :: Int -> PhyloLevel -> PhyloLevel
451 setPhyloLevelId lvl' (PhyloLevel (id, _lvl) groups)
452 = PhyloLevel (id, lvl') groups'
454 groups' = over (traverse . phylo_groupId)
455 (\((period, _lvl), idx) -> ((period, lvl'), idx))
464 -- | To get the clique of a PhyloFis
465 getClique :: PhyloFis -> Clique
466 getClique = _phyloFis_clique
468 -- | To get the metrics of a PhyloFis
469 getFisMetrics :: PhyloFis -> Map (Int,Int) (Map Text [Double])
470 getFisMetrics = _phyloFis_metrics
472 -- | To get the support of a PhyloFis
473 getSupport :: PhyloFis -> Support
474 getSupport = _phyloFis_support
477 ----------------------------
478 -- | PhyloNodes & Edges | --
479 ----------------------------
482 -- | To filter some GroupEdges with a given threshold
483 filterGroupEdges :: Double -> GroupEdges -> GroupEdges
484 filterGroupEdges thr edges = filter (\((_s,_t),w) -> w > thr) edges
487 -- | To get the neighbours (directed/undirected) of a PhyloGroup from a list of GroupEdges
488 getNeighbours :: Bool -> PhyloGroup -> GroupEdges -> [PhyloGroup]
489 getNeighbours directed g e = case directed of
490 True -> map (\((_s,t),_w) -> t)
491 $ filter (\((s,_t),_w) -> s == g) e
492 False -> map (\((s,t),_w) -> head $ delete g $ nub [s,t,g])
493 $ filter (\((s,t),_w) -> s == g || t == g) e
496 -- | To get the PhyloBranchId of PhyloNode if it exists
497 getNodeBranchId :: PhyloNode -> PhyloBranchId
498 getNodeBranchId n = case n ^. pn_bid of
499 Nothing -> panic "[ERR][Viz.Phylo.Tools.getNodeBranchId] branchId not found"
503 -- | To get the PhyloGroupId of a PhyloNode
504 getNodeId :: PhyloNode -> PhyloGroupId
505 getNodeId n = n ^. pn_id
508 -- | To get the Level of a PhyloNode
509 getNodeLevel :: PhyloNode -> Level
510 getNodeLevel n = (snd . fst) $ getNodeId n
513 -- | To get the Parent Node of a PhyloNode in a PhyloView
514 getNodeParent :: PhyloNode -> PhyloView -> [PhyloNode]
515 getNodeParent n v = filter (\n' -> elem (getNodeId n') (getNodeParentsId n))
519 -- | To get the Parent Node id of a PhyloNode if it exists
520 getNodeParentsId :: PhyloNode -> [PhyloGroupId]
521 getNodeParentsId n = case n ^. pn_parents of
522 Nothing -> panic "[ERR][Viz.Phylo.Tools.getNodeParentsId] node parent not found"
526 -- | To get a list of PhyloNodes grouped by PhyloBranch in a PhyloView
527 getNodesByBranches :: PhyloView -> [(PhyloBranchId,[PhyloNode])]
528 getNodesByBranches v = zip bIds $ map (\id -> filter (\n -> (getNodeBranchId n) == id)
529 $ getNodesInBranches v ) bIds
531 --------------------------------------
532 bIds :: [PhyloBranchId]
533 bIds = getViewBranchIds v
534 --------------------------------------
537 -- | To get a list of PhyloNodes owned by any PhyloBranches in a PhyloView
538 getNodesInBranches :: PhyloView -> [PhyloNode]
539 getNodesInBranches v = filter (\n -> isJust $ n ^. pn_bid)
543 -- | To get the PhyloGroupId of the Source of a PhyloEdge
544 getSourceId :: PhyloEdge -> PhyloGroupId
545 getSourceId e = e ^. pe_source
548 -- | To get the PhyloGroupId of the Target of a PhyloEdge
549 getTargetId :: PhyloEdge -> PhyloGroupId
550 getTargetId e = e ^. pe_target
553 ---------------------
554 -- | PhyloBranch | --
555 ---------------------
558 -- | To get the PhyloBranchId of a PhyloBranch
559 getBranchId :: PhyloBranch -> PhyloBranchId
560 getBranchId b = b ^. pb_id
563 -- | To get a list of PhyloBranchIds given a Level in a Phylo
564 getBranchIdsWith :: Level -> Phylo -> [PhyloBranchId]
565 getBranchIdsWith lvl p = sortOn snd
566 $ mapMaybe getGroupBranchId
567 $ getGroupsWithLevel lvl p
570 -- | To get the Meta value of a PhyloBranch
571 getBranchMeta :: Text -> PhyloBranch -> [Double]
572 getBranchMeta k b = (b ^. pb_metrics) ! k
575 -- | To get all the PhyloBranchIds of a PhyloView
576 getViewBranchIds :: PhyloView -> [PhyloBranchId]
577 getViewBranchIds v = map getBranchId $ v ^. pv_branches
580 --------------------------------
581 -- | PhyloQuery & QueryView | --
582 --------------------------------
584 -- | To get the first clustering method to apply to get the contextual units of a Phylo
585 getContextualUnit :: PhyloQueryBuild -> Cluster
586 getContextualUnit q = q ^. q_contextualUnit
589 -- | To get the metrics to apply to contextual units
590 getContextualUnitMetrics :: PhyloQueryBuild -> [Metric]
591 getContextualUnitMetrics q = q ^. q_contextualUnitMetrics
594 -- | To get the filters to apply to contextual units
595 getContextualUnitFilters :: PhyloQueryBuild -> [Filter]
596 getContextualUnitFilters q = q ^. q_contextualUnitFilters
599 -- | To get the cluster methods to apply to the Nths levels of a Phylo
600 getNthCluster :: PhyloQueryBuild -> Cluster
601 getNthCluster q = q ^. q_nthCluster
604 -- | To get the Sup Level of a reconstruction of a Phylo from a PhyloQuery
605 getNthLevel :: PhyloQueryBuild -> Level
606 getNthLevel q = q ^. q_nthLevel
609 -- | To get the Grain of the PhyloPeriods from a PhyloQuery
610 getPeriodGrain :: PhyloQueryBuild -> Int
611 getPeriodGrain q = q ^. q_periodGrain
614 -- | To get the intertemporal matching strategy to apply to a Phylo from a PhyloQuery
615 getInterTemporalMatching :: PhyloQueryBuild -> Proximity
616 getInterTemporalMatching q = q ^. q_interTemporalMatching
619 -- | To get the Steps of the PhyloPeriods from a PhyloQuery
620 getPeriodSteps :: PhyloQueryBuild -> Int
621 getPeriodSteps q = q ^. q_periodSteps
624 --------------------------------------------------
625 -- | PhyloQueryBuild & PhyloQueryView Constructors | --
626 --------------------------------------------------
629 -- | To get the Proximity associated to a given Clustering method
630 getProximity :: Cluster -> Proximity
631 getProximity cluster = case cluster of
632 Louvain (LouvainParams proxi) -> proxi
633 RelatedComponents (RCParams proxi) -> proxi
634 _ -> panic "[ERR][Viz.Phylo.Tools.getProximity] this cluster has no associated Proximity"
637 -- | To initialize all the Cluster / Proximity with their default parameters
638 initFis :: Maybe Bool -> Maybe Support -> FisParams
639 initFis (def True -> kmf) (def 1 -> min') = FisParams kmf min'
641 initHamming :: Maybe Double -> HammingParams
642 initHamming (def 0.01 -> sens) = HammingParams sens
644 initSmallBranch :: Maybe Int -> Maybe Int -> Maybe Int -> SBParams
645 initSmallBranch (def 2 -> periodsInf) (def 2 -> periodsSup) (def 1 -> minNodes) = SBParams periodsInf periodsSup minNodes
647 initLouvain :: Maybe Proximity -> LouvainParams
648 initLouvain (def defaultWeightedLogJaccard -> proxi) = LouvainParams proxi
650 initRelatedComponents :: Maybe Proximity -> RCParams
651 initRelatedComponents (def Filiation -> proxi) = RCParams proxi
653 initWeightedLogJaccard :: Maybe Double -> Maybe Double -> WLJParams
654 initWeightedLogJaccard (def 0 -> thr) (def 0.01 -> sens) = WLJParams thr sens
657 -- | To initialize a PhyloQuery from given and default parameters
658 initPhyloQuery :: Text -> Text -> Maybe Int -> Maybe Int -> Maybe Cluster -> Maybe [Metric] -> Maybe [Filter] -> Maybe Proximity -> Maybe Level -> Maybe Cluster -> PhyloQueryBuild
659 initPhyloQuery name desc (def 5 -> grain) (def 3 -> steps) (def defaultFis -> cluster) (def [] -> metrics) (def [] -> filters)
660 (def defaultWeightedLogJaccard -> matching') (def 2 -> nthLevel) (def defaultRelatedComponents -> nthCluster) =
661 PhyloQueryBuild name desc grain steps cluster metrics filters matching' nthLevel nthCluster
664 -- | To initialize a PhyloQueryView default parameters
665 initPhyloQueryView :: Maybe Level -> Maybe Filiation -> Maybe Bool -> Maybe Level -> Maybe [Metric] -> Maybe [Filter] -> Maybe [Tagger] -> Maybe (Sort, Order) -> Maybe DisplayMode -> Maybe Bool -> PhyloQueryView
666 initPhyloQueryView (def 2 -> lvl) (def Descendant -> f) (def False -> c) (def 1 -> d) (def [] -> ms) (def [] -> fs) (def [] -> ts) s (def Flat -> dm) (def True -> v) =
667 PhyloQueryView lvl f c d ms fs ts s dm v
670 -- | To define some obvious boolean getters
671 shouldKeepMinorFis :: FisParams -> Bool
672 shouldKeepMinorFis = _fis_keepMinorFis
674 ----------------------------
675 -- | Default ressources | --
676 ----------------------------
680 defaultFis :: Cluster
681 defaultFis = Fis (initFis Nothing Nothing)
683 defaultLouvain :: Cluster
684 defaultLouvain = Louvain (initLouvain Nothing)
686 defaultRelatedComponents :: Cluster
687 defaultRelatedComponents = RelatedComponents (initRelatedComponents Nothing)
691 defaultSmallBranch :: Filter
692 defaultSmallBranch = SmallBranch (initSmallBranch Nothing Nothing Nothing)
696 defaultPhyloParam :: PhyloParam
697 defaultPhyloParam = initPhyloParam Nothing Nothing Nothing
701 defaultHamming :: Proximity
702 defaultHamming = Hamming (initHamming Nothing)
704 defaultWeightedLogJaccard :: Proximity
705 defaultWeightedLogJaccard = WeightedLogJaccard (initWeightedLogJaccard Nothing Nothing)
709 defaultQuery :: PhyloQueryBuild
710 defaultQuery = initPhyloQuery "Cesar et Cleôpatre" "An example of Phylomemy (french without accent)"
711 Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
713 defaultQueryView :: PhyloQueryView
714 defaultQueryView = initPhyloQueryView Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
718 defaultSoftware :: Software
719 defaultSoftware = Software "Gargantext" "v4"
723 defaultPhyloVersion :: Text
724 defaultPhyloVersion = "v1"