Skip to content

Commit 7d46471

Browse files
committed
Backward compability in JSON_Format and Tutorials updated
1 parent 6ff101f commit 7d46471

10 files changed

Lines changed: 2724 additions & 27728 deletions

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SimpleHypergraphs"
22
uuid = "aa4a32ff-dd5d-5357-90e3-e7a9512f0501"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
authors = ["Przemysław Szufel <pszufe@sgh.waw.pl>", "Bogumił Kamiński <bkamins@sgh.waw.pl>", "Carmine Spagnuolo <spagnuolocarmine@gmail.com>", "Alessia Antelmi <aless.antelmi@gmail.com>", "Evan Walter Clark Spotte-Smith <espottesmith@gmail.com>"]
55

66
[deps]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Antelmi, A., Cordasco, G., Kamiński, B., Prałat, P., Scarano, V., Spagnuolo, C
5252
The full paper is available at [https://doi.org/10.24166/im.01.2020](https://doi.org/10.24166/im.01.2020)
5353

5454
## Acknowledgement
55-
The research is financed by NAWA - The Polish National Agency for Academic Exchange.
56-
55+
- The research was initially financed by NAWA - The Polish National Agency for Academic Exchange.
56+
- The development of HIF standard format support for exchange of hypergraphs was financed by the National Science Centre (NCN), Poland (grant number: 2021/41/B/HS4/03349).
5757

5858
[docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg
5959
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
@@ -62,7 +62,7 @@ The research is financed by NAWA - The Polish National Agency for Academic Excha
6262
[tutorial-url]: https://nbviewer.jupyter.org/github/pszufe/SimpleHypergraphs.jl/blob/master/tutorials/basics/SimpleHypergraphs_tutorial_v4.ipynb
6363
[got-url]: https://nbviewer.jupyter.org/github/pszufe/SimpleHypergraphs.jl/blob/master/tutorials/basics/A%20case%20study%20-%20Game%20of%20Thrones.ipynb
6464

65-
[tutorial-raw]: https://github.com/pszufe/SimpleHypergraphs.jl/raw/master/tutorials/basics/SimpleHypergraphs_tutorial_v4.ipynb
65+
[tutorial-raw]: https://github.com/pszufe/SimpleHypergraphs.jl/raw/master/tutorials/basics/SimpleHypergraphs_tutorial_v5.ipynb
6666
[got-raw]: https://github.com/pszufe/SimpleHypergraphs.jl/raw/master/tutorials/basics/A%20case%20study%20-%20Game%20of%20Thrones.ipynb
6767

6868
[travis-img]: https://travis-ci.org/pszufe/SimpleHypergraphs.jl.svg?branch=master

src/io.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,32 @@ function hg_load(
213213
E = Nothing
214214
) where {H <: AbstractSimpleHypergraph, U <: Real}
215215
json_hg = JSON.parse(read(io, String))
216+
if json_hg.m isa String
217+
json_hg.m = JSON.parse(json_hg.m)
218+
end
219+
if json_hg.v2he isa String
220+
json_hg.v2he = JSON.parse(json_hg.v2he)
221+
end
222+
if json_hg.v_meta isa String
223+
json_hg.v_meta = JSON.parse(json_hg.v_meta)
224+
end
225+
if json_hg.he_meta isa String
226+
json_hg.he_meta = JSON.parse(json_hg.he_meta)
227+
end
216228
m = reshape(Vector{Union{T, Nothing}}(json_hg.m), json_hg.n, json_hg.k)
217229

218230
V2 = (V == :auto) ? ("v_meta" keys(json_hg) && length(json_hg.v_meta) > 0 ? elemtypes(json_hg.v_meta) : Nothing) : V
219231
E2 = (E == :auto) ? ("he_meta" keys(json_hg) && length(json_hg.he_meta) > 0 ? elemtypes(json_hg.he_meta) : Nothing) : E
220232

221233
if V2 != Nothing && E2 != Nothing && hasvertexmeta(HType) && hashyperedgemeta(HType)
222-
v_meta = Vector{Union{V2, Nothing}}(json_hg.v_meta)
223-
he_meta = Vector{Union{E2, Nothing}}(json_hg.he_meta)
234+
v_meta = Union{V2, Nothing}[isnothing(e) ? e : V2(e) for e in json_hg.v_meta]
235+
he_meta = Union{E2, Nothing}[isnothing(e) ? e : E2(e) for e in json_hg.he_meta]
224236
h = HType{T, V2, E2, D}(m; v_meta, he_meta)
225237
elseif V2 != Nothing && hasvertexmeta(HType)
226-
v_meta = Vector{Union{V2, Nothing}}(json_hg.v_meta)
238+
v_meta = Union{V2, Nothing}[isnothing(e) ? e : V2(e) for e in json_hg.v_meta]
227239
h = HType{T, V2, D}(m; v_meta=v_meta)
228240
elseif E2 != Nothing && hashyperedgemeta(HType)
229-
he_meta = Vector{Union{E2, Nothing}}(json_hg.he_meta)
241+
he_meta = Union{E2, Nothing}[isnothing(e) ? e : E2(e) for e in json_hg.he_meta]
230242
h = HType{T, E2, D}(m; he_meta=he_meta)
231243
else
232244
h = HType{T, V2, E2, D}(m)

test/hif-standard-tests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ end
7272
#==
7373
using Revise
7474
using SimpleHypergraphs
75+
pathof(SimpleHypergraphs)
76+
pth = joinpath(dirname(pathof(SimpleHypergraphs)),"..","tutorials", "basics", "data", "hg_seasons_all.json");
77+
h = SimpleHypergraphs.hg_load(pth; format=JSON_Format(), T=Int, V=Symbol, E=Symbol);
78+
7579
cd("test")
7680
full_path = "data/HIF-standard/missing_direction.json"
7781
run(`cat $full_path`);
@@ -83,4 +87,4 @@ h_loaded2 = hg_load(seekstart(io_h2), HIF_Format(); T=Int, show_warning=true, ad
8387
h2 == h_loaded2
8488
h2.v_meta == h_loaded2.v_meta
8589
h2.he_meta == h_loaded2.he_meta
86-
==#
90+
==#

tutorials/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ For better visualization, open the notebooks on [nbviewer](https://nbviewer.jupy
66
- [Basics][basic-url] &mdash; for a quick start with `SimpleHypergraphs.jl`.
77
- [A Game of Thrones use case][got-url] &mdash; check out how you can exploit the library to gather insights into real-world networks through a case study of the Game of Thrones TV series.
88
- [Visualizing hypegraphs][viz-url] &mdash; take a look at this notebook for more in-depth insight about visualization functionalities.
9+
- [Working with HIF standard format][viz-hif] &mdash; use case scenario showing a use of HIF standard.
910

1011

1112

12-
[basic-url]: https://nbviewer.jupyter.org/github/pszufe/SimpleHypergraphs.jl/blob/master/tutorials/basics/SimpleHypergraphs_tutorial_v4.ipynb
13+
[basic-url]: https://nbviewer.jupyter.org/github/pszufe/SimpleHypergraphs.jl/blob/master/tutorials/basics/SimpleHypergraphs_tutorial_v5.ipynb
1314
[got-url]: https://nbviewer.jupyter.org/github/pszufe/SimpleHypergraphs.jl/blob/master/tutorials/basics/A%20case%20study%20-%20Game%20of%20Thrones.ipynb
1415
[viz-url]: https://nbviewer.jupyter.org/github/pszufe/SimpleHypergraphs.jl/blob/master/tutorials/viz/Visualizing_hypergraphs.ipynb
16+
[viz-hif]: https://nbviewer.jupyter.org/github/pszufe/SimpleHypergraphs.jl/blob/master/tutorials/hif-standard/HIF-SimpleHypergraphs-demo.ipynb

tutorials/basics/A case study - Game of Thrones.html

Lines changed: 202 additions & 8076 deletions
Large diffs are not rendered by default.

tutorials/basics/A case study - Game of Thrones.ipynb

Lines changed: 498 additions & 15711 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)