Commit a5bcf8db authored by Alexandre Delanoë's avatar Alexandre Delanoë

[RENAME] name and newtypes for createIndices.

parent 47ed713f
...@@ -21,7 +21,7 @@ import qualified Data.Map.Strict as M ...@@ -21,7 +21,7 @@ import qualified Data.Map.Strict as M
import Gargantext.Core (Lang(FR)) import Gargantext.Core (Lang(FR))
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Viz.Graph.Index (score, createIndexes, toIndex) import Gargantext.Viz.Graph.Index (score, createIndices, toIndex)
import Gargantext.Viz.Graph.Distances.Matrice (distributional) import Gargantext.Viz.Graph.Distances.Matrice (distributional)
import Gargantext.Text.Metrics.Occurrences (cooc, removeApax) import Gargantext.Text.Metrics.Occurrences (cooc, removeApax)
import Gargantext.Text.Terms (TermType(Multi, Mono), extractTerms) import Gargantext.Text.Terms (TermType(Multi, Mono), extractTerms)
...@@ -43,7 +43,7 @@ pipeline path = do ...@@ -43,7 +43,7 @@ pipeline path = do
-- Cooc -> Matrix -- Cooc -> Matrix
let theScores = M.filter (/=0) $ score distributional myCooc let theScores = M.filter (/=0) $ score distributional myCooc
let (ti, _) = createIndexes theScores let (ti, _) = createIndices theScores
-- Matrix -> Clustering -> Graph -> JSON -- Matrix -> Clustering -> Graph -> JSON
pure $ bestpartition False $ map2graph $ toIndex ti theScores pure $ bestpartition False $ map2graph $ toIndex ti theScores
......
...@@ -39,6 +39,8 @@ import qualified Data.Set as S ...@@ -39,6 +39,8 @@ import qualified Data.Set as S
import Data.Map (Map) import Data.Map (Map)
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import Data.Vector (Vector)
import Gargantext.Prelude import Gargantext.Prelude
type Index = Int type Index = Int
...@@ -50,7 +52,7 @@ score :: (Ord t) => (A.Matrix Int -> A.Matrix Double) ...@@ -50,7 +52,7 @@ score :: (Ord t) => (A.Matrix Int -> A.Matrix Double)
-> Map (t, t) Double -> Map (t, t) Double
score f m = fromIndex fromI . mat2map . f $ cooc2mat toI m score f m = fromIndex fromI . mat2map . f $ cooc2mat toI m
where where
(toI, fromI) = createIndexes m (toI, fromI) = createIndices m
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -79,21 +81,30 @@ toIndex ni ns = indexConversion ni ns ...@@ -79,21 +81,30 @@ toIndex ni ns = indexConversion ni ns
fromIndex :: Ord t => Map Index t -> Map (Index, Index) a -> Map (t,t) a fromIndex :: Ord t => Map Index t -> Map (Index, Index) a -> Map (t,t) a
fromIndex ni ns = indexConversion ni ns fromIndex ni ns = indexConversion ni ns
---------------------------------------------------------------------------------
indexConversion :: (Ord b, Ord k) => Map k b -> Map (k,k) a -> Map (b, b) a indexConversion :: (Ord b, Ord k) => Map k b -> Map (k,k) a -> Map (b, b) a
indexConversion index ms = M.fromList $ map (\((k1,k2),c) -> ( ((M.!) index k1, (M.!) index k2), c)) (M.toList ms) indexConversion index ms = M.fromList $ map (\((k1,k2),c) -> ( ((M.!) index k1, (M.!) index k2), c)) (M.toList ms)
---------------------------------------------------------------------------------
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
------------------------------------------------------------------------------- -- TODO
createIndexes :: Ord t => Map (t, t) b -> (Map t Index, Map Index t) fromIndex' :: Ord t => Vector t -> Map (Index, Index) a -> Map (t,t) a
createIndexes = set2indexes . cooc2set fromIndex' vi ns = undefined
-- TODO
createIndices' :: Ord t => Map (t, t) b -> (Map t Index, Vector t)
createIndices' = undefined
createIndices :: Ord t => Map (t, t) b -> (Map t Index, Map Index t)
createIndices = set2indices . map2set
where where
cooc2set :: Ord t => Map (t, t) a -> Set t map2set :: Ord t => Map (t, t) a -> Set t
cooc2set cs' = foldl' (\s ((t1,t2),_) -> insert [t1,t2] s ) S.empty (M.toList cs') map2set cs' = foldl' (\s ((t1,t2),_) -> insert [t1,t2] s ) S.empty (M.toList cs')
where where
insert as s = foldl' (\s' t -> S.insert t s') s as insert as s = foldl' (\s' t -> S.insert t s') s as
set2indexes :: Ord t => Set t -> (Map t Index, Map Index t) set2indices :: Ord t => Set t -> (Map t Index, Map Index t)
set2indexes s = (M.fromList toIndex', M.fromList fromIndex') set2indices s = (M.fromList toIndex', M.fromList fromIndex')
where where
fromIndex' = zip [0..] xs fromIndex' = zip [0..] xs
toIndex' = zip xs [0..] toIndex' = zip xs [0..]
......
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