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

[DOC] better variable names + warnings

parent fbac7b49
...@@ -132,7 +132,7 @@ unions' = invertBack . Map.unionsWith (<>) . map invertForw ...@@ -132,7 +132,7 @@ unions' = invertBack . Map.unionsWith (<>) . map invertForw
invertForw :: (Ord b, Semigroup a) => Map a (Set b) -> Map b a invertForw :: (Ord b, Semigroup a) => Map a (Set b) -> Map b a
invertForw = Map.unionsWith (<>) invertForw = Map.unionsWith (<>)
. (map (\(k,sets) -> Map.fromSet (\_ -> k) sets)) . (map (\(k,st) -> Map.fromSet (\_ -> k) st))
. Map.toList . Map.toList
invertBack :: (Ord a, Ord b) => Map b a -> Map a (Set b) invertBack :: (Ord a, Ord b) => Map b a -> Map a (Set b)
......
...@@ -35,30 +35,34 @@ toFlowListScores :: KeepAllParents ...@@ -35,30 +35,34 @@ toFlowListScores :: KeepAllParents
-> FlowListCont Text -> FlowListCont Text
-> [Map Text NgramsRepoElement] -> [Map Text NgramsRepoElement]
-> FlowListCont Text -> FlowListCont Text
toFlowListScores k flc = foldl' (toFlowListScores' k flc) mempty toFlowListScores k flc_origin = foldl' (toFlowListScores_Level1 k flc_origin) mempty
where where
toFlowListScores' :: KeepAllParents
toFlowListScores_Level1 :: KeepAllParents
-> FlowListCont Text -> FlowListCont Text
-> FlowListCont Text -> FlowListCont Text
-> Map Text NgramsRepoElement -> Map Text NgramsRepoElement
-> FlowListCont Text -> FlowListCont Text
toFlowListScores' k' flc flc' ngramsRepo = toFlowListScores_Level1 k' flc_origin' flc_dest ngramsRepo =
Set.foldl' (toFlowListScores'' k' ngramsRepo flc) flc' (view flc_cont flc) Set.foldl' (toFlowListScores_Level2 k' ngramsRepo flc_origin')
flc_dest
(view flc_cont flc_origin')
toFlowListScores'' :: KeepAllParents toFlowListScores_Level2 :: KeepAllParents
-> Map Text NgramsRepoElement -> Map Text NgramsRepoElement
-> FlowListCont Text -> FlowListCont Text
-> FlowListCont Text -> FlowListCont Text
-> Text -> Text
-> FlowListCont Text -> FlowListCont Text
toFlowListScores'' k'' ngramsRepo flc to'' t = toFlowListScores_Level2 k'' ngramsRepo flc_origin'' flc_dest' t =
case Map.lookup t ngramsRepo of case Map.lookup t ngramsRepo of
Nothing -> over flc_cont (Set.insert t) to'' Nothing -> over flc_cont (Set.insert t) flc_dest'
Just nre -> over flc_scores Just nre -> over flc_scores
( (Map.alter (addParent k'' nre (view flc_cont flc)) t) ( (Map.alter (addParent k'' nre (view flc_cont flc_origin'')) t)
. (Map.alter (addList $ _nre_list nre) t) . (Map.alter (addList $ _nre_list nre) t)
) to'' ) flc_dest'
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Main addFunctions to groupResolution the FlowListScores -- | Main addFunctions to groupResolution the FlowListScores
...@@ -68,18 +72,17 @@ addList :: ListType ...@@ -68,18 +72,17 @@ addList :: ListType
-> Maybe FlowListScores -> Maybe FlowListScores
-> Maybe FlowListScores -> Maybe FlowListScores
addList l Nothing = addList l Nothing =
Just $ FlowListScores Map.empty (addList' l Map.empty) Just $ FlowListScores Map.empty (addListScore l Map.empty)
addList l (Just (FlowListScores mapParent mapList)) = addList l (Just (FlowListScores mapParent mapList)) =
Just $ FlowListScores mapParent mapList' Just $ FlowListScores mapParent (addListScore l mapList)
where
mapList' = addList' l mapList
-- * Unseful but nice comment: -- * Unseful but nice comment:
-- "the addList function looks like an ASCII bird" -- "the addList function looks like an ASCII bird"
-- | Concrete function to pass to PatchMap -- | Concrete function to pass to PatchMap
addList' :: ListType -> Map ListType Int -> Map ListType Int addListScore :: ListType -> Map ListType Int -> Map ListType Int
addList' l m = Map.alter (plus l) l m addListScore l m = Map.alter (plus l) l m
where where
plus CandidateTerm Nothing = Just 1 plus CandidateTerm Nothing = Just 1
plus CandidateTerm (Just x) = Just $ x + 1 plus CandidateTerm (Just x) = Just $ x + 1
...@@ -90,7 +93,6 @@ addList' l m = Map.alter (plus l) l m ...@@ -90,7 +93,6 @@ addList' l m = Map.alter (plus l) l m
plus StopTerm Nothing = Just 3 plus StopTerm Nothing = Just 3
plus StopTerm (Just x) = Just $ x + 3 plus StopTerm (Just x) = Just $ x + 3
------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
data KeepAllParents = KeepAllParents Bool data KeepAllParents = KeepAllParents Bool
...@@ -101,21 +103,21 @@ addParent :: KeepAllParents -> NgramsRepoElement -> Set Text ...@@ -101,21 +103,21 @@ addParent :: KeepAllParents -> NgramsRepoElement -> Set Text
addParent k nre ss Nothing = addParent k nre ss Nothing =
Just $ FlowListScores mapParent Map.empty Just $ FlowListScores mapParent Map.empty
where where
mapParent = addParent' k (_nre_parent nre) ss Map.empty mapParent = addParentScore k (_nre_parent nre) ss Map.empty
addParent k nre ss (Just (FlowListScores mapParent mapList)) = addParent k nre ss (Just (FlowListScores mapParent mapList)) =
Just $ FlowListScores mapParent' mapList Just $ FlowListScores mapParent' mapList
where where
mapParent' = addParent' k (_nre_parent nre) ss mapParent mapParent' = addParentScore k (_nre_parent nre) ss mapParent
addParent' :: Num a addParentScore :: Num a
=> KeepAllParents => KeepAllParents
-> Maybe NgramsTerm -> Maybe NgramsTerm
-> Set Text -> Set Text
-> Map Text a -> Map Text a
-> Map Text a -> Map Text a
addParent' _ Nothing _ss mapParent = mapParent addParentScore _ Nothing _ss mapParent = mapParent
addParent' (KeepAllParents k) (Just (NgramsTerm p')) ss mapParent = addParentScore (KeepAllParents k) (Just (NgramsTerm p')) ss mapParent =
case k of case k of
True -> Map.alter addCount p' mapParent True -> Map.alter addCount p' mapParent
False -> case Set.member p' ss of False -> case Set.member p' ss of
......
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