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
141
Issues
141
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
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
a4b448de
Commit
a4b448de
authored
Oct 13, 2022
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] need more optimization
parent
fa7344cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
11 deletions
+30
-11
Bridgeness.hs
src/Gargantext/Core/Viz/Graph/Bridgeness.hs
+30
-11
No files found.
src/Gargantext/Core/Viz/Graph/Bridgeness.hs
View file @
a4b448de
...
...
@@ -21,14 +21,16 @@ module Gargantext.Core.Viz.Graph.Bridgeness -- (bridgeness)
import
Data.List
(
concat
,
sortOn
)
import
Data.Map
(
Map
,
fromListWith
,
lookup
,
toList
,
mapWithKey
,
elems
)
import
Data.Maybe
(
catMaybes
{-, fromMaybe-}
)
import
Data.Maybe
(
catMaybes
,
fromMaybe
)
import
Data.Set
(
Set
)
import
Gargantext.Prelude
import
Graph.Types
(
ClusterNode
(
..
))
import
Data.Ord
(
Down
(
..
))
import
qualified
Data.List
as
List
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
import
Data.IntMap
(
IntMap
)
import
qualified
Data.IntMap
as
IntMap
import
qualified
Data.List
as
List
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
----------------------------------------------------------------------
type
Partitions
a
=
Map
(
Int
,
Int
)
Double
->
IO
[
a
]
...
...
@@ -53,29 +55,46 @@ bridgeness3 :: Confluence
->
Map
(
NodeId
,
NodeId
)
Double
bridgeness3
_
m
=
m
map2intMap
::
Map
(
Int
,
Int
)
a
->
IntMap
(
IntMap
a
)
map2intMap
m
=
IntMap
.
fromListWith
(
<>
)
$
map
(
\
((
k1
,
k2
),
v
)
->
if
k1
<
k2
then
(
k1
,
IntMap
.
singleton
k2
v
)
else
(
k2
,
IntMap
.
singleton
k1
v
)
)
$
Map
.
toList
m
look
::
(
Int
,
Int
)
->
IntMap
(
IntMap
a
)
->
Maybe
a
look
(
k1
,
k2
)
m
=
if
k1
>
k2
then
case
(
IntMap
.
lookup
k1
m
)
of
Just
m'
->
IntMap
.
lookup
k2
m'
_
->
Nothing
else
look
(
k2
,
k1
)
m
bridgeness2
::
Confluence
->
Map
(
NodeId
,
NodeId
)
Double
->
Map
(
NodeId
,
NodeId
)
Double
bridgeness2
c
m
=
Map
.
fromList
$
List
.
filter
(
\
((
k1
,
k2
),
_v
)
->
if
k1
>
k2
then
fromMaybe
False
(
Set
.
member
k2
<$>
Map
.
lookup
k1
toKeep
)
else
fromMaybe
False
(
Set
.
member
k1
<$>
Map
.
lookup
k2
toKeep
)
$
List
.
filter
(
\
((
k1
,
k2
),
_v
)
->
if
k1
<
k2
then
fromMaybe
False
(
Set
.
member
k2
<$>
Int
Map
.
lookup
k1
toKeep
)
else
fromMaybe
False
(
Set
.
member
k1
<$>
Int
Map
.
lookup
k2
toKeep
)
)
$
m'
where
toKeep
::
Map
NodeId
(
Set
NodeId
)
!
toKeep
=
Map
.
fromListWith
(
<>
)
$
map
(
\
((
k1
,
k2
),
_v
)
->
if
k1
>
k2
toKeep
::
IntMap
(
Set
NodeId
)
!
toKeep
=
Int
Map
.
fromListWith
(
<>
)
$
map
(
\
((
k1
,
k2
),
_v
)
->
if
k1
<
k2
then
(
k1
,
Set
.
singleton
k2
)
else
(
k2
,
Set
.
singleton
k1
)
)
$
List
.
take
n
$
List
.
sortOn
(
Down
.
snd
)
$
catMaybes
$
map
(
\
ks
->
(,)
<$>
Just
ks
<*>
Map
.
lookup
ks
c
)
$
map
(
\
ks
->
(,)
<$>
Just
ks
<*>
look
ks
c'
)
$
Map
.
keys
m
c'
=
map2intMap
c
!
m'
=
Map
.
toList
m
n
::
Int
!
n
=
round
$
(
fromIntegral
$
List
.
length
m'
)
/
(
2
::
Double
)
...
...
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