sbromberger / MetaGraphs.jl

I never metagraph I didn't like.
Other
94 stars 24 forks source link

Use getproperty() to access a meta graph vertex via a label index #101

Closed CameronBieganek closed 4 years ago

CameronBieganek commented 4 years ago

Would it be possible to overload getproperty so that a meta graph vertex can be accessed using the . property-access syntax? For example, if I have an index called label, I could do something like the following to get the vertex number:

julia> mg.label["vertex2"]
2

instead of the current syntax:

julia> mg["vertex2", :label]

I think the current syntax is confusing, because it looks like you're trying to index a 2D object like a matrix or a data frame.

CameronBieganek commented 4 years ago

Taking a broader view, it might also be nice to be able to do things like this:

julia> mg.label["vertex2"].color = "blue"  # setproperty!
"blue"

julia> mg.label["vertex2"].color  # getproperty
"blue"

And then if one needed to retrieve the underlying integer vertex ID, perhaps something like the following:

julia> mg.label["vertex2"].id
2
CameronBieganek commented 4 years ago

Right now it appears that you can have multiple custom indexes. I don't do enough graph computing to know whether or not that's a feature that people need. If only one custom index was allowed, then we could have the following hypothetical API:

mg = MetaGraph(path_graph(3))

# getindex() with an Int uses the primitive index.
for i in vertices(mg)
    mg[i].label = "id$i"  # overloaded setproperty!() is used here. 
end
set_index_prop!(mg, :label)

add_edge!(mg, mg["id1"], mg["id2"])  # indexing with non-Int uses the custom index.

Or something like that.... The design details require some thought.

sbromberger commented 4 years ago

What happens if the indexed property is an integer?

CameronBieganek commented 4 years ago

Darn it, I was trying to avoid that question. :)

CameronBieganek commented 4 years ago

Superseded by https://github.com/JuliaGraphs/MetaGraphsNext.jl