Sunday, 30 June 2019

Gephi: Simple graph representation using GEXF


GEXF stands for Graph Exchange XML Format, it defines graph using xml schema. It is mainly used to describe complex graph structures.
In this post, I am going to explain basics of GEXF schema.

Let me try to represent below graph using GEXF schema.



From the above graph you can observe below things.
a. Above graph has two nodes
b. Nodes are labeled with A and B
c. There is a directed edge from A to B.

Model nodes
Every node is represented by <node> tag. All the nodes are grouped under <nodes> tag.

Below schema represents two nodes with labels A and B.

<nodes>
         <node id="0" label="A" />
         <node id="1" label="B" />
</nodes>

Model Edges
An edge is represented by <edge> tag. You should provide source and target node id of an edge. All the edges of a graph are grouped under <edges> tag.

<edges>
         <edge id="0" source="0" target="1" />
</edges>

How to specify directed graph?
All edges and nodes are defined inside the <graph> tag. <graph> tag has ‘defaultedgetype’ attribute to specify the type of the graph. Give the value as ‘directed’ to define directed graph, ‘undirected’ to define undirected graph.

   <graph defaultedgetype="directed">
      <!-- Define nodes here -->
      <nodes>
         <node id="0" label="A" />
         <node id="1" label="B" />
      </nodes>
   
   <!-- Define edges here -->
      <edges>
         <edge id="0" source="0" target="1" />
      </edges>
   </graph>

Total file looks like below.


HelloWorld.gexf
<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2">

   <meta lastmodifieddate="2018-04-05">
      <creator>Hari Krishna</creator>
      <description>Simple graph with two nodes</description>
   </meta>
   
   <graph defaultedgetype="directed">
      <!-- Define nodes here -->
      <nodes>
         <node id="0" label="A" />
         <node id="1" label="B" />
      </nodes>
   
   <!-- Define edges here -->
      <edges>
         <edge id="0" source="0" target="1" />
      </edges>
   
   </graph>
   
</gexf>


As you observe above snippet, <gexf> is the root element to represent gexf graph. We can provide basic information about the graph inside <meta> tag.

Previous                                                 Next                                                 Home

No comments:

Post a Comment