How to read a graph from a GML file

I cannot figure out how to get a graph definition from a GML file.
I downloaded the following file https://github.com/empet/Datasets/blob/master/gstrang_descendants.gml
and tried with the following code:

using LightGraphs, ParserCombinator, GraphIO 
G = loadgraph("gstrang_descendants.gml",  GMLFormat())
#G = loadgraph("gstrang_descendants.gml", "graph", GMLFormat())

and both cases (with “graph” or without it) give the same error:

Graph graph not found

Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:33
  [2] loadgml(io::IOStream, gname::String)
    @ GraphIO.GML C:\Users\empet\.julia\packages\GraphIO\IgxnP\src\GML\Gml.jl:40
  [3] loadgraph
    @ C:\Users\empet\.julia\packages\GraphIO\IgxnP\src\GML\Gml.jl:95 [inlined]
  [4] #117
    @ C:\Users\empet\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:15 [inlined]
  [5] open(::LightGraphs.var"#117#118"{String, GraphIO.GML.GMLFormat}, ::String, ::Vararg{String, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base .\io.jl:330
  [6] open
    @ .\io.jl:328 [inlined]
  [7] loadgraph(fn::String, gname::String, format::GraphIO.GML.GMLFormat)
    @ LightGraphs C:\Users\empet\.julia\packages\LightGraphs\IgJif\src\persistence\common.jl:14
  [8] top-level scope
    @ In[12]:1
  [9] eval
    @ .\boot.jl:360 [inlined]
 [10] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:1094

My code is based on this information:

?LightGraphs.loadgraph
loadgraph(file, gname="graph", format=LGFormat())
Read a graph named gname from file in the format format.

Implementation Notes
gname is graph-format dependent and is only used if the file contains multiple graphs; if the file format does not support multiple graphs, this value is ignored. The default value may change in the future.

This is the solution:

using LightGraphs,  ParserCombinator, GraphIO
graph = loadgraph("gstrang_descendants.gml",  "digraph", GraphIO.GML.GMLFormat())
1 Like