networkit.graphio

class networkit.graphio.CoverReader

Bases: object

Reads a cover from a file File format: each line contains the space-separated node ids of a community

read(self, path, Graph G)
class networkit.graphio.CoverWriter

Bases: object

Writes a partition to a file. File format: each line contains the space-separated node ids of a community

write(self, Cover zeta, path)
class networkit.graphio.DGSStreamParser

Bases: object

getStream(self)
class networkit.graphio.DGSWriter

Bases: object

write(self, stream, path)
class networkit.graphio.DotGraphWriter

Bases: object

Writes graphs in the .dot/GraphViz format

write(self, Graph G, path)
class networkit.graphio.EdgeListCoverReader

Bases: object

Reads a cover from an edge list type of file File format: each line starts with a node id and continues with a list of the communities the node belongs to

read(self, path, Graph G)
class networkit.graphio.EdgeListReader

Bases: _NetworKit.GraphReader

Reads a file in an edge list format. TODO: docstring

getNodeMap(self)
class networkit.graphio.EdgeListWriter

Bases: object

Writes graphs in various edge list formats.

separator : string
The separator character.
firstNode : node
The id of the first node, this value will be added to all node ids
bothDirections : bool, optional
If undirected edges shall be written in both directions, i.e., as symmetric directed graph (default: false)
write(self, Graph G, path)
class networkit.graphio.Enum

Bases: object

Generic enumeration.

Derive from this class to define new enumerations.

class networkit.graphio.Format

Bases: networkit.graphio.__AutoNumber

Simple enumeration class to list supported file types. Currently supported file types: SNAP, EdgeListSpaceZero, EdgeListSpaceOne, EdgeListTabZero, EdgeListTabOne, METIS, GraphML, GEXF, GML, EdgeListCommaOne, GraphViz, DOT, EdgeList, LFR, KONEC, GraphToolBinary

class networkit.graphio.GEXFReader

Bases: object

createEvent(eventTime, eventType, u, v, w)

Creates a NetworKit::GraphEvent from the supplied parameters and passes it to eventStream

getNodeMap()

Returns GEXF ID -> NetworKit::Graph node ID mapping.

mapDynamicNodes()

Node ID of a dynamic node must be determined before it’s mapped to its GEXF ID. This requires processing the sorted eventStream and figuring out the addition order of the nodes. After that, node addition/deletion/restoration operations of this node must be readded to eventStream with correct mapping.

!Note: New mapping of a node can be equal to old mapping of a node. In order to prevent collisions, isMapped array must be maintained and controlled.

parseDynamics(element, elementType, controlList, u, v='0', w='0')

Determine the operations as follows: 1.Element has start and not deleted before: Create add event 2.Element has start and deleted before: Create restore event 3.Element has end:Create del event 4.If an element has end before start(or no start at all), add it to the initial graph 5.For dynamic edges, simply go over the attvalues and create weight update events

  • A dynamic element must be defined either using only spells

or inline attributes. These 2 shouldn’t be mixed. (For example, Gephi will treat them differently. It’ll ignore the inline declaration if the same element also contains spells)

read(fpath)

Reads and returns the graph object defined in fpath

class networkit.graphio.GEXFWriter

Bases: object

This class provides a function to write a NetworKit graph to a file in the GEXF format.

write(graph, fname, eventStream=[], mapping=[])

Writes a NetworKit::Graph to the specified file fname. Parameters:

  • graph: a NetworKit::Graph python object
  • fname: the desired file path and name to be written to
  • eventStream: stream of events
  • mapping: random node mapping
writeEvent(xmlElement, eventStream, graphElement)
class networkit.graphio.GMLGraphReader

Bases: _NetworKit.GraphReader

Reader for the GML graph format, which is documented here [1].

[1]: http://www.fim.uni-passau.de/fileadmin/files/lehrstuhl/brandenburg/projekte/gml/gml-technical-report.pdf

class networkit.graphio.GMLGraphWriter

Bases: object

Writes a graph and its coordinates as a GML file.[1] [1] http://svn.bigcat.unimaas.nl/pvplugins/GML/trunk/docs/gml-technical-report.pdf

write(self, Graph G, path)
class networkit.graphio.GraphConverter(reader, writer)

Bases: object

convert(inPath, outPath)
class networkit.graphio.GraphMLReader

Bases: object

This class serves as wrapper for the GraphMLSAX class which is able to parse a GraphML XML file and construct a graph.

read(fpath)

Parses a GraphML XML file and returns the constructed Graph Parameters:

  • fpath: the path to the file as a string
class networkit.graphio.GraphMLWriter

Bases: object

This class provides a function to write a NetworKit graph to a file in the GraphML format.

write(graph, fname, nodeAttributes={}, edgeAttributes={})

Writes a NetworKit graph to the specified file fname. Parameters:

  • graph: a NetworKit::Graph python object
  • fname: the desired file path and name to be written to
  • nodeAttributes: optional dictionary of node attributes in the form attribute name => list of attribute values
  • edgeAttributes: optional dictionary of edge attributes in the form attribute name => list of attribute values
class networkit.graphio.GraphToolBinaryReader

Bases: _NetworKit.GraphReader

Reads the binary file format defined by graph-tool[1]. [1]: http://graph-tool.skewed.de/static/doc/gt_format.html

class networkit.graphio.GraphToolBinaryWriter

Bases: object

Reads the binary file format defined by graph-tool[1]. [1]: http://graph-tool.skewed.de/static/doc/gt_format.html

write(self, Graph G, path)
class networkit.graphio.GraphUpdater

Bases: object

Updates a graph according to a stream of graph events.

G : Graph
initial graph
update(self, stream)
class networkit.graphio.KONECTGraphReader

Bases: _NetworKit.GraphReader

Reader for the KONECT graph format, which is described in detail on the KONECT website[1].

[1]: http://konect.uni-koblenz.de/downloads/konect-handbook.pdf

class networkit.graphio.LineFileReader

Bases: object

Reads a file and puts each line in a list of strings

read(self, path)
class networkit.graphio.METISGraphReader

Bases: _NetworKit.GraphReader

Reads the METIS adjacency file format [1]. If the Fast reader fails, use readGraph(path, graphio.formats.metis) as an alternative. [1]: http://people.sc.fsu.edu/~jburkardt/data/metis_graph/metis_graph.html

class networkit.graphio.METISGraphWriter

Bases: object

Writes graphs in the METIS format

write(self, Graph G, path)
class networkit.graphio.MatReader(key='G')

Bases: object

read(path)
class networkit.graphio.MatWriter

Bases: object

write(G, path, key='G')
class networkit.graphio.SNAPEdgeListPartitionReader

Bases: object

Reads a partition from a SNAP ‘community with ground truth’ file

read(self, path, nodeMap, Graph G)
class networkit.graphio.SNAPGraphReader

Bases: _NetworKit.GraphReader

Reads a graph from the SNAP graph data collection [1] (currently experimental) [1]: http://snap.stanford.edu/data/index.html

getNodeIdMap(self)
class networkit.graphio.SNAPGraphWriter

Bases: object

Writes graphs in a format suitable for the Georgia Tech SNAP software [1] [1]: http://snap-graph.sourceforge.net/

write(self, Graph G, path)
networkit.graphio.convertGraph(fromFormat, toFormat, fromPath, toPath=None)
networkit.graphio.getConverter(fromFormat, toFormat)
networkit.graphio.getReader(fileformat, **kwargs)
networkit.graphio.getWriter(fileformat, **kwargs)
networkit.graphio.readGraph(path, fileformat, **kwargs)

Read graph file in various formats and return a NetworKit::Graph Parameters:

  • fileformat: An element of the Format enumeration. Currently supported file types:

SNAP, EdgeListSpaceZero, EdgeListSpaceOne, EdgeListTabZero, EdgeListTabOne, METIS, GraphML, GEXF, GML, EdgeListCommaOne, GraphViz, DOT, EdgeList, LFR, KONECT, GraphToolBinary - **kwargs: in case of a custom edge list, pass the genereic Fromat.EdgeList accompanied by

the defining paramaters as follows: “separator=CHAR, firstNode=NODE, commentPrefix=STRING, continuous=BOOL, directed=BOOL” commentPrefix=’#’, continuous=True and directed=False are optional because of their default values; firstNode is not needed when continuous=True.
networkit.graphio.readGraphs(dirPath, pattern, fileformat, some=None, exclude=None, **kwargs)
Read all graph files contained in a directory whose filename contains the pattern, return a dictionary of name to Graph object.
Parameters:
  • pattern: unix-style string pattern

  • fileformat: An element of the Format enumeration

  • some: restrict number of graphs to be read

  • **kwargs: in case of a custom edge list, provide the defining paramaters as follows:

    “separator=CHAR, firstNode=NODE, commentPrefix=STRING, continuous=BOOL” commentPrefix and continuous are optional

networkit.graphio.readMat(path, key='G')

Reads a Graph from a matlab object file containing an adjacency matrix and returns a NetworKit::Graph Parameters: - key: The key of the adjacency matrix in the matlab object file (default: A)

networkit.graphio.readStream(path, mapped=True, baseIndex=0)

Read a graph event stream from a file.

networkit.graphio.writeGraph(G, path, fileformat, **kwargs)

Write graph to various output formats.

Paramaters: - G: a graph - path: output path - fileformat: an element of the Format enumeration

networkit.graphio.writeMat(G, path, key='G')

Writes a NetworKit::Graph to a Matlab object file. Parameters: - G: The graph - path: Path of the matlab file - key: Dictionary Key

networkit.graphio.writeStream(stream, path)

Write a graph event stream to a file.