Skip to main content

GDF formatter for networks representation

Project description

# GDF Formatter

This is a simple and flexible Python library to create and format your graphs in GDF.

## GDF format information

**GDF types:**

| Type | Explanation |
| VARCHAR | A string |
| BOOLEAN | `true` or `false` |
| INTERGER | Interger number |
| DOUBLE | Float number |

**Default Attributes:**

For nodes, the default GDF attributes are:

| Attribute | Type |
| name | VARCHAR |
| label | VARCHAR |
| class | VARCHAR |
| visible | BOOLEAN |
| labelvisible | BOOLEAN |
| height | DOUBLE |
| x | DOUBLE |
| y | DOUBLE |
| width | DOUBLE |
| color | VARCHAR |

And for edges, the default GDF attributes are:

| Attribute | Type |
| node1 | VARCHAR |
| node2 | VARCHAR |
| weight | DOUBLE |
| directed | BOOLEAN |
| color | VARCHAR |

## How to use

**Declaring a graph:**

You have 3 different ways to declare a graph. The fist one is using the default constructor which implements the default attributes for GDF format as below

graph = Graph()
You can also define custom nodes and edges attributes by passing a dictionary composed by `{attribute:type}` through the Graph constructor parameters `custom_nodes` and `custom_edges`

node = {'type':'VARCHAR', 'connections':'DOUBLE', 'class':'DOUBLE'}
edge = {'influence':'DOUBLE', 'weight':'DOUBLE'}
graph = Graph(custom_nodes=node, custom_edges=edge)

Another way to do that is defining custom node attributes on the go as a parameter in the constructor as `name='TYPE'`, like that:

graph = Graph(age='INTERGER')
graph2 = Graph(age='INTERGER', size='DOUBLE')

* You can use both dictionary and on-the-go methods at the same time
* If you want to overwrite the type of a default attribute you can just pass them in one of the two way above

**Adding nodes:**

Only the `name` parameter are required
graph.addNode(name='1', label='Foo', type='t1', connections=2, age=80)

**Adding edges:**

Only the `node1` and `node2` parameters are required
graph.addLink(node1='1', node2='2')

**Dumping a GDF formatted file:**


from graph import Graph

node = {'type':'VARCHAR', 'connections':'DOUBLE'}
edge = {'influence':'DOUBLE', 'weight':'DOUBLE'}
graph = Graph(custom_nodes=node, custom_edges=edge, allow_equal_nodes=True, age='INTERGER')

graph.addNode(name='1', label='Foo', type='t1', connections=2, age=80)
graph.addNode(name='2', label='Bar', type='t1', connections=3)
graph.addNode(name='3', label='Qux', connections=8, age=21)

graph.addLink(node1='1', node2='2', weight=0.3)
graph.addLink(node1='1', node2='2', weight=8, influence=8)
graph.addLink(node1='2', node2='1', weight=0)
graph.addLink(node1='2', node2='1', weight=0, influence=9)


**Example output**
nodedef>name VARCHAR,label VARCHAR,type VARCHAR,connections DOUBLE,age INTERGER

edgedef>node1 VARCHAR,node2 VARCHAR,weight DOUBLE,influence DOUBLE

## Credits

[GabrielTrettel]( for creating the library

[GrayJack]( for creating the README

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gdf_formatter-0.0.5.tar.gz (4.0 kB view hashes)

Uploaded source

Built Distribution

gdf_formatter-0.0.5-py3-none-any.whl (5.4 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page