Commit c9512dee authored by Quentin Lobbé's avatar Quentin Lobbé

refactoring

parent f6f6d304
...@@ -138,14 +138,28 @@ data PhyloBranch = ...@@ -138,14 +138,28 @@ data PhyloBranch =
} }
deriving (Generic, Show) deriving (Generic, Show)
-- | PhyloPeriodId : A period of time framed by a starting Date and an ending Date
type PhyloPeriodId = (Start, End) type PhyloPeriodId = (Start, End)
type PhyloLevelId = (PhyloPeriodId, Int) -- | Level : A level of aggregation (-1 = Txt, 0 = Ngrams, 1 = Fis, [2..] = Cluster)
type PhyloGroupId = (PhyloLevelId, Int) type Level = Int
-- | Index : A generic index of an element (PhyloGroup, PhyloBranch, etc) in a given List
type Index = Int
type PhyloLevelId = (PhyloPeriodId, Level)
type PhyloGroupId = (PhyloLevelId, Index)
type PhyloBranchId = (Level, Index)
type Pointer = (PhyloGroupId, Weight) type Pointer = (PhyloGroupId, Weight)
type Weight = Double type Weight = Double
type PhyloBranchId = (Int, Int)
-- | Ngrams : a contiguous sequence of n terms -- | Ngrams : a contiguous sequence of n terms
...@@ -159,24 +173,9 @@ type Clique = Set Ngrams ...@@ -159,24 +173,9 @@ type Clique = Set Ngrams
-- | Support : Number of Documents where a Clique occurs -- | Support : Number of Documents where a Clique occurs
type Support = Int type Support = Int
-- | Fis : Frequent Items Set (ie: the association between a Clique and a Support) -- | Fis : Frequent Items Set (ie: the association between a Clique and a Support)
type Fis = Map Clique Support type Fis = (Clique,Support)
data Direction = From | To
deriving (Show, Eq)
data LevelLabel = Level_m1 | Level_0 | Level_1 | Level_mN | Level_N | Level_pN
deriving (Show, Eq, Enum, Bounded)
data Level =
Level { _levelLabel :: LevelLabel
, _levelValue :: Int
} deriving (Show, Eq)
data LevelLink =
LevelLink { _levelFrom :: Level
, _levelTo :: Level
} deriving (Show)
-- | Document : a piece of Text linked to a Date -- | Document : a piece of Text linked to a Date
data Document = Document data Document = Document
...@@ -184,6 +183,9 @@ data Document = Document ...@@ -184,6 +183,9 @@ data Document = Document
, text :: Text , text :: Text
} deriving (Show) } deriving (Show)
data PhyloError = LevelDoesNotExist data PhyloError = LevelDoesNotExist
| LevelUnassigned | LevelUnassigned
deriving (Show) deriving (Show)
...@@ -209,8 +211,6 @@ makeLenses ''Software ...@@ -209,8 +211,6 @@ makeLenses ''Software
makeLenses ''PhyloGroup makeLenses ''PhyloGroup
makeLenses ''PhyloLevel makeLenses ''PhyloLevel
makeLenses ''PhyloPeriod makeLenses ''PhyloPeriod
makeLenses ''Level
makeLenses ''LevelLink
makeLenses ''PhyloBranch makeLenses ''PhyloBranch
-- | JSON instances -- | JSON instances
......
This diff is collapsed.
...@@ -21,7 +21,7 @@ import Control.Lens hiding (both, Level) ...@@ -21,7 +21,7 @@ import Control.Lens hiding (both, Level)
import Data.List (filter, intersect, (++), sort, null, head, tail, last, tails, delete, nub) import Data.List (filter, intersect, (++), sort, null, head, tail, last, tails, delete, nub)
import Data.Map (Map, mapKeys, member) import Data.Map (Map, mapKeys, member)
import Data.Set (Set) import Data.Set (Set)
import Data.Text (Text) import Data.Text (Text, toLower)
import Data.Tuple.Extra import Data.Tuple.Extra
import Data.Vector (Vector,elemIndex) import Data.Vector (Vector,elemIndex)
import Gargantext.Prelude hiding (head) import Gargantext.Prelude hiding (head)
...@@ -30,6 +30,7 @@ import Gargantext.Viz.Phylo ...@@ -30,6 +30,7 @@ import Gargantext.Viz.Phylo
import qualified Data.List as List import qualified Data.List as List
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.Vector as Vector
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -201,30 +202,19 @@ getIdx x v = case (elemIndex x v) of ...@@ -201,30 +202,19 @@ getIdx x v = case (elemIndex x v) of
Just i -> i Just i -> i
-- | To get the label of a Level -- | To get the good pair of keys (x,y) or (y,x) in a given Map (a,b) c
getLevelLabel :: Level -> LevelLabel getKeyPair :: (Int,Int) -> Map (Int,Int) a -> (Int,Int)
getLevelLabel lvl = _levelLabel lvl getKeyPair (x,y) m = case findPair (x,y) m of
Nothing -> panic "[ERR][Viz.Phylo.Example.getKeyPair] Nothing"
Just i -> i
-- | To get the value of a Level where
getLevelValue :: Level -> Int --------------------------------------
getLevelValue lvl = _levelValue lvl findPair :: (Int,Int) -> Map (Int,Int) a -> Maybe (Int,Int)
findPair (x,y) m
| member (x,y) m = Just (x,y)
-- | To get the label of a LevelLink based on a Direction | member (y,x) m = Just (y,x)
getLevelLinkLabel :: Direction -> LevelLink -> LevelLabel | otherwise = Nothing
getLevelLinkLabel dir link = case dir of --------------------------------------
From -> view (levelFrom . levelLabel) link
To -> view (levelTo . levelLabel) link
_ -> panic "[ERR][Viz.Phylo.Tools.getLevelLinkLabel] Wrong direction"
-- | To get the value of a LevelLink based on a Direction
getLevelLinkValue :: Direction -> LevelLink -> Int
getLevelLinkValue dir link = case dir of
From -> view (levelFrom . levelValue) link
To -> view (levelTo . levelValue) link
_ -> panic "[ERR][Viz.Phylo.Tools.getLevelLinkValue] Wrong direction"
-- | To get the neighbours (directed/undirected) of a PhyloGroup from a list of PhyloEdges -- | To get the neighbours (directed/undirected) of a PhyloGroup from a list of PhyloEdges
...@@ -268,14 +258,14 @@ initGroup ngrams lbl idx lvl from to p = PhyloGroup ...@@ -268,14 +258,14 @@ initGroup ngrams lbl idx lvl from to p = PhyloGroup
[] [] [] [] [] [] [] []
-- | To create a Level -- | To init a PhyloNgrams as a Vector of Ngrams
initLevel :: Int -> LevelLabel -> Level initNgrams :: [Ngrams] -> PhyloNgrams
initLevel lvl lbl = Level lbl lvl initNgrams l = Vector.fromList $ map toLower l
-- | To create a LevelLink -- | To init a Phylomemy
initLevelLink :: Level -> Level -> LevelLink initPhylo :: [Document] -> PhyloNgrams -> Phylo
initLevelLink lvl lvl' = LevelLink lvl lvl' initPhylo docs ngrams = Phylo (both date $ (last &&& head) docs) ngrams [] []
-- | To create a PhyloLevel -- | To create a PhyloLevel
...@@ -288,6 +278,13 @@ initPhyloPeriod :: PhyloPeriodId -> [PhyloLevel] -> PhyloPeriod ...@@ -288,6 +278,13 @@ initPhyloPeriod :: PhyloPeriodId -> [PhyloLevel] -> PhyloPeriod
initPhyloPeriod id l = PhyloPeriod id l initPhyloPeriod id l = PhyloPeriod id l
-- | To filter Fis with small Support but by keeping non empty Periods
keepFilled :: (Int -> [a] -> [a]) -> Int -> [a] -> [a]
keepFilled f thr l = if (null $ f thr l) && (not $ null l)
then keepFilled f (thr - 1) l
else f thr l
-- | To get all combinations of a list -- | To get all combinations of a list
listToDirectedCombi :: Eq a => [a] -> [(a,a)] listToDirectedCombi :: Eq a => [a] -> [(a,a)]
listToDirectedCombi l = [(x,y) | x <- l, y <- l, x /= y] listToDirectedCombi l = [(x,y) | x <- l, y <- l, x /= y]
...@@ -322,16 +319,11 @@ setPhyloLevelId lvl' (PhyloLevel (id, lvl) groups) ...@@ -322,16 +319,11 @@ setPhyloLevelId lvl' (PhyloLevel (id, lvl) groups)
-- | To choose a LevelLink strategy based an a given Level -- | To choose a LevelLink strategy based an a given Level
shouldLink :: LevelLink -> [Int] -> [Int] -> Bool shouldLink :: (Level,Level) -> [Int] -> [Int] -> Bool
shouldLink lvl l l' shouldLink (lvl,lvl') l l'
| from <= 1 = doesContainsOrd l l' | lvl <= 1 = doesContainsOrd l l'
| from > 1 = undefined | lvl > 1 = undefined
| otherwise = panic ("[ERR][Viz.Phylo.Tools.shouldLink] LevelLink not defined") | otherwise = panic ("[ERR][Viz.Phylo.Tools.shouldLink] LevelLink not defined")
where
--------------------------------------
from :: Int
from = getLevelLinkValue From lvl
--------------------------------------
-- | To unify the keys (x,y) that Map 1 share with Map 2 such as: (x,y) <=> (y,x) -- | To unify the keys (x,y) that Map 1 share with Map 2 such as: (x,y) <=> (y,x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment