Skip to content

Commit 5e6207f

Browse files
authored
Merge pull request #17 from simonschoelly/split_into_submodules
Split GraphIO into submodules
2 parents 5678e32 + 577c444 commit 5e6207f

File tree

25 files changed

+358
-251
lines changed

25 files changed

+358
-251
lines changed

REQUIRE

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
julia 0.7
2-
LightGraphs 0.9.5
3-
EzXML 0.9.0
4-
ParserCombinator 2.0.0
5-
#JLD
2+
LightGraphs 1.1.0
63
SimpleTraits
7-
CodecZlib
4+
Requires

src/cdf.jl renamed to src/CDF/Cdf.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
module CDF
2+
13
# loads a graph from a IEEE CDF file.
24
# http://www2.ee.washington.edu/research/pstca/formats/cdf.txt
35
# http://www2.ee.washington.edu/research/pstca/pf30/ieee30cdf.txt
46

7+
using LightGraphs
8+
using LightGraphs: AbstractGraphFormat
9+
10+
import LightGraphs: loadgraph, loadgraphs, savegraph
11+
12+
export CDFFormat
13+
14+
515
struct CDFFormat <: AbstractGraphFormat end
616

717
function _loadcdf(io::IO)
@@ -45,3 +55,5 @@ end
4555
loadcdf(io::IO, gname::String) = _loadcdf(io)
4656
loadgraph(io::IO, gname::String, ::CDFFormat) = loadcdf(io, gname)
4757
loadgraphs(io::IO, ::CDFFormat) = Dict("graph" => loadcdf(io, "graph"))
58+
59+
end # module
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
module DOT
2+
3+
using GraphIO.ParserCombinator.Parsers
4+
using LightGraphs
5+
using LightGraphs: AbstractGraphFormat
6+
7+
import LightGraphs: loadgraph, loadgraphs
8+
9+
export DOTFormat
110

211
struct DOTFormat <: AbstractGraphFormat end
312
# TODO: implement save
413

5-
function _dot_read_one_graph(pg::DOT.Graph)
14+
function _dot_read_one_graph(pg::Parsers.DOT.Graph)
615
isdir = pg.directed
7-
nvg = length(DOT.nodes(pg))
8-
nodedict = Dict(zip(collect(DOT.nodes(pg)), 1:nvg))
16+
nvg = length(Parsers.DOT.nodes(pg))
17+
nodedict = Dict(zip(collect(Parsers.DOT.nodes(pg)), 1:nvg))
918
if isdir
1019
g = LightGraphs.DiGraph(nvg)
1120
else
1221
g = LightGraphs.Graph(nvg)
1322
end
14-
for es in DOT.edges(pg)
23+
for es in Parsers.DOT.edges(pg)
1524
s = nodedict[es[1]]
1625
d = nodedict[es[2]]
1726
add_edge!(g, s, d)
@@ -20,24 +29,24 @@ function _dot_read_one_graph(pg::DOT.Graph)
2029
end
2130

2231
function loaddot(io::IO, gname::String)
23-
p = DOT.parse_dot(read(io, String))
32+
p = Parsers.DOT.parse_dot(read(io, String))
2433
for pg in p
2534
isdir = pg.directed
26-
possname = isdir ? DOT.StringID("digraph") : DOT.StringID("graph")
35+
possname = isdir ? Parsers.DOT.StringID("digraph") : Parsers.DOT.StringID("graph")
2736
name = get(pg.id, possname).id
2837
name == gname && return _dot_read_one_graph(pg)
2938
end
3039
error("Graph $gname not found")
3140
end
3241

3342
function loaddot_mult(io::IO)
34-
p = DOT.parse_dot(read(io, String))
43+
p = Parsers.DOT.parse_dot(read(io, String))
3544

36-
graphs = Dict{String,LightGraphs.AbstractGraph}()
45+
graphs = Dict{String,AbstractGraph}()
3746

3847
for pg in p
3948
isdir = pg.directed
40-
possname = isdir ? DOT.StringID("digraph") : DOT.StringID("graph")
49+
possname = isdir ? Parsers.DOT.StringID("digraph") : Parsers.DOT.StringID("graph")
4150
name = get(pg.id, possname).id
4251
graphs[name] = _dot_read_one_graph(pg)
4352
end
@@ -46,3 +55,5 @@ end
4655

4756
loadgraph(io::IO, gname::String, ::DOTFormat) = loaddot(io, gname)
4857
loadgraphs(io::IO, ::DOTFormat) = loaddot_mult(io)
58+
59+
end #module

src/edgelist.jl renamed to src/Edgelist/Edgelist.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
module EdgeList
2+
13
# loads a graph from an edge list format (list of srcs and dsts separated
24
# by commas or whitespace. Will only read the first two elements on
35
# each line. Will return a directed graph.
46

57
using DelimitedFiles: writedlm
8+
using LightGraphs
9+
using LightGraphs: AbstractGraphFormat
10+
11+
import LightGraphs: loadgraph, loadgraphs, savegraph
12+
13+
export EdgeListFormat
14+
615

716
struct EdgeListFormat <: AbstractGraphFormat end
817

@@ -42,3 +51,5 @@ end
4251
loadgraph(io::IO, gname::String, ::EdgeListFormat) = loadedgelist(io, gname)
4352
loadgraphs(io::IO, ::EdgeListFormat) = Dict("graph" => loadedgelist(io, "graph"))
4453
savegraph(io::IO, g::AbstractGraph, gname::String, ::EdgeListFormat) = saveedgelist(io, g, gname)
54+
55+
end

src/gexf.jl renamed to src/GEXF/Gexf.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
module GEXF
2+
3+
using GraphIO.EzXML
4+
using LightGraphs
5+
using LightGraphs: AbstractGraph, AbstractGraphFormat
6+
7+
import LightGraphs: savegraph
8+
9+
export GEXFFormat
110

211
# TODO: implement readgexf
312
struct GEXFFormat <: AbstractGraphFormat end
@@ -42,3 +51,5 @@ function savegexf(io::IO, g::LightGraphs.AbstractGraph, gname::String)
4251
end
4352

4453
savegraph(io::IO, g::AbstractGraph, gname::String, ::GEXFFormat) = savegexf(io, g, gname)
54+
55+
end #module

src/gml.jl renamed to src/GML/Gml.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
module GML
2+
3+
using GraphIO.ParserCombinator.Parsers
4+
using LightGraphs
5+
using LightGraphs: AbstractGraphFormat
6+
7+
import LightGraphs: loadgraph, loadgraphs, savegraph
8+
9+
export GMLFormat
10+
11+
112
struct GMLFormat <: AbstractGraphFormat end
213

314
function _gml_read_one_graph(gs, dir)
@@ -19,7 +30,7 @@ function _gml_read_one_graph(gs, dir)
1930
end
2031

2132
function loadgml(io::IO, gname::String)
22-
p = GML.parse_dict(read(io, String))
33+
p = Parsers.GML.parse_dict(read(io, String))
2334
for gs in p[:graph]
2435
dir = Bool(get(gs, :directed, 0))
2536
graphname = get(gs, :label, dir ? "digraph" : "graph")
@@ -30,7 +41,7 @@ function loadgml(io::IO, gname::String)
3041
end
3142

3243
function loadgml_mult(io::IO)
33-
p = GML.parse_dict(read(io, String))
44+
p = Parsers.GML.parse_dict(read(io, String))
3445
graphs = Dict{String,LightGraphs.AbstractGraph}()
3546
for gs in p[:graph]
3647
dir = Bool(get(gs, :directed, 0))
@@ -85,3 +96,5 @@ loadgraph(io::IO, gname::String, ::GMLFormat) = loadgml(io, gname)
8596
loadgraphs(io::IO, ::GMLFormat) = loadgml_mult(io)
8697
savegraph(io::IO, g::AbstractGraph, gname::String, ::GMLFormat) = savegml(io, g, gname)
8798
savegraph(io::IO, d::Dict, ::GMLFormat) = savegml_mult(io, d)
99+
100+
end # module

src/graph6.jl renamed to src/Graph6/Graph6.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
module Graph6
2+
3+
using SimpleTraits
4+
using LightGraphs
5+
using LightGraphs: AbstractGraphFormat
6+
7+
import LightGraphs: loadgraph, loadgraphs, savegraph
8+
9+
export Graph6Format
10+
111
struct Graph6Format <: AbstractGraphFormat end
212

313
function _bv2int(x::BitVector)
@@ -158,3 +168,5 @@ loadgraph(io::IO, gname::String, ::Graph6Format) = loadgraph6(io, gname)
158168
loadgraphs(io::IO, ::Graph6Format) = loadgraph6_mult(io)
159169
savegraph(io::IO, g::AbstractGraph, gname::String, ::Graph6Format) = savegraph6(io, g, gname)
160170
savegraph(io::IO, d::Dict, ::Graph6Format) = savegraph6_mult(io, d)
171+
172+
end # module

src/GraphIO.jl

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
module GraphIO
22

3-
using LightGraphs
4-
using SimpleTraits
3+
using Requires
54

6-
import LightGraphs: loadgraph, loadgraphs, savegraph, AbstractGraphFormat
7-
using EzXML
8-
using ParserCombinator.Parsers.DOT
9-
using ParserCombinator.Parsers.GML
10-
using CodecZlib
5+
#=
6+
NOTE: This is a temporary fix until we can have multiple sub-packages with their own
7+
requirements in a single repository.
8+
=#
9+
function __init__()
10+
@require CodecZlib="944b1d66-785c-5afd-91f1-9de20f533193" begin
11+
include("LGCompressed/LGCompressed.jl")
12+
end
13+
@require EzXML="8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615" begin
14+
include("GEXF/Gexf.jl")
15+
include("GraphML/GraphML.jl")
16+
end
17+
@require ParserCombinator="fae87a5f-d1ad-5cf0-8f61-c941e1580b46" begin
18+
include("DOT/Dot.jl")
19+
include("GML/Gml.jl")
20+
end
21+
end
1122

12-
export DOTFormat, GEXFFormat, GMLFormat, Graph6Format,
13-
GraphMLFormat, NETFormat, EdgeListFormat, CDFFormat,
14-
LGCompressedFormat
15-
# package code goes here
1623

17-
#include("jld.jl")
18-
include("lgcompressed.jl")
19-
include("dot.jl")
20-
include("gexf.jl")
21-
include("gml.jl")
22-
include("graph6.jl")
23-
include("graphml.jl")
24-
include("net.jl")
25-
include("edgelist.jl")
26-
include("cdf.jl")
24+
include("Graph6/Graph6.jl")
25+
include("NET/Net.jl")
26+
include("Edgelist/Edgelist.jl")
27+
include("CDF/Cdf.jl")
28+
29+
include("deprecations.jl")
2730

2831
end # module

src/graphml.jl renamed to src/GraphML/GraphML.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
module GraphML
2+
3+
using GraphIO.EzXML
4+
using LightGraphs
5+
using LightGraphs: AbstractGraphFormat
6+
7+
import LightGraphs: loadgraph, loadgraphs, savegraph
8+
9+
export GraphMLFormat
10+
11+
112
# TODO: implement writing a dict of graphs
213

314
struct GraphMLFormat <: AbstractGraphFormat end
@@ -123,3 +134,5 @@ loadgraph(io::IO, gname::String, ::GraphMLFormat) = loadgraphml(io, gname)
123134
loadgraphs(io::IO, ::GraphMLFormat) = loadgraphml_mult(io)
124135
savegraph(io::IO, g::AbstractGraph, gname::String, ::GraphMLFormat) = savegraphml(io, g, gname)
125136
savegraph(io::IO, d::Dict, ::GraphMLFormat) = savegraphml_mult(io, d)
137+
138+
end # module

src/lgcompressed.jl renamed to src/LGCompressed/LGCompressed.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
module LGCompressed
2+
3+
using GraphIO.CodecZlib
4+
using LightGraphs
5+
using LightGraphs: AbstractGraphFormat
6+
7+
import LightGraphs: loadgraph, loadgraphs, savegraph
8+
9+
export LGCompressedFormat
10+
111
struct LGCompressedFormat <: AbstractGraphFormat end
212

313
function savegraph(fn::AbstractString, g::AbstractGraph, gname::AbstractString,
@@ -36,4 +46,6 @@ loadgraph(fn::AbstractString, gname::AbstractString, format::LGCompressedFormat)
3646

3747
loadgraph(fn::AbstractString, format::LGCompressedFormat) = loadgraph(fn, "graph", LightGraphs.LGFormat())
3848

39-
loadgraphs(fn::AbstractString, format::LGCompressedFormat) = loadgraphs(fn, LGFormat())
49+
loadgraphs(fn::AbstractString, format::LGCompressedFormat) = loadgraphs(fn, LGFormat())
50+
51+
end # module

src/net.jl renamed to src/NET/Net.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
module NET
2+
3+
import LightGraphs
4+
using LightGraphs
5+
using LightGraphs: AbstractGraphFormat
6+
7+
import LightGraphs: loadgraph, loadgraphs, savegraph
8+
9+
export NETFormat
10+
11+
112
struct NETFormat <: AbstractGraphFormat end
213
"""
314
savenet(io, g, gname="g")
@@ -19,7 +30,6 @@ function savenet(io::IO, g::LightGraphs.AbstractGraph, gname::String = "g")
1930
return 1
2031
end
2132

22-
2333
"""
2434
loadnet(io::IO, gname="graph")
2535
@@ -66,3 +76,5 @@ end
6676
loadgraph(io::IO, gname::String, ::NETFormat) = loadnet(io, gname)
6777
loadgraphs(io::IO, ::NETFormat) = Dict("graph" => loadnet(io, "graph"))
6878
savegraph(io::IO, g::AbstractGraph, gname::String, ::NETFormat) = savenet(io, g, gname)
79+
80+
end # module

0 commit comments

Comments
 (0)