Commit 0e44e77f authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Social List] increments with listIds either Private or Shared, need group filtering in textflow

parent 35ed3bb7
...@@ -151,7 +151,7 @@ buildNgramsTermsList user l n m _s uCid mCid = do ...@@ -151,7 +151,7 @@ buildNgramsTermsList user l n m _s uCid mCid = do
-- stopTerms ignored for now (need to be tagged already) -- stopTerms ignored for now (need to be tagged already)
(stopTerms, candidateTerms) = List.partition ((\t -> Set.member t socialStop) . fst) allTerms (stopTerms, candidateTerms) = List.partition ((\t -> Set.member t socialStop) . fst) allTerms
printDebug "stopTerms" stopTerms printDebug "\n * stopTerms * \n" stopTerms
-- Grouping the ngrams and keeping the maximum score for label -- Grouping the ngrams and keeping the maximum score for label
let grouped = groupStems' let grouped = groupStems'
...@@ -286,13 +286,15 @@ buildNgramsTermsList user l n m _s uCid mCid = do ...@@ -286,13 +286,15 @@ buildNgramsTermsList user l n m _s uCid mCid = do
printDebug "multScoredInclHead" multScoredInclHead printDebug "multScoredInclHead" multScoredInclHead
printDebug "multScoredExclTail" multScoredExclTail printDebug "multScoredExclTail" multScoredExclTail
pure $ Map.unionsWith (<>) let result = Map.unionsWith (<>)
[ Map.fromList [( [ Map.fromList [(
NgramsTerms, (List.concat $ map toNgramsElement $ termListHead) NgramsTerms, (List.concat $ map toNgramsElement $ termListHead)
<> (List.concat $ map toNgramsElement $ termListTail) <> (List.concat $ map toNgramsElement $ termListTail)
)] )]
, toElements NgramsTerms StopTerm stopTerms , toElements NgramsTerms StopTerm stopTerms
] ]
-- printDebug "\n result \n" r
pure result
groupStems :: [(Stem, GroupedText Double)] -> [GroupedText Double] groupStems :: [(Stem, GroupedText Double)] -> [GroupedText Double]
groupStems = Map.elems . groupStems' groupStems = Map.elems . groupStems'
......
...@@ -44,38 +44,42 @@ flowSocialList :: ( RepoCmdM env err m ...@@ -44,38 +44,42 @@ flowSocialList :: ( RepoCmdM env err m
-> m (Map ListType (Set Text)) -> m (Map ListType (Set Text))
flowSocialList user nt ngrams' = do flowSocialList user nt ngrams' = do
privateLists <- flowSocialListByMode Private user nt ngrams' privateLists <- flowSocialListByMode Private user nt ngrams'
printDebug "* privateLists *: \n" privateLists -- printDebug "* privateLists *: \n" privateLists
-- here preference to privateLists (discutable) -- here preference to privateLists (discutable)
sharedLists <- flowSocialListByMode Shared user nt (termsByList CandidateTerm privateLists) sharedLists <- flowSocialListByMode Shared user nt (termsByList CandidateTerm privateLists)
printDebug "* sharedLists *: \n" sharedLists -- printDebug "* sharedLists *: \n" sharedLists
-- TODO publicMapList -- TODO publicMapList
let result = unions [ Map.mapKeys (fromMaybe CandidateTerm) privateLists let result = unions [ Map.mapKeys (fromMaybe CandidateTerm) privateLists
, Map.mapKeys (fromMaybe CandidateTerm) sharedLists , Map.mapKeys (fromMaybe CandidateTerm) sharedLists
] ]
printDebug "* socialLists *: results \n" sharedLists printDebug "* socialLists *: results \n" result
pure result pure result
------------------------------------------------------------------------ ------------------------------------------------------------------------
unions :: (Ord a, Semigroup a, Semigroup b, Ord b) unions :: (Ord a, Semigroup a, Semigroup b, Ord b)
=> [Map a (Set b)] -> Map a (Set b) => [Map a (Set b)] -> Map a (Set b)
unions = foldl' union Map.empty unions = invertBack . Map.unionsWith (<>) . map invertForw
union :: (Ord a, Semigroup a, Semigroup b, Ord b) invertForw :: (Ord b, Semigroup a) => Map a (Set b) -> Map b a
=> Map a (Set b) -> Map a (Set b) -> Map a (Set b) invertForw = Map.unionsWith (<>)
union m1 m2 = invertBack $ Map.unionWith (<>) (invert m1) (invert m2) . (map (\(k,sets) -> Map.fromSet (\_ -> k) sets))
. Map.toList
invert :: (Ord b, Semigroup a) => Map a (Set b) -> Map b a
invert = Map.unionsWith (<>)
. (map (\(k,ss) -> Map.fromSet (\_ -> k) ss))
. 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)
invertBack = Map.fromListWith (<>) invertBack = Map.fromListWith (<>)
. (map (\(b,a) -> (a, Set.singleton b))) . (map (\(b,a) -> (a, Set.singleton b)))
. Map.toList . Map.toList
unions_test :: Map ListType (Set Text)
unions_test = unions [m1, m2]
where
m1 = Map.fromList [ (StopTerm, Set.singleton "Candidate")]
m2 = Map.fromList [ (CandidateTerm, Set.singleton "Candidate")
, (MapTerm, Set.singleton "Candidate")
]
------------------------------------------------------------------------ ------------------------------------------------------------------------
termsByList :: ListType -> (Map (Maybe ListType) (Set Text)) -> Set Text termsByList :: ListType -> (Map (Maybe ListType) (Set Text)) -> Set Text
...@@ -99,9 +103,9 @@ flowSocialListByMode mode user nt ngrams' = do ...@@ -99,9 +103,9 @@ flowSocialListByMode mode user nt ngrams' = do
[] -> pure $ Map.fromList [(Nothing, ngrams')] [] -> pure $ Map.fromList [(Nothing, ngrams')]
_ -> do _ -> do
counts <- countFilterList ngrams' nt listIds Map.empty counts <- countFilterList ngrams' nt listIds Map.empty
printDebug "flowSocialListByMode counts" counts -- printDebug "flowSocialListByMode counts" counts
let r = toSocialList counts ngrams' let r = toSocialList counts ngrams'
printDebug "flowSocialListByMode r" r -- printDebug "flowSocialListByMode r" r
pure r pure r
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
...@@ -180,7 +184,7 @@ listOf m ng = case _nre_parent ng of ...@@ -180,7 +184,7 @@ listOf m ng = case _nre_parent ng of
Nothing -> _nre_list ng Nothing -> _nre_list ng
Just p -> case Map.lookup (unNgramsTerm p) m of Just p -> case Map.lookup (unNgramsTerm p) m of
Just ng' -> listOf m ng' Just ng' -> listOf m ng'
Nothing -> CandidateTerm -- Should Not happen Nothing -> panic "CandidateTerm -- Should Not happen"
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
countList :: Text countList :: Text
...@@ -195,10 +199,13 @@ countList t m input = case Map.lookup t m of ...@@ -195,10 +199,13 @@ countList t m input = case Map.lookup t m of
addList (Just lm) = Just $ addCount l lm addList (Just lm) = Just $ addCount l lm
addCount :: ListType -> Map ListType Int -> Map ListType Int addCount :: ListType -> Map ListType Int -> Map ListType Int
addCount l m = Map.alter plus l m addCount l m = Map.alter (plus l) l m
where where
plus Nothing = Just 1 plus CandidateTerm Nothing = Just 1
plus (Just x) = Just $ x + 1 plus CandidateTerm (Just x) = Just $ x + 1
plus _ Nothing = Just 3
plus _ (Just x) = Just $ x + 3
------------------------------------------------------------------------ ------------------------------------------------------------------------
findListsId :: (HasNodeError err, HasTreeError err) findListsId :: (HasNodeError err, HasTreeError err)
...@@ -210,8 +217,6 @@ findListsId mode u = do ...@@ -210,8 +217,6 @@ findListsId mode u = do
-- printDebug "findListsIds" ns -- printDebug "findListsIds" ns
pure ns pure ns
commonNodes:: [NodeType]
commonNodes = [NodeFolder, NodeCorpus, NodeList]
findNodes' :: HasTreeError err findNodes' :: HasTreeError err
=> NodeMode -> RootId => NodeMode -> RootId
...@@ -219,3 +224,9 @@ findNodes' :: HasTreeError err ...@@ -219,3 +224,9 @@ findNodes' :: HasTreeError err
findNodes' Private r = findNodes Private r $ [NodeFolderPrivate] <> commonNodes findNodes' Private r = findNodes Private r $ [NodeFolderPrivate] <> commonNodes
findNodes' Shared r = findNodes Shared r $ [NodeFolderShared ] <> commonNodes findNodes' Shared r = findNodes Shared r $ [NodeFolderShared ] <> commonNodes
findNodes' Public r = findNodes Public r $ [NodeFolderPublic ] <> commonNodes findNodes' Public r = findNodes Public r $ [NodeFolderPublic ] <> commonNodes
commonNodes:: [NodeType]
commonNodes = [NodeFolder, NodeCorpus, NodeList]
...@@ -49,7 +49,8 @@ instance ToSchema NodeTree where ...@@ -49,7 +49,8 @@ instance ToSchema NodeTree where
type TypeId = Int type TypeId = Int
-- TODO multiple ListType declaration, remove it -- TODO multiple ListType declaration, remove it
data ListType = CandidateTerm | StopTerm | MapTerm -- data ListType = CandidateTerm | StopTerm | MapTerm
data ListType = StopTerm | CandidateTerm | MapTerm
deriving (Generic, Eq, Ord, Show, Read, Enum, Bounded) deriving (Generic, Eq, Ord, Show, Read, Enum, Bounded)
instance ToJSON ListType instance ToJSON ListType
...@@ -61,11 +62,11 @@ instance Arbitrary ListType where ...@@ -61,11 +62,11 @@ instance Arbitrary ListType where
instance Semigroup ListType instance Semigroup ListType
where where
MapTerm <> _ = MapTerm MapTerm <> _ = MapTerm
_ <> MapTerm = MapTerm _ <> MapTerm = MapTerm
StopTerm <> CandidateTerm = StopTerm StopTerm <> _ = StopTerm
CandidateTerm <> StopTerm = StopTerm _ <> StopTerm = StopTerm
_ <> _ = CandidateTerm _ <> _ = CandidateTerm
instance FromHttpApiData ListType where instance FromHttpApiData ListType where
......
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