graphml

package module
v0.0.0-...-6d40272 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

README

GraphML library for Go

The goal of the project is to provide a lossless encoder and decoder for GraphML.

Status

The library can successfully roundtrip GraphML of following applications:

Supported features:

  • Nodes, Edges

  • Multiple graphs

  • Subgraphs inside nodes

  • Custom data for any node kind (key, data)

Not yet supported:

  • Hyper-Edges

  • Ports

  • Endpoints

Documentation

Index

Constants

View Source
const (
	// Ext is a file extension for GraphML files.
	Ext = ".graphml"
	// Namespace is a canonical XML namespace for GraphML.
	Namespace = "http://graphml.graphdrawing.org/xmlns"
)
View Source
const (
	EdgeDirected   = EdgeDir("directed")
	EdgeUndirected = EdgeDir("undirected")
)
View Source
const (
	KindAll       = Kind("all")
	KindGraphML   = Kind("graphml")
	KindGraph     = Kind("graph")
	KindNode      = Kind("node")
	KindEdge      = Kind("edge")
	KindHyperEdge = Kind("hyperedge")
	KindPort      = Kind("port")
	KindEndpoint  = Kind("endpoint")
)

Variables

This section is empty.

Functions

func Encode

func Encode(w io.Writer, doc *Document) error

Encode writes a GraphML document to the stream.

func EncodeTo

func EncodeTo(enc *xml.Encoder, doc *Document) error

EncodeTo is similar to Encode, but allows to provide a custom XML encoder.

Types

type Data

type Data struct {
	Key          string     `xml:"key,attr"`
	Unrecognized []xml.Attr `xml:",any,attr"`
	Data         []xml.Token
}

Data is a raw XML value for a custom attribute.

func (*Data) Reader

func (d *Data) Reader() xml.TokenReader

Reader returns a XML token reader for this custom attribute. See xml.NewTokenDecoder().

type Document

type Document struct {
	Instr  xml.ProcInst
	Attrs  []xml.Attr
	Keys   []Key
	Graphs []Graph `xml:"graph"`
	Data   []Data  `xml:"data"`
}

Document is a self-contained GraphML document.

func Decode

func Decode(r io.Reader) (*Document, error)

Decode reads a GraphML document from the stream.

func DecodeFrom

func DecodeFrom(dec *xml.Decoder) (*Document, error)

DecodeFrom is similar to Decode, but allows to specify a custom XML decoder.

type Edge

type Edge struct {
	ExtObject
	Source string `xml:"source,attr"`
	Target string `xml:"target,attr"`
}

Edge is a connection between two nodes in a graph.

type EdgeDir

type EdgeDir string

EdgeDir is a direction mode for edges (directed or undirected).

type ExtObject

type ExtObject struct {
	Object
	Data []Data `xml:"data"`
}

ExtObject is a common set of attributes for nodes that can be extended.

type Graph

type Graph struct {
	ExtObject

	// EdgeDefault is a default direction mode for edges (directed or undirected).
	EdgeDefault EdgeDir `xml:"edgedefault,attr"`

	Nodes []Node `xml:"node"`
	Edges []Edge `xml:"edge"`
}

Graph is a set of nodes and edges.

type Key

type Key struct {
	Object
	For  Kind   `xml:"for,attr"`
	Name string `xml:"attr.name,attr"`
	Type string `xml:"attr.type,attr"`
}

Key is a definition of a custom attribute.

func NewKey

func NewKey(kind Kind, id, name, typ string) Key

NewKey creates a new custom attribute definition.

type Kind

type Kind string

Kind is an element kind used for extensions.

type Node

type Node struct {
	ExtObject

	Graphs []Graph `xml:"graph"`
}

Node is a node in a graph.

type Object

type Object struct {
	ID           string     `xml:"id,attr"`
	Unrecognized []xml.Attr `xml:",any,attr"`
}

Object is a set of common attributes for nodes edges and graphs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL