Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
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
Przemyslaw Kaminski
haskell-gargantext
Commits
35ed3bb7
Commit
35ed3bb7
authored
Oct 13, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Social Lists] WIP
parent
3e6c662a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
20 deletions
+50
-20
Social.hs
src/Gargantext/Core/Text/List/Social.hs
+50
-20
No files found.
src/Gargantext/Core/Text/List/Social.hs
View file @
35ed3bb7
...
@@ -25,15 +25,15 @@ import Gargantext.Prelude
...
@@ -25,15 +25,15 @@ import Gargantext.Prelude
import
Data.Maybe
(
fromMaybe
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Map
(
Map
)
import
Data.Map
(
Map
)
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
import
Data.Semigroup
(
Semigroup
(
..
))
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.Core.Types.Main
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Ngrams
import
qualified
Data.List
as
List
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
flowSocialList
::
(
RepoCmdM
env
err
m
flowSocialList
::
(
RepoCmdM
env
err
m
,
CmdM
env
err
m
,
CmdM
env
err
m
...
@@ -44,20 +44,39 @@ flowSocialList :: ( RepoCmdM env err m
...
@@ -44,20 +44,39 @@ 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)
sharedLists
<-
flowSocialListByMode
Shared
user
nt
(
termsByList
CandidateTerm
privateLists
)
sharedLists
<-
flowSocialListByMode
Shared
user
nt
(
termsByList
CandidateTerm
privateLists
)
-- printDebug "* social
Lists *: \n" sharedLists
printDebug
"* shared
Lists *:
\n
"
sharedLists
-- TODO publicMapList
-- TODO publicMapList
pure
$
Map
.
fromList
[
(
MapTerm
,
termsByList
MapTerm
privateLists
let
result
=
unions
[
Map
.
mapKeys
(
fromMaybe
CandidateTerm
)
privateLists
<>
termsByList
MapTerm
sharedLists
,
Map
.
mapKeys
(
fromMaybe
CandidateTerm
)
sharedLists
)
]
,
(
StopTerm
,
termsByList
StopTerm
privateLists
printDebug
"* socialLists *: results
\n
"
sharedLists
<>
termsByList
StopTerm
sharedLists
pure
result
)
,
(
CandidateTerm
,
termsByList
CandidateTerm
sharedLists
)
]
------------------------------------------------------------------------
unions
::
(
Ord
a
,
Semigroup
a
,
Semigroup
b
,
Ord
b
)
=>
[
Map
a
(
Set
b
)]
->
Map
a
(
Set
b
)
unions
=
foldl'
union
Map
.
empty
union
::
(
Ord
a
,
Semigroup
a
,
Semigroup
b
,
Ord
b
)
=>
Map
a
(
Set
b
)
->
Map
a
(
Set
b
)
->
Map
a
(
Set
b
)
union
m1
m2
=
invertBack
$
Map
.
unionWith
(
<>
)
(
invert
m1
)
(
invert
m2
)
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
=
Map
.
fromListWith
(
<>
)
.
(
map
(
\
(
b
,
a
)
->
(
a
,
Set
.
singleton
b
)))
.
Map
.
toList
------------------------------------------------------------------------
termsByList
::
ListType
->
(
Map
(
Maybe
ListType
)
(
Set
Text
))
->
Set
Text
termsByList
::
ListType
->
(
Map
(
Maybe
ListType
)
(
Set
Text
))
->
Set
Text
termsByList
CandidateTerm
m
=
Set
.
unions
termsByList
CandidateTerm
m
=
Set
.
unions
...
@@ -67,7 +86,6 @@ termsByList l m =
...
@@ -67,7 +86,6 @@ termsByList l m =
fromMaybe
Set
.
empty
$
Map
.
lookup
(
Just
l
)
m
fromMaybe
Set
.
empty
$
Map
.
lookup
(
Just
l
)
m
flowSocialListByMode
::
(
RepoCmdM
env
err
m
flowSocialListByMode
::
(
RepoCmdM
env
err
m
,
CmdM
env
err
m
,
CmdM
env
err
m
,
HasNodeError
err
,
HasNodeError
err
...
@@ -81,8 +99,10 @@ flowSocialListByMode mode user nt ngrams' = do
...
@@ -81,8 +99,10 @@ 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
pure
$
toSocialList
counts
ngrams'
let
r
=
toSocialList
counts
ngrams'
printDebug
"flowSocialListByMode r"
r
pure
r
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- TODO: maybe use social groups too
-- TODO: maybe use social groups too
...
@@ -107,6 +127,16 @@ toSocialList1 m t = case Map.lookup t m of
...
@@ -107,6 +127,16 @@ toSocialList1 m t = case Map.lookup t m of
,
Set
.
singleton
t
,
Set
.
singleton
t
)
)
toSocialList1_testIsTrue
::
Bool
toSocialList1_testIsTrue
=
result
==
(
Just
MapTerm
,
Set
.
singleton
token
)
where
result
=
toSocialList1
(
Map
.
fromList
[(
token
,
m
)])
token
token
=
"token"
m
=
Map
.
fromList
[
(
CandidateTerm
,
1
)
,
(
MapTerm
,
2
)
,
(
StopTerm
,
3
)
]
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- | [ListId] does not merge the lists (it is for Master and User lists
-- | [ListId] does not merge the lists (it is for Master and User lists
-- here we need UserList only
-- here we need UserList only
...
@@ -131,9 +161,9 @@ countFilterList' st nt ls input = do
...
@@ -131,9 +161,9 @@ countFilterList' st nt ls input = do
-- FIXME children have to herit the ListType of the parent
-- FIXME children have to herit the ListType of the parent
toMapTextListType
::
Map
Text
NgramsRepoElement
->
Map
Text
ListType
toMapTextListType
::
Map
Text
NgramsRepoElement
->
Map
Text
ListType
toMapTextListType
m
=
Map
.
fromListWith
(
<>
)
toMapTextListType
m
=
Map
.
fromListWith
(
<>
)
$
List
.
concat
$
List
.
concat
$
(
map
(
toList
m
))
$
(
map
(
toList
m
))
$
Map
.
toList
m
$
Map
.
toList
m
toList
::
Map
Text
NgramsRepoElement
->
(
Text
,
NgramsRepoElement
)
->
[(
Text
,
ListType
)]
toList
::
Map
Text
NgramsRepoElement
->
(
Text
,
NgramsRepoElement
)
->
[(
Text
,
ListType
)]
toList
m
(
t
,
nre
@
(
NgramsRepoElement
_
_
_
_
(
MSet
children
)))
=
toList
m
(
t
,
nre
@
(
NgramsRepoElement
_
_
_
_
(
MSet
children
)))
=
...
...
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