graphml

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package graphml implements marshaling and unmarshalling of GraphML XML documents.

Index

Constants

This section is empty.

Variables

View Source
var NotAValue interface{} = nil

The Not value of data attribute to substitute with default one if present

Functions

This section is empty.

Types

type Data

type Data struct {
	// The ID of this data element (in form dX, where X denotes the number of occurrences of the data element before the current one)
	ID string `xml:"id,attr,omitempty"`
	// The ID of <key> element for this data element
	Key string `xml:"key,attr"`

	// The data value associated with this element
	Value string `xml:",chardata"`
}

In GraphML there may be data-functions attached to graphs, nodes, ports, edges, hyperedges and endpoint and to the whole collection of graphs described by the content of <graphml>. These functions are declared by <key> elements (children of <graphml>) and defined by <data> elements. Occurrence: <graphml>, <graph>, <node>, <port>, <edge>, <hyperedge>, and <endpoint>.

type DataType

type DataType string

The GraphML data types

const (
	// boolean (reflect.Bool)
	BooleanType DataType = "boolean"
	// single integer precision (reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint8, reflect.Uint16)
	IntType DataType = "int"
	// double integer precision (reflect.Int64, reflect.Uint32)
	LongType DataType = "long"
	// single float precision (reflect.Float32)
	FloatType DataType = "float"
	// double float precision (reflect.Float64)
	DoubleType DataType = "double"
	// string value (reflect.String)
	StringType DataType = "string"
)

type Edge

type Edge struct {
	// The ID of this edge element (in form eX, where X is the number of edge elements before this one)
	ID string `xml:"id,attr"`
	// The source node ID
	Source string `xml:"source,attr"`
	// The target node ID
	Target string `xml:"target,attr"`
	// The direction type of this edge (true - directed, false - undirected)
	Directed string `xml:"directed,attr,omitempty"`

	// Provides human readable description
	Description string `xml:"desc,omitempty"`
	// The data associated with this edge
	Data []*Data `xml:"data,omitempty"`
	// contains filtered or unexported fields
}

Describes an edge in the <graph> which contains this <edge>. Occurrence: <graph>.

func (*Edge) GetAttributes

func (e *Edge) GetAttributes() (map[string]interface{}, error)

returns data attributes map associated with Edge

type EdgeDirection

type EdgeDirection int

The edge direction

const (
	// edge direction is not specified
	EdgeDirectionDefault EdgeDirection = iota
	// edge is directed
	EdgeDirectionDirected
	// edge is undirected
	EdgeDirectionUndirected
)

type Graph

type Graph struct {
	// The ID of this graph element (in form gX, where X denotes the number of occurrences of the graph element before the current one)
	ID string `xml:"id,attr"`
	// The default edge direction (directed|undirected)
	EdgeDefault string `xml:"edgedefault,attr"`

	// Provides human readable description
	Description string `xml:"desc,omitempty"`
	// The nodes associated with this graph
	Nodes []*Node `xml:"node,omitempty"`
	// The edges associated with this graph and connecting nodes
	Edges []*Edge `xml:"edge,omitempty"`
	// The data associated with this node
	Data []*Data `xml:"data,omitempty"`
	// contains filtered or unexported fields
}

Describes one graph in this document. Occurrence: <graphml>, <node>, <edge>, <hyperedge>.

func (*Graph) AddEdge

func (gr *Graph) AddEdge(source, target *Node, attributes map[string]interface{}, edgeDirection EdgeDirection, description string) (edge *Edge, err error)

Adds edge to the graph which connects two its nodes with provided additional attributes and description

func (*Graph) AddNode

func (gr *Graph) AddNode(attributes map[string]interface{}, description string) (node *Node, err error)

Adds node to the graph with provided additional attributes and description

func (*Graph) GetEdge

func (gr *Graph) GetEdge(sourceId, targetId string) *Edge

method to test if edge exists between given nodes. If edge exists it will be returned, otherwise nil returned

type GraphML

type GraphML struct {
	// The name of root element
	XMLName xml.Name `xml:"graphml"`
	// The name space definitions
	XmlNS string `xml:"xmlns,attr"`
	// The XML schema definition
	XmlnsXsi          string `xml:"xmlns:xsi,attr"`
	XsiSchemaLocation string `xml:"xsi:schemaLocation,attr"`

	// Provides human readable description
	Description string `xml:"desc,omitempty"`
	// The custom keys describing data-functions used in this or other elements
	Keys []*Key `xml:"key,omitempty"`
	// The data associated with root element
	Data []*Data `xml:"data,omitempty"`
	// The graph objects encapsulated
	Graphs []*Graph `xml:"graph,omitempty"`
	// contains filtered or unexported fields
}

The root element

func NewGraphML

func NewGraphML(description string) *GraphML

Creates new GraphML instance

func NewGraphMLWithAttributes

func NewGraphMLWithAttributes(description string, attributes map[string]interface{}) (gml *GraphML, err error)

Creates new GraphML instance with given attributes

func (*GraphML) AddGraph

func (gml *GraphML) AddGraph(description string, edgeDefault EdgeDirection, attributes map[string]interface{}) (graph *Graph, err error)

Creates new Graph and add it to the root GraphML

func (*GraphML) Decode

func (gml *GraphML) Decode(r io.Reader) error

Decodes GraphML from provided Reader

func (*GraphML) Encode

func (gml *GraphML) Encode(w io.Writer, withIndent bool) error

Encodes GraphML into provided Writer. If withIndent set then each element begins on a new indented line.

func (*GraphML) GetKey

func (gml *GraphML) GetKey(name string, target KeyForElement) *Key

Looks for registered keys with specified name for a given target element. If specific target has no registered key then common target (KeyForAll) will be checked next. Returns Key (either specific or common) or nil.

func (*GraphML) RegisterKey

func (gml *GraphML) RegisterKey(target KeyForElement, name, description string, keyType reflect.Kind, defaultValue interface{}) (key *Key, err error)

Register data function with GraphML instance

type Key

type Key struct {
	// The ID of this key element (in form dX, where X denotes the number of occurrences of the key element before the current one)
	ID string `xml:"id,attr"`
	// The name of element this key is for (graphml|graph|node|edge|hyperedge|port|endpoint|all)
	Target KeyForElement `xml:"for,attr"`
	// The name of data-function associated with this key
	Name string `xml:"attr.name,attr"`
	// The type of input to the data-function associated with this key. (Allowed values: boolean, int, long, float, double, string)
	KeyType DataType `xml:"attr.type,attr"`
	// Provides human readable description
	Description string `xml:"desc,omitempty"`
	// The default value
	DefaultValue string `xml:"default,omitempty"`
}

Description: In GraphML there may be data-functions attached to graphs, nodes, ports, edges, hyperedges and endpoint and to the whole collection of graphs described by the content of <graphml>. These functions are declared by <key> elements (children of <graphml>) and defined by <data> elements. Occurrence: <graphml>.

type KeyForElement

type KeyForElement string

The elements where data-function can be attached

const (
	// the data-function is for root GraphML element only
	KeyForGraphML KeyForElement = "graphml"
	// the data-function is for Graph element only
	KeyForGraph KeyForElement = "graph"
	// the data-function is for Node element only
	KeyForNode KeyForElement = "node"
	// the data-function is for Edge element only
	KeyForEdge KeyForElement = "edge"
	// the data-function is for all elements
	KeyForAll KeyForElement = "all"
)

type Node

type Node struct {
	// The ID of this node element (in form nX, where X denotes the number of occurrences of the node element before the current one)
	ID string `xml:"id,attr"`
	// Provides human readable description
	Description string `xml:"desc,omitempty"`
	// The data associated with this node
	Data []*Data `xml:"data,omitempty"`
	// contains filtered or unexported fields
}

Describes one node in the <graph> containing this <node>. Occurrence: <graph>.

func (*Node) GetAttributes

func (n *Node) GetAttributes() (map[string]interface{}, error)

returns data attributes map associated with Node

Jump to

Keyboard shortcuts

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