Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clustering-louvain
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
gargantext
clustering-louvain
Commits
e59c3846
Commit
e59c3846
authored
Jul 27, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Separate function for clusters. Need to optimized.
parent
46c3bc54
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
9 deletions
+89
-9
louvain.cabal
louvain.cabal
+2
-1
GexfParser.hs
src/Data/GexfParser.hs
+80
-0
Louvain.hs
src/Data/Louvain.hs
+7
-2
Lib.hs
src/Lib.hs
+0
-6
No files found.
louvain.cabal
View file @
e59c3846
...
@@ -15,9 +15,10 @@ cabal-version: >=1.10
...
@@ -15,9 +15,10 @@ cabal-version: >=1.10
library
library
hs-source-dirs: src
hs-source-dirs: src
exposed-modules: Data.Louvain
exposed-modules: Data.Louvain
, Data.GexfParser
build-depends: base >= 4.7 && < 5
build-depends: base >= 4.7 && < 5
, fgl
, fgl
, hxt
default-language: Haskell2010
default-language: Haskell2010
-- executable louvain-exe
-- executable louvain-exe
...
...
src/Data/GexfParser.hs
0 → 100644
View file @
e59c3846
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
module
Data.GexfParser
where
import
Text.XML.HXT.Core
import
qualified
Data.Graph
as
DataGraph
import
qualified
Data.Graph.Inductive
as
FGL
import
System.Environment
(
getArgs
)
data
Graph
=
Graph
{
graphId
::
String
,
nodes
::
[
String
],
edges
::
[(
String
,
String
)]
-- (Source, target)
}
deriving
(
Show
,
Eq
)
atTag
tag
=
deep
(
isElem
>>>
hasName
tag
)
parseEdges
=
atTag
"edge"
>>>
proc
e
->
do
source
<-
getAttrValue
"source"
-<
e
target
<-
getAttrValue
"target"
-<
e
returnA
-<
(
source
,
target
)
parseNodes
=
atTag
"node"
>>>
proc
n
->
do
nodeId
<-
getAttrValue
"id"
-<
n
returnA
-<
nodeId
parseGraph
=
atTag
"graph"
>>>
proc
g
->
do
graphId
<-
getAttrValue
"id"
-<
g
nodes
<-
listA
parseNodes
-<
g
edges
<-
listA
parseEdges
-<
g
returnA
-<
Graph
{
graphId
=
graphId
,
nodes
=
nodes
,
edges
=
edges
}
getEdges
=
atTag
"edge"
>>>
getAttrValue
"source"
-- Get targets for a single node in a Graph
getTargets
::
String
->
Graph
->
[
String
]
getTargets
source
graph
=
map
snd
$
filter
((
==
source
)
.
fst
)
$
edges
graph
-- Convert a graph node into a Data.Graph-usable
getDataGraphNode
::
Graph
->
String
->
(
String
,
String
,
[
String
])
getDataGraphNode
graph
node
=
(
node
,
node
,
getTargets
node
graph
)
getDataGraphNode'
::
Graph
->
String
->
(
Int
,
[
Int
])
getDataGraphNode'
graph
node
=
(
read
node
,
Prelude
.
map
read
(
getTargets
node
graph
))
-- Convert a Graph instance into a Data.Graph list of (node, nodeid, edge) tuples
getDataGraphNodeList
::
Graph
->
[(
String
,
String
,
[
String
])]
getDataGraphNodeList
graph
=
map
(
getDataGraphNode
graph
)
(
nodes
graph
)
getDataGraphNodeList'
::
Graph
->
[(
Int
,
[
Int
])]
getDataGraphNodeList'
graph
=
map
(
getDataGraphNode'
graph
)
(
nodes
graph
)
-- Convert Graph structure to Data.Graph-importable tuple list
importGraph
::
FilePath
->
IO
[(
Int
,
[
Int
])]
importGraph
file
=
do
graphs
<-
runX
(
readDocument
[
withValidate
no
]
file
>>>
parseGraph
)
let
graphEdges
=
getDataGraphNodeList'
$
head
graphs
return
graphEdges
--importGraph' :: FilePath -> IO [(Int, [Int])]
importGraph'
file
=
runX
(
readDocument
[
withValidate
no
]
file
>>>
parseGraph
)
importGraph''
::
FilePath
->
IO
[
FGL
.
LEdge
Double
]
importGraph''
file
=
Prelude
.
map
(
\
(
a
,
b
)
->
(
read
a
,
read
b
,
1
))
<$>
edges
<$>
head
<$>
importGraph'
file
--main :: IO()
main
=
do
[
file
]
<-
getArgs
importGraph
file
>>=
print
-- Convert to a Data.Graph
-- let (graph, vertexMap) = DataGraph.graphFromEdges' graphEdges
-- Example of what to do with the Graph: Print vertices
-- print $ map ((\ (vid, _, _) -> vid) . vertexMap) (DataGraph.vertices graph)
src/Data/Louvain.hs
View file @
e59c3846
...
@@ -20,7 +20,6 @@ mkGraph' es = mkGraph ns es
...
@@ -20,7 +20,6 @@ mkGraph' es = mkGraph ns es
where
ns'
=
S
.
toList
.
S
.
fromList
$
concat
(
Prelude
.
map
edge2nodes
es
)
where
ns'
=
S
.
toList
.
S
.
fromList
$
concat
(
Prelude
.
map
edge2nodes
es
)
edge2nodes
::
LEdge
b
->
[
Node
]
edge2nodes
::
LEdge
b
->
[
Node
]
edge2nodes
(
a
,
b
,
_
)
=
[
a
,
b
]
edge2nodes
(
a
,
b
,
_
)
=
[
a
,
b
]
...
@@ -121,8 +120,14 @@ separate (x:xs) = let recur = separate xs
...
@@ -121,8 +120,14 @@ separate (x:xs) = let recur = separate xs
return
$
(
x
:
y
)
:
ys
return
$
(
x
:
y
)
:
ys
in
split
++
noSplit
in
split
++
noSplit
separate'
xs
=
[
takeDrop
t
(
rotate
r
xs
)
|
t
<-
[
1
..
fromIntegral
(
length
xs
)
-
1
]
,
r
<-
[
0
..
fromIntegral
(
length
xs
)
]
]
gpartition
::
DynGraph
gr
=>
gr
a
b
->
[[[
Node
]]]
gpartition
::
DynGraph
gr
=>
gr
a
b
->
[[[
Node
]]]
gpartition
gr
=
separate
(
nodes
gr
)
gpartition
gr
=
separate
'
(
nodes
gr
)
modularities
::
DynGraph
gr
=>
gr
a
b
->
[[
Node
]]
->
Double
modularities
::
DynGraph
gr
=>
gr
a
b
->
[[
Node
]]
->
Double
modularities
gr
xs
=
sum
$
Prelude
.
map
(
\
y
->
modularity
gr
y
)
xs
modularities
gr
xs
=
sum
$
Prelude
.
map
(
\
y
->
modularity
gr
y
)
xs
...
...
src/Lib.hs
deleted
100644 → 0
View file @
46c3bc54
module
Lib
(
someFunc
)
where
someFunc
::
IO
()
someFunc
=
putStrLn
"someFunc"
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