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
158
Issues
158
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
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
ac45aebc
Commit
ac45aebc
authored
Nov 20, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Types] organization, using more Lenses
parent
b9de7802
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
33 deletions
+42
-33
Prelude.hs
src/Gargantext/Core/Text/List/Group/Prelude.hs
+10
-10
WithScores.hs
src/Gargantext/Core/Text/List/Group/WithScores.hs
+19
-10
Prelude.hs
src/Gargantext/Core/Text/List/Social/Prelude.hs
+6
-4
Scores.hs
src/Gargantext/Core/Text/List/Social/Scores.hs
+7
-9
No files found.
src/Gargantext/Core/Text/List/Group/Prelude.hs
View file @
ac45aebc
...
@@ -14,18 +14,14 @@ Portability : POSIX
...
@@ -14,18 +14,14 @@ Portability : POSIX
module
Gargantext.Core.Text.List.Group.Prelude
module
Gargantext.Core.Text.List.Group.Prelude
where
where
import
Control.Lens
(
makeLenses
,
view
,
set
)
import
Control.Lens
(
makeLenses
)
import
Data.Monoid
import
Data.Semigroup
import
Data.Semigroup
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
import
Data.Map
(
Map
)
import
Data.Maybe
(
catMaybes
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.Core.Types
(
ListType
(
..
))
import
Gargantext.Core.Types
(
ListType
(
..
))
import
Gargantext.Database.Admin.Types.Node
(
NodeId
)
import
Gargantext.Core.Text.List.Social.Prelude
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Data.Set
as
Set
import
qualified
Data.Set
as
Set
import
qualified
Data.Map
as
Map
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Group With Scores Main Types
-- | Group With Scores Main Types
...
@@ -33,8 +29,8 @@ import qualified Data.Map as Map
...
@@ -33,8 +29,8 @@ import qualified Data.Map as Map
-- Target : type FlowCont Text GroupedTextScores'
-- Target : type FlowCont Text GroupedTextScores'
data
GroupedTextScores'
score
=
data
GroupedTextScores'
score
=
GroupedTextScores'
{
_gts'_listType
::
!
(
Maybe
ListType
)
GroupedTextScores'
{
_gts'_listType
::
!
(
Maybe
ListType
)
,
_gts'_score
::
score
,
_gts'_children
::
!
(
Set
(
GroupedTextScores'
score
))
,
_gts'_children
::
!
(
Set
(
GroupedTextScores'
score
))
,
_gts'_score
::
score
}
deriving
(
Show
,
Ord
,
Eq
)
}
deriving
(
Show
,
Ord
,
Eq
)
makeLenses
'G
r
oupedTextScores'
makeLenses
'G
r
oupedTextScores'
instance
(
Semigroup
a
,
Ord
a
)
=>
Semigroup
(
GroupedTextScores'
a
)
where
instance
(
Semigroup
a
,
Ord
a
)
=>
Semigroup
(
GroupedTextScores'
a
)
where
...
@@ -45,8 +41,8 @@ instance (Semigroup a, Ord a) => Semigroup (GroupedTextScores' a) where
...
@@ -45,8 +41,8 @@ instance (Semigroup a, Ord a) => Semigroup (GroupedTextScores' a) where
-- | Intermediary Type
-- | Intermediary Type
data
GroupedWithListScores
=
data
GroupedWithListScores
=
GroupedWithListScores
{
_gwls_
children
::
!
(
Set
Text
)
GroupedWithListScores
{
_gwls_
listType
::
!
(
Maybe
ListType
)
,
_gwls_
listType
::
!
(
Maybe
ListType
)
,
_gwls_
children
::
!
(
Set
Text
)
}
deriving
(
Show
)
}
deriving
(
Show
)
makeLenses
''
G
roupedWithListScores
makeLenses
''
G
roupedWithListScores
instance
Semigroup
GroupedWithListScores
where
instance
Semigroup
GroupedWithListScores
where
...
@@ -55,5 +51,9 @@ instance Semigroup GroupedWithListScores where
...
@@ -55,5 +51,9 @@ instance Semigroup GroupedWithListScores where
GroupedWithListScores
(
c1
<>
c2
)
GroupedWithListScores
(
c1
<>
c2
)
(
l1
<>
l2
)
(
l1
<>
l2
)
instance
Monoid
GroupedWithListScores
where
mempty
=
GroupedWithListScores
Nothing
Set
.
empty
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Group With Stem Main Types
-- | Group With Stem Main Types
src/Gargantext/Core/Text/List/Group/WithScores.hs
View file @
ac45aebc
...
@@ -18,6 +18,7 @@ import Control.Lens (makeLenses, view, set)
...
@@ -18,6 +18,7 @@ import Control.Lens (makeLenses, view, set)
import
Data.Semigroup
import
Data.Semigroup
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
import
Data.Map
(
Map
)
import
Data.Map
(
Map
)
import
Data.Monoid
(
mempty
)
import
Data.Maybe
(
catMaybes
)
import
Data.Maybe
(
catMaybes
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.Core.Types
(
ListType
(
..
))
import
Gargantext.Core.Types
(
ListType
(
..
))
...
@@ -29,22 +30,26 @@ import qualified Data.Set as Set
...
@@ -29,22 +30,26 @@ import qualified Data.Set as Set
import
qualified
Data.Map
as
Map
import
qualified
Data.Map
as
Map
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Main function
-- | Main function
groupWithScores'
::
FlowCont
Text
FlowListScores
groupWithScores'
::
FlowCont
Text
FlowListScores
->
(
Text
->
Set
NodeId
)
-- Map Text (Set NodeId)
->
(
Text
->
Set
NodeId
)
-- Map Text (Set NodeId)
->
FlowCont
Text
(
GroupedTextScores'
(
Set
NodeId
))
->
FlowCont
Text
(
GroupedTextScores'
(
Set
NodeId
))
groupWithScores'
flc
scores
=
FlowCont
groups
orphans
groupWithScores'
flc
_
scores
=
FlowCont
groups
orphans
where
where
groups
=
toGroupedTextScores'
$
view
flc_scores
flc
groups
=
toGroupedTextScores'
$
view
flc_scores
flc
orphans
=
(
view
flc_cont
flc
)
-- parent/child relation is inherited from social lists
orphans
=
(
view
flc_cont
flc
)
-- orphans have been filtered already
------------------------------------------------------------------------
------------------------------------------------------------------------
toGroupedTextScores'
::
Map
Text
FlowListScores
toGroupedTextScores'
::
Map
Text
FlowListScores
->
Map
Parent
(
GroupedTextScores'
(
Set
NodeId
))
->
Map
Parent
(
GroupedTextScores'
(
Set
NodeId
))
toGroupedTextScores'
=
toGroupedScores'
.
fromListScores'
toGroupedTextScores'
=
toGroupedScores'
.
fromListScores'
------------------------------------------------------------------------
------------------------------------------------------------------------
fromListScores'
::
Map
Text
FlowListScores
fromListScores'
::
Map
Text
FlowListScores
->
Map
Parent
GroupedWithListScores
->
Map
Parent
GroupedWithListScores
...
@@ -52,18 +57,22 @@ fromListScores' = Map.fromListWith (<>) . (map fromScores') . Map.toList
...
@@ -52,18 +57,22 @@ fromListScores' = Map.fromListWith (<>) . (map fromScores') . Map.toList
where
where
fromScores'
::
(
Text
,
FlowListScores
)
->
(
Text
,
GroupedWithListScores
)
fromScores'
::
(
Text
,
FlowListScores
)
->
(
Text
,
GroupedWithListScores
)
fromScores'
(
t
,
fs
)
=
case
(
keyWithMaxValue
$
view
fls_parents
fs
)
of
fromScores'
(
t
,
fs
)
=
case
(
keyWithMaxValue
$
view
fls_parents
fs
)
of
Nothing
->
(
t
,
GroupedWithListScores
Set
.
empty
(
keyWithMaxValue
$
view
fls_listType
fs
))
Nothing
->
(
t
,
set
gwls_listType
(
keyWithMaxValue
$
view
fls_listType
fs
)
mempty
)
-- Parent case: taking its listType, for now children Set is empty
-- Parent case: taking its listType, for now children Set is empty
Just
parent
->
(
parent
,
GroupedWithListScores
(
Set
.
singleton
t
)
Nothing
)
Just
parent
->
(
parent
,
set
gwls_children
(
Set
.
singleton
t
)
mempty
)
-- We ignore the ListType of children for the parents' one
-- We ignore the ListType of children for the parents' one
-- added after and winner of semigroup actions
-- added after and winner of semigroup actions
toGroupedScores'
::
Map
Parent
GroupedWithListScores
toGroupedScores'
::
Map
Parent
GroupedWithListScores
->
Map
Parent
(
GroupedTextScores'
(
Set
NodeId
))
->
Map
Parent
(
GroupedTextScores'
(
Set
NodeId
))
toGroupedScores'
=
undefined
-- Map.map (\(GroupedWithListScores c l) -> GroupedTextScores l Set.empty c)
toGroupedScores'
=
undefined
-- Map.map (\(GroupedWithListScores c l) -> GroupedTextScores l Set.empty c)
-- toGroupedTree :: GroupedW
...
@@ -133,7 +142,7 @@ addIfNotExist mapSocialScores mapScores =
...
@@ -133,7 +142,7 @@ addIfNotExist mapSocialScores mapScores =
------------------------------------------------------------------------
------------------------------------------------------------------------
fromGroupedScores
::
Map
Parent
GroupedWithListScores
fromGroupedScores
::
Map
Parent
GroupedWithListScores
->
Map
Parent
(
GroupedTextScores
(
Set
NodeId
))
->
Map
Parent
(
GroupedTextScores
(
Set
NodeId
))
fromGroupedScores
=
Map
.
map
(
\
(
GroupedWithListScores
c
l
)
->
GroupedTextScores
l
Set
.
empty
c
)
fromGroupedScores
=
Map
.
map
(
\
(
GroupedWithListScores
l
c
)
->
GroupedTextScores
l
Set
.
empty
c
)
------------------------------------------------------------------------
------------------------------------------------------------------------
fromListScores
::
Map
Text
FlowListScores
->
Map
Parent
GroupedWithListScores
fromListScores
::
Map
Text
FlowListScores
->
Map
Parent
GroupedWithListScores
...
@@ -141,10 +150,10 @@ fromListScores = Map.fromListWith (<>) . (map fromScores') . Map.toList
...
@@ -141,10 +150,10 @@ fromListScores = Map.fromListWith (<>) . (map fromScores') . Map.toList
where
where
fromScores'
::
(
Text
,
FlowListScores
)
->
(
Text
,
GroupedWithListScores
)
fromScores'
::
(
Text
,
FlowListScores
)
->
(
Text
,
GroupedWithListScores
)
fromScores'
(
t
,
fs
)
=
case
(
keyWithMaxValue
$
view
fls_parents
fs
)
of
fromScores'
(
t
,
fs
)
=
case
(
keyWithMaxValue
$
view
fls_parents
fs
)
of
Nothing
->
(
t
,
GroupedWithListScores
Set
.
empty
(
keyWithMaxValue
$
view
fls_listType
fs
)
)
Nothing
->
(
t
,
set
gwls_listType
(
keyWithMaxValue
$
view
fls_listType
fs
)
mempty
)
-- Parent case: taking its listType, for now children Set is empty
-- Parent case: taking its listType, for now children Set is empty
Just
parent
->
(
parent
,
GroupedWithListScores
(
Set
.
singleton
t
)
Nothing
)
Just
parent
->
(
parent
,
set
gwls_children
(
Set
.
singleton
t
)
mempty
)
-- We ignore the ListType of children for the parents' one
-- We ignore the ListType of children for the parents' one
-- added after and winner of semigroup actions
-- added after and winner of semigroup actions
...
...
src/Gargantext/Core/Text/List/Social/Prelude.hs
View file @
ac45aebc
...
@@ -37,8 +37,8 @@ type Parent = Text
...
@@ -37,8 +37,8 @@ type Parent = Text
-- | DataType inspired by continuation Monad (but simpler)
-- | DataType inspired by continuation Monad (but simpler)
data
FlowCont
a
b
=
data
FlowCont
a
b
=
FlowCont
{
_flc_scores
::
Map
a
b
FlowCont
{
_flc_scores
::
Map
a
b
,
_flc_cont
::
Set
a
,
_flc_cont
::
Set
a
}
}
instance
Ord
a
=>
Monoid
(
FlowCont
a
b
)
where
instance
Ord
a
=>
Monoid
(
FlowCont
a
b
)
where
mempty
=
FlowCont
Map
.
empty
Set
.
empty
mempty
=
FlowCont
Map
.
empty
Set
.
empty
...
@@ -55,8 +55,8 @@ instance (Eq a, Ord a) => Semigroup (FlowCont a b) where
...
@@ -55,8 +55,8 @@ instance (Eq a, Ord a) => Semigroup (FlowCont a b) where
-- | Datatype definition
-- | Datatype definition
data
FlowListScores
=
data
FlowListScores
=
FlowListScores
{
_fls_
parents
::
Map
Parent
Int
FlowListScores
{
_fls_
listType
::
Map
ListType
Int
,
_fls_
listType
::
Map
ListType
Int
,
_fls_
parents
::
Map
Parent
Int
-- You can add any score by incrementing this type
-- You can add any score by incrementing this type
-- , _flc_score :: Map Score Int
-- , _flc_score :: Map Score Int
}
}
...
@@ -78,6 +78,8 @@ instance Semigroup FlowListScores where
...
@@ -78,6 +78,8 @@ instance Semigroup FlowListScores where
FlowListScores
(
p1
<>
p2
)
FlowListScores
(
p1
<>
p2
)
(
l1
<>
l2
)
(
l1
<>
l2
)
instance
Monoid
FlowListScores
where
mempty
=
FlowListScores
Map
.
empty
Map
.
empty
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Tools to inherit groupings
-- | Tools to inherit groupings
...
...
src/Gargantext/Core/Text/List/Social/Scores.hs
View file @
ac45aebc
...
@@ -72,10 +72,10 @@ addList :: ListType
...
@@ -72,10 +72,10 @@ addList :: ListType
->
Maybe
FlowListScores
->
Maybe
FlowListScores
->
Maybe
FlowListScores
->
Maybe
FlowListScores
addList
l
Nothing
=
addList
l
Nothing
=
Just
$
FlowListScores
Map
.
empty
(
addListScore
l
Map
.
empty
)
Just
$
set
fls_listType
(
addListScore
l
Map
.
empty
)
mempty
addList
l
(
Just
(
FlowListScores
mapParent
mapList
)
)
=
addList
l
(
Just
fls
)
=
Just
$
FlowListScores
mapParent
(
addListScore
l
mapList
)
Just
$
over
fls_listType
(
addListScore
l
)
fls
-- * Unseful but nice comment:
-- * Unseful but nice comment:
-- "the addList function looks like an ASCII bird"
-- "the addList function looks like an ASCII bird"
...
@@ -101,14 +101,12 @@ addParent :: KeepAllParents -> NgramsRepoElement -> Set Text
...
@@ -101,14 +101,12 @@ addParent :: KeepAllParents -> NgramsRepoElement -> Set Text
->
Maybe
FlowListScores
->
Maybe
FlowListScores
addParent
k
nre
ss
Nothing
=
addParent
k
nre
ss
Nothing
=
Just
$
FlowListScores
mapParent
Map
.
empty
Just
$
FlowListScores
Map
.
empty
mapParent
where
where
mapParent
=
addParentScore
k
(
_
nre_parent
nre
)
ss
Map
.
empty
mapParent
=
addParentScore
k
(
view
nre_parent
nre
)
ss
Map
.
empty
addParent
k
nre
ss
(
Just
(
FlowListScores
mapParent
mapList
))
=
addParent
k
nre
ss
(
Just
fls
{-(FlowListScores mapList mapParent)-}
)
=
Just
$
FlowListScores
mapParent'
mapList
Just
$
over
fls_parents
(
addParentScore
k
(
view
nre_parent
nre
)
ss
)
fls
where
mapParent'
=
addParentScore
k
(
_nre_parent
nre
)
ss
mapParent
addParentScore
::
Num
a
addParentScore
::
Num
a
=>
KeepAllParents
=>
KeepAllParents
...
...
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