LEMON Graph Format (LGF)

The LGF is a column oriented file format for storing graphs and associated data like node and edge maps.

Each line with '#' first non-whitespace character is considered as a comment line.

Otherwise the file consists of sections starting with a header line. The header lines starts with an '@' character followed by the type of section. The standard section types are @nodes, @arcs and @edges and @attributes. Each header line may also have an optional name, which can be use to distinguish the sections of the same type.

The standard sections are column oriented, each line consists of tokens separated by whitespaces. A token can be plain or quoted. A plain token is just a sequence of non-whitespace characters, while a quoted token is a character sequence surrounded by double quotes, and it can also contain whitespaces and escape sequences.

The @nodes section describes a set of nodes and associated maps. The first is a header line, its columns are the names of the maps appearing in the following lines. One of the maps must be called "label", which plays special role in the file. The following non-empty lines until the next section describes nodes of the graph. Each line contains the values of the node maps associated to the current node.

@nodes
label coordinates size title
1 (10,20) 10 "First node"
2 (80,80) 8 "Second node"
3 (40,10) 10 "Third node"

The LGF files can also contain bipartite graphs, in this case a @red_nodes and a @blue_nodes sections describe the node set of the graph. If a map is in both of these sections, then it can be used as a regular node map.

@red_nodes
label only_red_map name
1 "cherry" "John"
2 "Santa Claus" "Jack"
3 "blood" "Jason"
@blue_nodes
label name
4 "Elisabeth"
5 "Eve"

The @arcs section is very similar to the @nodes section, it again starts with a header line describing the names of the maps, but the "label" map is not obligatory here. The following lines describe the arcs. The first two tokens of each line are the source and the target node of the arc, respectively, then come the map values. The source and target tokens must be node labels.

@arcs
capacity
1 2 16
1 3 12
2 3 18

If there is no map in the @arcs section at all, then it must be indicated by a sole '-' sign in the first line.

@arcs
-
1 2
1 3
2 3

The @edges is just a synonym of @arcs. The @arcs section can also store the edge set of an undirected graph. In such case there is a conventional method for store arc maps in the file, if two columns have the same caption with '+' and '-' prefix, then these columns can be regarded as the values of an arc map.

The @attributes section contains key-value pairs, each line consists of two tokens, an attribute name, and then an attribute value. The value of the attribute could be also a label value of a node or an edge, or even an edge label prefixed with '+' or '-', which regards to the forward or backward directed arc of the corresponding edge.

@attributes
source 1
target 3
caption "LEMON test digraph"

The LGF can contain extra sections, but there is no restriction on the format of such sections.