Vertex Metadata

Vertex Metadata

Graft supports the assignment of metadata to vertices, and adopts a tabular approach to storage. Vertex metadata is stored as an AbstractDataFrame. The vertices internal identifiers are used to index the vertex table.

The following example demonstrates vertex metadata:

julia> using Graft

julia> g = completegraph(10);

julia> setlabel!(g, map(string, 1:10));

julia> # Create a new vertex property
       setvprop!(g, :, 1 : 10, :p1);

julia> # Fetch an entire column from the vertex table
       getvprop(g, :, :p1)
10-element DataArrays.DataArray{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

julia> # Modify the property's value for a subset of the vertices
       setvprop!(g, 1:5, 5, :p1)
5

julia> # Fetch the property's value for a subset of the vertices
       getvprop(g, 1:5, :p1)
5-element DataArrays.DataArray{Int64,1}:
 5
 5
 5
 5
 5

julia> # Create a new vertex property
       setvprop!(g, :, 1, :p2);

julia> # List all vertex properties in the graph
       listvprops(g)
2-element Array{Symbol,1}:
 :p1
 :p2

julia> # Display the vertex table
       V = VertexDescriptor(g)
 VertexID  Labels  p1  p2 
├──────────┼────────┼────┼────┤
 1         "1"     5   1  
 2         "2"     5   1  
 3         "3"     5   1  
 4         "4"     5   1  
 5         "5"     5   1  
 6         "6"     6   1  
 7         "7"     7   1  
 8         "8"     8   1  
 9         "9"     9   1  
 10        "10"    10  1  

Vertex 5
p1 => 5
p2 => 1
julia> # Examine a single labelled vertex
       V["5"]

Detailed documentation:

# Graft.listvpropsFunction.

List the column headers in the vertex dataframe

source

# Graft.hasvpropFunction.

Check if the vertex dataframe has the input column

source

# Graft.getvpropFunction.

Retrieve vertex properties.

getvprop(g::Graph, v::VertexID, vprop::Symbol) -> Fetch the value of a property for vertex v

source

getvprop(g::Graph, vs::VertexList, vprop::Symbol) -> Fetch the value of a property for v in vs

source

getvprop(g::Graph, ::Colon, vprop::Symbol) -> Fetch the value of a property for all verices

source

# Graft.setvprop!Function.

Set vertex properties.

setvprop!(g::Graph, v::VertexID, val(s), vprop::Symbol) -> Set a property for v

source

setvprop!(g::Graph, vs::VertexList, val(s), vprop::Symbol) -> Set a property for v in vs

source

setvprop!(g::Graph, ::Colon, val(s), vprop::Symbol) -> Set a property for all vertices in g

source