Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Merten
haskell-gargantext
Commits
c3a9237b
Commit
c3a9237b
authored
Oct 30, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACT] SocialLists: merging scores
parent
6160cc34
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
150 additions
and
95 deletions
+150
-95
Social.hs
src/Gargantext/Core/Text/List/Social.hs
+12
-19
Group.hs
src/Gargantext/Core/Text/List/Social/Group.hs
+110
-49
ListType.hs
src/Gargantext/Core/Text/List/Social/ListType.hs
+28
-27
No files found.
src/Gargantext/Core/Text/List/Social.hs
View file @
c3a9237b
...
@@ -11,30 +11,23 @@ Portability : POSIX
...
@@ -11,30 +11,23 @@ Portability : POSIX
module
Gargantext.Core.Text.List.Social
module
Gargantext.Core.Text.List.Social
where
where
-- findList imports
import
Gargantext.Core.Types.Individu
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Table.Node.Error
import
Gargantext.Database.Query.Tree
import
Gargantext.Database.Query.Tree.Root
(
getRootId
)
import
Gargantext.Prelude
-- filterList imports
import
Data.Maybe
(
fromMaybe
)
import
Data.Map
(
Map
)
import
Data.Map
(
Map
)
import
Data.
Set
(
Set
)
import
Data.
Maybe
(
fromMaybe
)
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Set
(
Set
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.API.Ngrams.Tools
-- (getListNgrams)
import
Gargantext.API.Ngrams.Tools
-- (getListNgrams)
import
Gargantext.API.Ngrams.Types
import
Gargantext.API.Ngrams.Types
import
Gargantext.Core.Types.Main
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Core.Text.List.Social.Find
import
Gargantext.Core.Text.List.Social.Find
import
Gargantext.Core.Text.List.Social.Group
import
Gargantext.Core.Text.List.Social.ListType
import
Gargantext.Core.Text.List.Social.ListType
import
qualified
Data.List
as
List
import
Gargantext.Core.Types.Individu
import
Gargantext.Core.Types.Main
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Table.Node.Error
import
Gargantext.Database.Query.Tree
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Prelude
import
qualified
Data.Map
as
Map
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
import
qualified
Data.Set
as
Set
...
@@ -76,8 +69,8 @@ flowSocialListByMode :: ( RepoCmdM env err m
...
@@ -76,8 +69,8 @@ flowSocialListByMode :: ( RepoCmdM env err m
)
)
=>
[
NodeId
]
->
NgramsType
->
Set
Text
=>
[
NodeId
]
->
NgramsType
->
Set
Text
->
m
(
Map
(
Maybe
ListType
)
(
Set
Text
))
->
m
(
Map
(
Maybe
ListType
)
(
Set
Text
))
flowSocialListByMode
[]
nt
ngrams'
=
pure
$
Map
.
fromList
[(
Nothing
,
ngrams'
)]
flowSocialListByMode
[]
_
nt
ngrams'
=
pure
$
Map
.
fromList
[(
Nothing
,
ngrams'
)]
flowSocialListByMode
listIds
nt
ngrams'
=
do
flowSocialListByMode
listIds
nt
ngrams'
=
do
counts
<-
countFilterList
ngrams'
nt
listIds
Map
.
empty
counts
<-
countFilterList
ngrams'
nt
listIds
Map
.
empty
let
r
=
toSocialList
counts
ngrams'
let
r
=
toSocialList
counts
ngrams'
pure
r
pure
r
...
...
src/Gargantext/Core/Text/List/Social/Group.hs
View file @
c3a9237b
...
@@ -8,38 +8,39 @@ Stability : experimental
...
@@ -8,38 +8,39 @@ Stability : experimental
Portability : POSIX
Portability : POSIX
-}
-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
module
Gargantext.Core.Text.List.Social.Group
module
Gargantext.Core.Text.List.Social.Group
where
where
-- findList imports
import
Control.Lens
import
Data.Map
(
Map
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Set
(
Set
)
import
Data.Text
(
Text
)
import
GHC.Generics
(
Generic
)
import
Gargantext.API.Ngrams.Types
import
Gargantext.Core.Types.Individu
import
Gargantext.Core.Types.Individu
import
Gargantext.Core.Types.Main
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Table.Node.Error
import
Gargantext.Database.Query.Table.Node.Error
import
Gargantext.Database.Query.Tree
import
Gargantext.Database.Query.Tree.Root
(
getRootId
)
import
Gargantext.Prelude
import
Gargantext.Prelude
-- filterList imports
import
Data.Maybe
(
fromMaybe
)
import
Data.Map
(
Map
)
import
Data.Set
(
Set
)
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Text
(
Text
)
import
Gargantext.API.Ngrams.Tools
-- (getListNgrams)
import
Gargantext.API.Ngrams.Types
import
Gargantext.Core.Types.Main
import
Gargantext.Database.Schema.Ngrams
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
----------------------
----------------------
--------------------------------------------------
-- | Tools to inherit groupings
-- | Tools to inherit groupings
----------------------
------------------------------------------------------------------------
type
Parent
=
Text
-- | Tools
parentUnionsMerge
::
(
Ord
a
,
Ord
b
,
Num
c
)
parentUnionsMerge
::
(
Ord
a
,
Ord
b
,
Num
c
)
=>
[
Map
a
(
Map
b
c
)]
=>
[
Map
a
(
Map
b
c
)]
->
Map
a
(
Map
b
c
)
->
Map
a
(
Map
b
c
)
...
@@ -56,6 +57,9 @@ parentUnionsExcl :: Ord a
...
@@ -56,6 +57,9 @@ parentUnionsExcl :: Ord a
->
Map
a
b
->
Map
a
b
parentUnionsExcl
=
Map
.
unions
parentUnionsExcl
=
Map
.
unions
------------------------------------------------------------------------
type
Parent
=
Text
hasParent
::
Text
hasParent
::
Text
->
Map
Text
(
Map
Parent
Int
)
->
Map
Text
(
Map
Parent
Int
)
...
@@ -64,43 +68,100 @@ hasParent t m = case Map.lookup t m of
...
@@ -64,43 +68,100 @@ hasParent t m = case Map.lookup t m of
Nothing
->
Nothing
Nothing
->
Nothing
Just
m'
->
(
fst
.
fst
)
<$>
Map
.
maxViewWithKey
m'
Just
m'
->
(
fst
.
fst
)
<$>
Map
.
maxViewWithKey
m'
------------------------------------------------------------------------
toMapTextParent
::
Set
Text
data
FlowListScores
=
->
Map
Text
(
Map
Parent
Int
)
FlowListScores
{
_flc_parents
::
Map
Parent
Int
->
[
Map
Text
NgramsRepoElement
]
,
_flc_lists
::
Map
ListType
Int
->
Map
Text
(
Map
Parent
Int
)
-- You can add any score by incrementing this type
toMapTextParent
ts
=
foldl'
(
toMapTextParent'
ts
)
-- , _flc_score :: Map Score Int
where
}
deriving
(
Generic
)
toMapTextParent'
::
Set
Text
makeLenses
''
F
lowListScores
->
Map
Text
(
Map
Parent
Int
)
->
Map
Text
NgramsRepoElement
->
Map
Text
(
Map
Parent
Int
)
toMapTextParent'
ts'
to
from
=
Set
.
foldl'
(
toMapTextParent''
ts'
from
)
to
ts'
------------------------------------------------------------------------
-- | toFlowListScores which generate Score from list of Map Text NgramsRepoElement
toMapTextParent''
::
Set
Text
toFlowListScores
::
Set
Text
->
Map
Text
FlowListScores
->
[
Map
Text
NgramsRepoElement
]
->
Map
Text
FlowListScores
toFlowListScores
ts
=
foldl'
(
toFlowListScores'
ts
)
where
toFlowListScores'
::
Set
Text
->
Map
Text
FlowListScores
->
Map
Text
NgramsRepoElement
->
Map
Text
FlowListScores
toFlowListScores'
ts'
to'
ngramsRepo
=
Set
.
foldl'
(
toFlowListScores''
ts'
ngramsRepo
)
to'
ts'
toFlowListScores''
::
Set
Text
->
Map
Text
NgramsRepoElement
->
Map
Text
NgramsRepoElement
->
Map
Text
(
Map
Parent
Int
)
->
Map
Text
FlowListScores
->
Text
->
Text
->
Map
Text
(
Map
Parent
Int
)
->
Map
Text
FlowListScores
toMapTextParent''
ss
from
to
t
=
case
Map
.
lookup
t
from
of
toFlowListScores''
ss
ngramsRepo
to''
t
=
Nothing
->
to
case
Map
.
lookup
t
ngramsRepo
of
Just
nre
->
case
_nre_parent
nre
of
Nothing
->
to''
Just
(
NgramsTerm
p'
)
->
if
Set
.
member
p'
ss
Just
nre
->
Map
.
alter
(
addParent
nre
ss
)
t
then
Map
.
alter
(
addParent
p'
)
t
to
$
Map
.
alter
(
addList
$
_nre_list
nre
)
t
to''
else
to
where
------------------------------------------------------------------------
addParent
p''
Nothing
=
Just
$
addCountParent
p''
Map
.
empty
-- | Main addFunctions to FlowListScores
addParent
p''
(
Just
ps
)
=
Just
$
addCountParent
p''
ps
------------------------------------------------------------------------
addCountParent
::
Parent
->
Map
Parent
Int
->
Map
Parent
Int
-- | Very unseful but nice comment:
addCountParent
p
m
=
Map
.
alter
addCount
p
m
-- "this function looks like an ASCII bird"
where
addList
::
ListType
addCount
Nothing
=
Just
1
->
Maybe
FlowListScores
addCount
(
Just
n
)
=
Just
$
n
+
1
->
Maybe
FlowListScores
addList
l
Nothing
=
_
->
to
Just
$
FlowListScores
Map
.
empty
(
addList'
l
Map
.
empty
)
addList
l
(
Just
(
FlowListScores
mapParent
mapList
))
=
Just
$
FlowListScores
mapParent
mapList'
where
mapList'
=
addList'
l
mapList
addList'
::
ListType
->
Map
ListType
Int
->
Map
ListType
Int
addList'
l
m
=
Map
.
alter
(
plus
l
)
l
m
where
plus
CandidateTerm
Nothing
=
Just
1
plus
CandidateTerm
(
Just
x
)
=
Just
$
x
+
1
plus
_
Nothing
=
Just
3
plus
_
(
Just
x
)
=
Just
$
x
+
3
------------------------------------------------------------------------
------------------------------------------------------------------------
addParent
::
NgramsRepoElement
->
Set
Text
->
Maybe
FlowListScores
->
Maybe
FlowListScores
addParent
nre
ss
Nothing
=
Just
$
FlowListScores
mapParent
Map
.
empty
where
mapParent
=
addParent'
(
_nre_parent
nre
)
ss
Map
.
empty
addParent
nre
ss
(
Just
(
FlowListScores
mapParent
mapList
))
=
Just
$
FlowListScores
mapParent'
mapList
where
mapParent'
=
addParent'
(
_nre_parent
nre
)
ss
mapParent
addParent'
::
Num
a
=>
Maybe
NgramsTerm
->
Set
Text
->
Map
Text
a
->
Map
Text
a
addParent'
Nothing
_ss
mapParent
=
mapParent
addParent'
(
Just
(
NgramsTerm
p'
))
ss
mapParent
=
if
not
(
Set
.
member
p'
ss
)
then
mapParent
else
Map
.
alter
addCount
p'
mapParent
where
addCount
Nothing
=
Just
1
addCount
(
Just
n
)
=
Just
$
n
+
1
------------------------------------------------------------------------
------------------------------------------------------------------------
src/Gargantext/Core/Text/List/Social/ListType.hs
View file @
c3a9237b
...
@@ -40,14 +40,14 @@ import qualified Data.Set as Set
...
@@ -40,14 +40,14 @@ import qualified Data.Set as Set
-- here we need UserList only
-- here we need UserList only
countFilterList
::
RepoCmdM
env
err
m
countFilterList
::
RepoCmdM
env
err
m
=>
Set
Text
->
NgramsType
->
[
ListId
]
=>
Set
Text
->
NgramsType
->
[
ListId
]
->
Map
Text
(
Map
ListType
Int
)
->
Map
Text
(
Map
ListType
Int
)
->
m
(
Map
Text
(
Map
ListType
Int
))
->
m
(
Map
Text
(
Map
ListType
Int
))
countFilterList
st
nt
ls
input
=
countFilterList
st
nt
ls
input
=
foldM'
(
\
m
l
->
countFilterList'
st
nt
[
l
]
m
)
input
ls
foldM'
(
\
m
l
->
countFilterList'
st
nt
[
l
]
m
)
input
ls
where
where
countFilterList'
::
RepoCmdM
env
err
m
countFilterList'
::
RepoCmdM
env
err
m
=>
Set
Text
->
NgramsType
->
[
ListId
]
=>
Set
Text
->
NgramsType
->
[
ListId
]
->
Map
Text
(
Map
ListType
Int
)
->
Map
Text
(
Map
ListType
Int
)
->
m
(
Map
Text
(
Map
ListType
Int
))
->
m
(
Map
Text
(
Map
ListType
Int
))
countFilterList'
st
nt
ls
input
=
do
countFilterList'
st
nt
ls
input
=
do
ml
<-
toMapTextListType
<$>
getListNgrams
ls
nt
ml
<-
toMapTextListType
<$>
getListNgrams
ls
nt
...
@@ -60,25 +60,24 @@ toMapTextListType m = Map.fromListWith (<>)
...
@@ -60,25 +60,24 @@ toMapTextListType m = Map.fromListWith (<>)
$
List
.
concat
$
List
.
concat
$
map
(
toList
m
)
$
map
(
toList
m
)
$
Map
.
toList
m
$
Map
.
toList
m
where
toList
::
Map
Text
NgramsRepoElement
->
(
Text
,
NgramsRepoElement
)
->
[(
Text
,
ListType
)]
toList
m
(
t
,
nre
@
(
NgramsRepoElement
_
_
_
_
(
MSet
children
)))
=
List
.
zip
terms
(
List
.
cycle
[
lt'
])
where
terms
=
[
t
]
-- <> maybe [] (\n -> [unNgramsTerm n]) root
-- <> maybe [] (\n -> [unNgramsTerm n]) parent
<>
(
map
unNgramsTerm
$
Map
.
keys
children
)
lt'
=
listOf
m
nre
------------------------------------------------------------------------
listOf
::
Map
Text
NgramsRepoElement
->
NgramsRepoElement
->
ListType
toList
::
Map
Text
NgramsRepoElement
->
(
Text
,
NgramsRepoElement
)
->
[(
Text
,
ListType
)]
listOf
m
ng
=
case
_nre_parent
ng
of
toList
m
(
t
,
nre
@
(
NgramsRepoElement
_
_
_
_
(
MSet
children
)))
=
Nothing
->
_nre_list
ng
List
.
zip
terms
(
List
.
cycle
[
lt'
])
Just
p
->
case
Map
.
lookup
(
unNgramsTerm
p
)
m
of
where
Just
ng'
->
listOf
m
ng'
terms
=
[
t
]
Nothing
->
CandidateTerm
-- <> maybe [] (\n -> [unNgramsTerm n]) root
-- panic "[G.C.T.L.Social.listOf] Nothing: Should Not happen"
-- <> maybe [] (\n -> [unNgramsTerm n]) parent
<>
(
map
unNgramsTerm
$
Map
.
keys
children
)
lt'
=
listOf
m
nre
listOf
::
Map
Text
NgramsRepoElement
->
NgramsRepoElement
->
ListType
listOf
m
ng
=
case
_nre_parent
ng
of
Nothing
->
_nre_list
ng
Just
p
->
case
Map
.
lookup
(
unNgramsTerm
p
)
m
of
Just
ng'
->
listOf
m
ng'
Nothing
->
CandidateTerm
-- panic "[G.C.T.L.Social.listOf] Nothing: Should Not happen"
------------------------------------------------------------------------
------------------------------------------------------------------------
countList
::
Text
countList
::
Text
...
@@ -89,14 +88,16 @@ countList t m input = case Map.lookup t m of
...
@@ -89,14 +88,16 @@ countList t m input = case Map.lookup t m of
Nothing
->
input
Nothing
->
input
Just
l
->
Map
.
alter
addList
t
input
Just
l
->
Map
.
alter
addList
t
input
where
where
addList
Nothing
=
Just
$
addCountList
l
Map
.
empty
addList
Nothing
=
Just
$
addCountList
l
Map
.
empty
addList
(
Just
lm
)
=
Just
$
addCountList
l
lm
addList
(
Just
lm
)
=
Just
$
addCountList
l
lm
addCountList
::
ListType
->
Map
ListType
Int
->
Map
ListType
Int
addCountList
::
ListType
->
Map
ListType
Int
->
Map
ListType
Int
addCountList
l
m
=
Map
.
alter
(
plus
l
)
l
m
addCountList
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
plus
_
Nothing
=
Just
3
plus
_
(
Just
x
)
=
Just
$
x
+
3
plus
_
Nothing
=
Just
3
plus
_
(
Just
x
)
=
Just
$
x
+
3
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment