, fisWithSizePoly
, fisWithSizePoly2
, fisWithSizePolyMap
+ , fisWithSizePolyMap'
, module HLCM
)
where
-import Prelude (Functor(..)) -- TODO
-import qualified Data.Map.Strict as Map
+import Data.List (concat, null)
import Data.Map.Strict (Map)
-import qualified Data.Set as Set
+import Data.Maybe (catMaybes, isNothing)
import Data.Set (Set)
-import qualified Data.Vector as V
-
-import Data.List (concat, null)
-import Data.Maybe (catMaybes)
-
+import Gargantext.Prelude
import HLCM
+import qualified Data.Map.Strict as Map
+import qualified Data.Set as Set
+import qualified Data.Vector as V
-import Gargantext.Prelude
+import Control.Monad (sequence)
data Size = Point Int | Segment Int Int
------------------------------------------------------------------------
------------------------------------------------------------------------
+---- Weighted [[Item]]
+
+isSublistOf :: Ord a => [a] -> [a] -> Bool
+isSublistOf sub lst = all (\i -> elem i lst) sub
+
+reIndexFis :: Ord a => [([a],(b,c))] -> [Fis' a] -> [(Fis' a,([b],[c]))]
+reIndexFis items fis = map (\f ->
+ let docs = filter (\(lst,_) -> isSublistOf (_fisItemSet f) lst) items
+ in (f, (map (fst . snd) docs, map (snd . snd) docs))) fis
+
+wsum :: [Maybe Double] -> Int -> Maybe Double
+wsum lst sup =
+ let w = fmap sum $ sequence lst
+ in
+ if (isNothing w)
+ then Just $ fromIntegral sup
+ else w
+
+fisWithSizePolyMap' :: Ord a => Size -> Frequency -> [([a], (Maybe Double,[Int]))] -> Map (Set a) (Int, (Maybe Double,[Int]))
+fisWithSizePolyMap' n f is = Map.fromList
+ $ map (\(fis,(ws,sources)) -> (Set.fromList (_fisItemSet fis),(_fisCount fis,(wsum ws (_fisCount fis),concat sources))))
+ $ reIndexFis is
+ $ fisWithSizePoly2 n f (map fst is)
+
+------------------------------------------------------------------------
+------------------------------------------------------------------------
+
--
---- | /!\ indexes are not the same: