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
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
8
Merge Requests
8
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
gargantext
haskell-gargantext
Commits
093afa75
Commit
093afa75
authored
Nov 02, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] SocialList refactor, Type ListType Ord fixed
parent
c3a9237b
Pipeline
#1184
failed with stage
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
57 deletions
+44
-57
List.hs
src/Gargantext/Core/Text/List.hs
+1
-1
Social.hs
src/Gargantext/Core/Text/List/Social.hs
+17
-7
Find.hs
src/Gargantext/Core/Text/List/Social/Find.hs
+0
-14
Group.hs
src/Gargantext/Core/Text/List/Social/Group.hs
+10
-12
ListType.hs
src/Gargantext/Core/Text/List/Social/ListType.hs
+10
-21
Main.hs
src/Gargantext/Core/Types/Main.hs
+6
-2
No files found.
src/Gargantext/Core/Text/List.hs
View file @
093afa75
...
...
@@ -129,7 +129,7 @@ buildNgramsTermsList user uCid mCid groupParams = do
printDebug
"
\n
* socialLists *
\n
"
socialLists
let
socialStop
=
fromMaybe
Set
.
empty
$
Map
.
lookup
StopTerm
socialLists
_socialStop
=
fromMaybe
Set
.
empty
$
Map
.
lookup
StopTerm
socialLists
_socialMap
=
fromMaybe
Set
.
empty
$
Map
.
lookup
MapTerm
socialLists
_socialCand
=
fromMaybe
Set
.
empty
$
Map
.
lookup
CandidateTerm
socialLists
-- stopTerms ignored for now (need to be tagged already)
...
...
src/Gargantext/Core/Text/List/Social.hs
View file @
093afa75
...
...
@@ -20,6 +20,7 @@ import Gargantext.API.Ngrams.Tools -- (getListNgrams)
import
Gargantext.API.Ngrams.Types
import
Gargantext.Core.Text.List.Social.Find
import
Gargantext.Core.Text.List.Social.ListType
import
Gargantext.Core.Text.List.Social.Group
import
Gargantext.Core.Types.Individu
import
Gargantext.Core.Types.Main
import
Gargantext.Database.Admin.Types.Node
...
...
@@ -54,7 +55,8 @@ flowSocialList user nt ngrams' = do
-- publicListIds <- findListsId Public user
-- publicLists <- flowSocialListByMode' publicListIds nt (termsByList CandidateTerm privateLists)
let
result
=
unions
[
Map
.
mapKeys
(
fromMaybe
CandidateTerm
)
privateLists
let
result
=
parentUnionsExcl
[
Map
.
mapKeys
(
fromMaybe
CandidateTerm
)
privateLists
,
Map
.
mapKeys
(
fromMaybe
CandidateTerm
)
sharedLists
-- , Map.mapKeys (fromMaybe CandidateTerm) publicLists
]
...
...
@@ -76,6 +78,17 @@ flowSocialListByMode listIds nt ngrams' = do
pure
r
flowSocialListByMode'
::
(
RepoCmdM
env
err
m
,
CmdM
env
err
m
,
HasNodeError
err
,
HasTreeError
err
)
=>
[
NodeId
]
->
NgramsType
->
Set
Text
->
m
(
Map
Text
FlowListScores
)
flowSocialListByMode'
ns
nt
st
=
do
ngramsRepos
<-
mapM
(
\
l
->
getListNgrams
[
l
]
nt
)
ns
pure
$
toFlowListScores
st
Map
.
empty
ngramsRepos
------------------------------------------------------------------------
-- TODO: maybe use social groups too
-- | TODO what if equality ?
...
...
@@ -111,7 +124,6 @@ toSocialList1_testIsTrue = result == (Just MapTerm, Set.singleton token)
------------------------------------------------------------------------
-- | Tools
------------------------------------------------------------------------
termsByList
::
ListType
->
(
Map
(
Maybe
ListType
)
(
Set
Text
))
->
Set
Text
termsByList
CandidateTerm
m
=
Set
.
unions
...
...
@@ -121,8 +133,6 @@ termsByList l m =
fromMaybe
Set
.
empty
$
Map
.
lookup
(
Just
l
)
m
------------------------------------------------------------------------
unions
::
(
Ord
a
,
Semigroup
a
,
Semigroup
b
,
Ord
b
)
=>
[
Map
a
(
Set
b
)]
->
Map
a
(
Set
b
)
unions
=
invertBack
.
Map
.
unionsWith
(
<>
)
.
map
invertForw
...
...
src/Gargantext/Core/Text/List/Social/Find.hs
View file @
093afa75
...
...
@@ -21,20 +21,6 @@ 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.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.Set
as
Set
------------------------------------------------------------------------
findListsId
::
(
HasNodeError
err
,
HasTreeError
err
)
=>
NodeMode
->
User
->
Cmd
err
[
NodeId
]
...
...
src/Gargantext/Core/Text/List/Social/Group.hs
View file @
093afa75
...
...
@@ -20,18 +20,12 @@ module Gargantext.Core.Text.List.Social.Group
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.Main
import
Gargantext.Database.Admin.Config
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Table.Node.Error
import
Gargantext.Prelude
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
...
...
@@ -58,7 +52,6 @@ parentUnionsExcl :: Ord a
parentUnionsExcl
=
Map
.
unions
------------------------------------------------------------------------
type
Parent
=
Text
hasParent
::
Text
...
...
@@ -68,8 +61,8 @@ hasParent t m = case Map.lookup t m of
Nothing
->
Nothing
Just
m'
->
(
fst
.
fst
)
<$>
Map
.
maxViewWithKey
m'
------------------------------------------------------------------------
------------------------------------------------------------------------
data
FlowListScores
=
FlowListScores
{
_flc_parents
::
Map
Parent
Int
,
_flc_lists
::
Map
ListType
Int
...
...
@@ -80,8 +73,13 @@ data FlowListScores =
makeLenses
''
F
lowListScores
instance
Semigroup
FlowListScores
where
(
<>
)
(
FlowListScores
p1
l1
)
(
FlowListScores
p2
l2
)
=
FlowListScores
(
p1
<>
p2
)
(
l1
<>
l2
)
------------------------------------------------------------------------
-- | toFlowListScores which generate Score from list of Map Text NgramsRepoElement
-- | toFlowListScores which generate Score from list of Map Text
-- NgramsRepoElement
toFlowListScores
::
Set
Text
->
Map
Text
FlowListScores
...
...
@@ -111,7 +109,7 @@ toFlowListScores ts = foldl' (toFlowListScores' ts)
-- | Main addFunctions to FlowListScores
------------------------------------------------------------------------
-- |
Very u
nseful but nice comment:
-- |
U
nseful but nice comment:
-- "this function looks like an ASCII bird"
addList
::
ListType
->
Maybe
FlowListScores
...
...
src/Gargantext/Core/Text/List/Social/ListType.hs
View file @
093afa75
...
...
@@ -11,22 +11,11 @@ Portability : POSIX
module
Gargantext.Core.Text.List.Social.ListType
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.Set
(
Set
)
import
Data.Semigroup
(
Semigroup
(
..
))
import
Data.Text
(
Text
)
import
Gargantext.Prelude
import
Gargantext.API.Ngrams.Tools
-- (getListNgrams)
import
Gargantext.API.Ngrams.Types
import
Gargantext.Core.Types.Main
...
...
@@ -49,9 +38,9 @@ countFilterList st nt ls input =
=>
Set
Text
->
NgramsType
->
[
ListId
]
->
Map
Text
(
Map
ListType
Int
)
->
m
(
Map
Text
(
Map
ListType
Int
))
countFilterList'
st
nt
ls
input
=
do
ml
<-
toMapTextListType
<$>
getListNgrams
ls
nt
pure
$
Set
.
foldl'
(
\
m
t
->
countList
t
ml
m
)
input
st
countFilterList'
st
'
nt'
ls'
input'
=
do
ml
<-
toMapTextListType
<$>
getListNgrams
ls
'
nt'
pure
$
Set
.
foldl'
(
\
m
t
->
countList
t
ml
m
)
input
'
st'
------------------------------------------------------------------------
-- FIXME children have to herit the ListType of the parent
...
...
@@ -62,20 +51,20 @@ toMapTextListType m = Map.fromListWith (<>)
$
Map
.
toList
m
where
toList
::
Map
Text
NgramsRepoElement
->
(
Text
,
NgramsRepoElement
)
->
[(
Text
,
ListType
)]
toList
m
(
t
,
nre
@
(
NgramsRepoElement
_
_
_
_
(
MSet
children
)))
=
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
lt'
=
listOf
m
'
nre
listOf
::
Map
Text
NgramsRepoElement
->
NgramsRepoElement
->
ListType
listOf
m
ng
=
case
_nre_parent
ng
of
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'
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"
...
...
@@ -93,7 +82,7 @@ countList t m input = case Map.lookup t m of
addList
(
Just
lm
)
=
Just
$
addCountList
l
lm
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
plus
CandidateTerm
Nothing
=
Just
1
plus
CandidateTerm
(
Just
x
)
=
Just
$
x
+
1
...
...
src/Gargantext/Core/Types/Main.hs
View file @
093afa75
...
...
@@ -50,7 +50,7 @@ instance ToSchema NodeTree where
type
TypeId
=
Int
-- TODO multiple ListType declaration, remove it
-- data ListType = CandidateTerm | StopTerm | MapTerm
data
ListType
=
StopTerm
|
Candidate
Term
|
MapTerm
data
ListType
=
CandidateTerm
|
Stop
Term
|
MapTerm
deriving
(
Generic
,
Eq
,
Ord
,
Show
,
Read
,
Enum
,
Bounded
)
instance
ToJSON
ListType
...
...
@@ -81,7 +81,11 @@ listTypeId CandidateTerm = 1
listTypeId
MapTerm
=
2
fromListTypeId
::
ListTypeId
->
Maybe
ListType
fromListTypeId
i
=
lookup
i
$
fromList
[
(
listTypeId
l
,
l
)
|
l
<-
[
minBound
..
maxBound
]]
fromListTypeId
i
=
lookup
i
$
fromList
[
(
listTypeId
l
,
l
)
|
l
<-
[
StopTerm
,
CandidateTerm
,
MapTerm
]
]
-- data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
-- | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
...
...
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