Graph
objects support both custom properties, which do not have special meanings, and standard properties, which may be used by some functions.
When importing from formats such as GraphML, we usually get a result with custom properties.
What is the simplest way to remap one property to another, e.g. to remap a custom property to a standard one so it can be used with various functions?
Example: Let's get Zachary's karate club network with edge weights and vertex names from here: http://nexus.igraph.org/api/dataset_info?id=1&format=html
g = Import[
"http://nexus.igraph.org/api/dataset?id=1&format=GraphML", {"ZIP", "karate.GraphML"}]
I can remap "name"
to VertexLabels
and "weights"
to EdgeWeight
like this:
sp[prop_][g_] := SetProperty[g, prop]
g2 = g //
sp[EdgeWeight -> (PropertyValue[{g, #}, "weight"] & /@ EdgeList[g])] //
sp[VertexLabels -> (# -> PropertyValue[{g, #}, "name"] & /@ VertexList[g])]
I do find this quite tedious though. I am wondering if there are easier, more streamlined ways to do it.
For example, with igraph this is usually as easy as g.betweeness(weights="weight")
(Python) to use the "weight"
attribute as edge weights for a betweenness calculation. I know that WeightedAdjacencyMatrix
does support such a simple syntax: WeightedAdjacencyMatrix[g, EdgeWeight -> "weight"]
uses the "weight"
attribute for the matrix. But I don't know if there are simple syntaxes like this in other situations.