Skip to content

Commit 8ac9017

Browse files
authored
Merge pull request #23 from gdalle/master
Harmonize code and improve docs
2 parents 307fe68 + a868f25 commit 8ac9017

18 files changed

+599
-467
lines changed

Project.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
name = "MetaGraphsNext"
22
uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
3-
version = "0.2"
3+
version = "0.2.0"
44

55
[deps]
6-
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
76
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
7+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
88

99
[compat]
10-
JLD2 = "0.1.11, 0.2, 0.3, 0.4"
1110
Graphs = "1.4.1"
11+
JLD2 = "0.1.11, 0.2, 0.3, 0.4"
1212
julia = "1"
1313

1414
[extras]
1515
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
16+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1617

1718
[targets]
18-
test = ["Documenter"]
19+
test = ["Documenter", "Test"]

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# MetaGraphsNext
22

33
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaGraphs.github.io/MetaGraphsNext.jl/dev)
4+
[![Build Status](https://github.com/JuliaGraphs/MetaGraphsNext.jl/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/JuliaGraphs/MetaGraphsNext.jl/actions/workflows/test.yml?query=branch%3Amaster)
45
[![CodeCov](https://codecov.io/gh/JuliaGraphs/MetaGraphsNext.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaGraphs/MetaGraphsNext.jl)
56

6-
Welcome to `MetaGraphsNext.jl`, an experimental, type-stable replacement for [MetaGraphs](https://github.com/JuliaGraphs/MetaGraphs.jl).
7-
8-
## Getting started
9-
10-
To see how the package works, take a look at the tutorial in the [documentation](https://juliagraphs.org/MetaGraphsNext.jl/dev/). We first explain [the basics](tutorial_basics.md) of the `MetaGraph` structure, before moving on to its [integration](tutorial_graphs.md) with `Graphs.jl`.
7+
Welcome to MetaGraphsNext, an experimental, type-stable replacement for [MetaGraphs](https://github.com/JuliaGraphs/MetaGraphs.jl). This package will let you store metadata on the vertices and edges of your graphs. Take a look at the [documentation](https://juliagraphs.org/MetaGraphsNext.jl/dev/) to learn more!

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"

docs/src/api.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
11
# API reference
22

3-
## Basics
3+
## Docstrings
44

55
```@autodocs
66
Modules = [MetaGraphsNext]
7-
Pages = ["metagraph.jl"]
87
```
98

10-
```@autodocs
11-
Modules = [MetaGraphsNext]
12-
Pages = ["metaundigraph.jl", "metadigraph.jl"]
13-
```
14-
15-
```@autodocs
16-
Modules = [MetaGraphsNext]
17-
Pages = ["dict_utils.jl"]
18-
```
19-
20-
```@autodocs
21-
Modules = [MetaGraphsNext]
22-
Pages = ["weights.jl"]
23-
```
9+
## Index
2410

25-
## Graphs.jl interface
26-
27-
```@autodocs
28-
Modules = [MetaGraphsNext]
29-
Pages = ["graphs.jl"]
30-
```
31-
32-
```@autodocs
33-
Modules = [MetaGraphsNext]
34-
Pages = ["overrides.jl"]
35-
```
36-
37-
## Reading / writing
38-
39-
```@autodocs
11+
```@index
4012
Modules = [MetaGraphsNext]
41-
Pages = ["persistence.jl"]
4213
```

docs/src/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Welcome to `MetaGraphsNext.jl`, an experimental, type-stable replacement for [Me
44

55
## Getting started
66

7-
To see how the package works, take a look at the tutorial. We first explain [the basics](tutorial_basics.md) of the `MetaGraph` structure, before moving on to its [integration](tutorial_graphs.md) with `Graphs.jl`.
7+
To install the package, open the Julia REPL and type
88

9-
## Index
10-
11-
```@index
12-
Modules = [MetaGraphsNext]
9+
```julia
10+
julia> using Pkg; Pkg.add("MetaGraphsNext")
1311
```
12+
13+
The tutorial provides an overview of the functionalities. We first explain the [basics](tutorial_basics.md) of the `MetaGraph` structure, before moving on to its [integration](tutorial_graphs.md) with `Graphs.jl`.

docs/src/tutorial_basics.md

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,127 +11,133 @@ julia> using MetaGraphsNext
1111
We provide a default constructor in which you only need to specify types:
1212

1313
```jldoctest example
14-
julia> colors = MetaGraph(Graph(), VertexMeta = String, EdgeMeta = Symbol, gprops = "special")
15-
Meta graph based on a {0, 0} undirected simple Int64 graph with vertices indexed by Symbol(s), String(s) vertex metadata, Symbol(s) edge metadata, "special" as graph metadata, and default weight 1.0
14+
julia> colors = MetaGraph( Graph(), VertexData = String, EdgeData = Symbol, graph_data = "graph_of_colors")
15+
Meta graph based on a {0, 0} undirected simple Int64 graph with vertex labels of type Symbol, vertex metadata of type String, edge metadata of type Symbol, graph metadata given by "graph_of_colors", and default weight 1.0
1616
```
1717

18-
## Adding and modifying vertices
18+
## Modifying the graph
1919

20-
Use `setindex!` (as you would do with a dictionary) to add a new vertex with the given metadata. If a vertex with the given label does not exist, it will be created automatically. Otherwise, `setindex!` will modify the metadata for the existing vertex.
20+
Modifications of graph elements and the associated metadata can always be done using `setindex!` (as in a dictionary) with the relevant labels.
21+
22+
### Vertices
23+
24+
Use `setindex!` with one key to add a new vertex with the given label and metadata. If a vertex with the given label does not exist, it will be created automatically. Otherwise, the function will simply modify the metadata for the existing vertex.
2125

2226
```jldoctest example
2327
julia> colors[:red] = "warm";
2428
2529
julia> colors[:yellow] = "warm";
2630
31+
julia> colors[:blue] = "warm"; # wrong metadata
32+
2733
julia> colors[:blue] = "cool";
2834
```
2935

30-
## Using vertex codes
36+
### Edges
3137

32-
In the absence of removal, vertex codes correspond to order of insertion in the underlying graph:
38+
Use `setindex!` with two keys to add a new edge between the given labels and containing the given metadata. Beware that this time, nonexistent labels will throw an error.
3339

3440
```jldoctest example
35-
julia> code_for(colors, :red)
36-
1
41+
julia> colors[:red, :yellow] = :orange;
3742
38-
julia> code_for(colors, :blue)
39-
3
43+
julia> colors[:red, :blue] = :violet;
44+
45+
julia> colors[:yellow, :blue] = :green;
4046
```
4147

42-
You can retrieve the associated labels as follows:
48+
## Accessing graph properties
49+
50+
To retrieve graph properties, we still follow a dictionary-like interface based on labels.
51+
52+
### Existence
53+
54+
To check the presence of a vertex or edge, use `haskey`:
4355

4456
```jldoctest example
45-
julia> label_for(colors, 1)
46-
:red
57+
julia> haskey(colors, :red)
58+
true
4759
48-
julia> label_for(colors, 3)
49-
:blue
60+
julia> haskey(colors, :black)
61+
false
62+
63+
julia> haskey(colors, :red, :yellow) && haskey(colors, :yellow, :red)
64+
true
65+
66+
julia> haskey(colors, :red, :black)
67+
false
5068
```
5169

52-
## Accessing metadata
70+
### Metadata
5371

54-
You can access and change the metadata using indexing: zero arguments for graph metadata, one label for vertex metadata, and two labels for edge metadata.
72+
All kinds of metadata can be accessed with `getindex`:
5573

5674
```jldoctest example
5775
julia> colors[]
58-
"special"
59-
60-
julia> colors[:blue] = "very cool";
76+
"graph_of_colors"
6177
6278
julia> colors[:blue]
63-
"very cool"
79+
"cool"
6480
65-
julia> colors[:red, :yellow] = :orange;
66-
67-
julia> colors[:red, :yellow]
68-
:orange
81+
julia> colors[:yellow, :blue]
82+
:green
6983
```
7084

71-
Checking the presence of a vertex or edge can be done with `haskey`:
72-
73-
```jldoctest example
74-
julia> haskey(colors, :red)
75-
true
76-
77-
julia> haskey(colors, :green)
78-
false
85+
## Using vertex codes
7986

80-
julia> haskey(colors, :red, :yellow)
81-
true
87+
In the absence of removal, vertex codes correspond to order of insertion in the underlying graph:
8288

83-
julia> haskey(colors, :yellow, :red) # undirected graph, so vertex order doesn't matter
84-
true
89+
```jldoctest example
90+
julia> code_for(colors, :red)
91+
1
8592
86-
julia> haskey(colors, :red, :green)
87-
false
93+
julia> code_for(colors, :blue)
94+
3
8895
```
8996

90-
## Deleting vertices and edges
91-
92-
You can delete vertices and edges with `delete!`.
97+
You can retrieve the associated labels as follows:
9398

9499
```jldoctest example
95-
julia> delete!(colors, :red, :yellow);
100+
julia> label_for(colors, 1)
101+
:red
96102
97-
julia> delete!(colors, :blue);
103+
julia> label_for(colors, 3)
104+
:blue
98105
```
99106

100107
## Adding weights
101108

102109
The most simple way to add edge weights is to speficy a default weight for all of them.
103110

104111
```jldoctest example
105-
julia> defaultweight(MetaGraph(Graph(), defaultweight = 2))
112+
julia> weighted_default = MetaGraph(Graph(), default_weight = 2);
113+
114+
julia> default_weight(weighted_default)
106115
2
107116
108-
julia> weighttype(MetaGraph(Graph(), defaultweight = 2))
117+
julia> weighttype(weighted_default)
109118
Int64
110119
```
111120

112-
You can use the `weightfunction` keyword to specify a function which will
113-
transform edge metadata into a weight. This weight must always be the same
114-
type as the `defaultweight`.
121+
You can use the `weight_function` keyword to specify a function which will transform edge metadata into a weight. This weight must always be the same type as the `default_weight`.
115122

116123
```jldoctest example
117-
julia> weighted = MetaGraph(Graph(), EdgeMeta = Float64, weightfunction = identity);
124+
julia> weighted = MetaGraph(Graph(), EdgeData = Float64, weight_function = identity);
118125
119126
julia> weighted[:red] = nothing; weighted[:blue] = nothing; weighted[:yellow] = nothing;
120127
121128
julia> weighted[:red, :blue] = 1.0; weighted[:blue, :yellow] = 2.0;
122129
123-
julia> the_weights = Graphs.weights(weighted)
124-
metaweights
130+
julia> weight_matrix = Graphs.weights(weighted)
131+
MetaWeights of size (3, 3)
125132
126-
julia> size(the_weights)
133+
julia> size(weight_matrix)
127134
(3, 3)
128135
129-
julia> the_weights[1, 3]
136+
julia> weight_matrix[1, 3]
130137
1.0
131138
132-
julia> diameter(weighted)
133-
3.0
134-
135-
julia> weightfunction(weighted)(0)
139+
julia> weight_function(weighted)(0)
136140
0
137-
```
141+
```
142+
143+
You can then use all functions from Graphs.jl that require weighted graphs (see the rest of the tutorial).

docs/src/tutorial_files.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ graph T {
2424
}
2525
2626
julia> complicated = MetaGraph(DiGraph(),
27-
VertexMeta = Dict{Symbol, Int},
28-
EdgeMeta = Dict{Symbol, Int},
29-
gprops = (tagged = true,)
27+
VertexData = Dict{Symbol, Int},
28+
EdgeData = Dict{Symbol, Int},
29+
graph_data = (tagged = true,)
3030
);
3131
3232
julia> complicated[:a] = Dict(:code_1 => 1, :code_2 => 2);
@@ -57,4 +57,4 @@ julia> mktemp() do file, io
5757
loadgraph(file, "something", MGFormat()) == example
5858
end
5959
true
60-
```
60+
```

0 commit comments

Comments
 (0)