Creating dynamic GEXF files

While Gephi can be used to create GEXF files, it can be advantageous in many cases to have the file already prepared prior to importing data into Gephi. For any reader acquainted with XML, the formatting and structure will appear very familiar. If you aren't an XML expert, we'll walk through some of the GEXF basics to help you get started.

The code in this section is based on the examples from the http://gexf.net/format/ site, which provides a general primer for how to structure the data. At a very basic level, the GEXF file is designed to represent a single graph, although that graph might contain many nodes and edges. For a very basic example with two nodes and a single edge between them, the GEXF code would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2">
    <meta lastmodifieddate="2009-03-20">
        <creator>Gexf.net</creator>
        <description>A Web network not changing over time</description>
    </meta>
    <graph mode="static" defaultedgetype="directed">
        <nodes>
            <node id="0" label="Hello" />
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1" />
        </edges>
    </graph>
</gexf>

This file would deliver a simple static graph, which is not what we're after in this chapter. So let's move on to creating a more complex file with time intervals and changing attribute values.

Here's a somewhat more advanced example from the gexf.net site, incorporating time intervals and value changes. We'll break this code into four distinct sections and provide brief descriptions for what is being achieved.

The first section provides basic descriptive information about the file and its format, as well as simple information about who created the file and how it should be described:

<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd" version="1.2">
    <meta lastmodifieddate="2009-03-20">
        <creator>Gexf.net</creator>
        <description>A Web network changing over time</description>
    </meta>

Our second section of code pertains to the graph structure, providing the capability for individual nodes to be static or dynamic. Note also that the default edge type (directed) has also been specified:

    <graph mode="dynamic" defaultedgetype="directed" timeformat="date">
        <attributes class="node" mode="static">
            <attribute id="0" title="url" type="string"/>
            <attribute id="1" title="frog" type="boolean">
                <default>true</default>
            </attribute>
        </attributes>
        <attributes class="node" mode="dynamic">
            <attribute id="2" title="indegree" type="float"/>
        </attributes>

The third section provides detail about how individual nodes will function, including their respective start and end dates for a dynamic network:

        <nodes>
            <node id="0" label="Gephi" start="2009-03-01">
                <attvalues>
                    <attvalue for="0" value="http://gephi.org"/>
                    <attvalue for="2" value="1"/>
                </attvalues>
            </node>
            <node id="1" label="Network">
                <attvalues>
                    <attvalue for="2" value="1" end="2009-03-01"/>
                    <attvalue for="2" value="2" start="2009-03-01" end="2009-03-10"/>
                    <attvalue for="2" value="1" start="2009-03-10"/>
                </attvalues>
            </node>
            <node id="2" label="Visualization">
                <attvalues>
                    <attvalue for="2" value="0" end="2009-03-01"/>
                    <attvalue for="2" value="1" start="2009-03-01"/>
                </attvalues>
                <spells>
                    <spell end="2009-03-01"/>
                    <spell start="2009-03-05" end="2009-03-10" />
                </spells>
            </node>
            <node id="3" label="Graph">
                <attvalues>
                    <attvalue for="1" value="false"/>
                    <attvalue for="2" value="0" end="2009-03-01"/>
                    <attvalue for="2" value="1" start="2009-03-01"/>
                </attvalues>
            </node>
        </nodes>

Finally, we see the edge parameters, again with start and end values set where appropriate:

        <edges>
            <edge id="0" source="0" target="1" start="2009-03-01"/>
            <edge id="1" source="0" target="2" start="2009-03-01" end="2009-03-10"/>
            <edge id="2" source="1" target="0" start="2009-03-01"/>
            <edge id="3" source="2" target="1" end="2009-03-10"/>
            <edge id="4" source="0" target="3" start="2009-03-01"/>
        </edges>
    </graph>
</gexf>

Note a few changes in the code between the two examples:

  • The graph mode value has changed from static to dynamic
  • The second example has now declared node attributes to be either static or dynamic
  • Start and/or end dates have been specified for certain nodes and edges
  • Values relative to time windows are now specified at the node level

These changes will take us from a simple static graph to a living dynamic graph that shows changes over a time continuum and thus adds a far more insightful view of the network. There are additional structures that can be created using GEXF; for further examples please visit the site at http://gexf.net/format/.

The other option for creating your own dynamic GEXF files is to import data into Gephi using .csv or other protocols; make your necessary adjustments and customization, and then export the data to a .gexf format. This is the process we used in our dynamic attribute example earlier in the chapter. Note that other graph formats can also be created if you are planning to utilize software other than Gephi.

One of the significant advantages of creating a GEXF file is that you will be saving custom analysis performed on a network—colors, sizes, and other attributes can then be easily imported into Gephi at a future date. Similarly, other users could import your network into Gephi and will be able to benefit from your existing work.

It is not essential that you know how to create GEXF files outside of Gephi, as Gephi will do much of the heavy lifting for you within the application. You can certainly continue to load data into Gephi from other formats, enhance it within the application, and eventually output the GEXF format. However, for those who like to do their own coding, or can create processes that download data into an XML framework, there is great potential value in understanding how GEXF functions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.41.235