Documentation ¶
Index ¶
- Constants
- func AttrsToStringMap(a map[string]any) map[string]string
- type Edge
- func (e *Edge) Attributes() []encoding.Attribute
- func (e *Edge) Attrs() map[string]any
- func (e *Edge) From() gonum.Node
- func (e *Edge) Label() string
- func (e *Edge) ReversedEdge() gonum.Edge
- func (e *Edge) SetLabel(l string)
- func (e *Edge) SetUID(uid string)
- func (e *Edge) SetWeight(w float64)
- func (e *Edge) String() string
- func (e *Edge) To() gonum.Node
- func (e *Edge) UID() string
- func (e *Edge) Weight() float64
- type Graph
- func (g *Graph) AddNode(n *Node) error
- func (g *Graph) Attributes() []encoding.Attribute
- func (g *Graph) Attrs() map[string]any
- func (g *Graph) DOTAttributers() (graph, node, edge encoding.Attributer)
- func (g *Graph) DOTID() string
- func (g *Graph) HasEdgeFromTo(uid, vid int64) bool
- func (g *Graph) Inputs() []*Node
- func (g *Graph) Label() string
- func (g *Graph) NewEdge(from, to hypher.Node, opts ...hypher.Option) (*Edge, error)
- func (g *Graph) NewNode(opts ...hypher.Option) (*Node, error)
- func (g *Graph) Outputs() []*Node
- func (g *Graph) Reset()
- func (g *Graph) Run(ctx context.Context, inputs map[string]hypher.Value, opts ...hypher.Option) error
- func (g *Graph) SetDOTID(dotid string)
- func (g *Graph) SetEdge(e hypher.Edge) error
- func (g *Graph) SetInputs(nodes []*Node)
- func (g *Graph) SetLabel(l string)
- func (g *Graph) SetOutputs(nodes []*Node)
- func (g *Graph) SetUID(uid string)
- func (g *Graph) String() string
- func (g *Graph) SubGraph(inputNodes, outputNodes Nodes) (*Graph, error)
- func (g *Graph) To(id int64) gonum.Nodes
- func (g *Graph) TopoSort() ([]gonum.Node, error)
- func (g *Graph) TopoSortWithLevels() ([][]gonum.Node, error)
- func (g *Graph) UID() string
- type NoOp
- type Node
- func (n *Node) Attributes() []encoding.Attribute
- func (n *Node) Attrs() map[string]any
- func (n *Node) Clone() (*Node, error)
- func (n *Node) CloneTo(g *Graph) (*Node, error)
- func (n *Node) DOTID() string
- func (n *Node) Exec(ctx context.Context, inputs ...hypher.Value) ([]hypher.Value, error)
- func (n *Node) Graph() hypher.Graph
- func (n *Node) ID() int64
- func (n *Node) Inputs() []hypher.Value
- func (n *Node) Label() string
- func (n *Node) Op() hypher.Op
- func (n *Node) Outputs() []hypher.Value
- func (n *Node) Reset()
- func (n *Node) SetDOTID(dotid string)
- func (n *Node) SetInputs(inputs ...hypher.Value) error
- func (n *Node) SetLabel(l string)
- func (n *Node) SetUID(uid string)
- func (n *Node) String() string
- func (n *Node) UID() string
- type Nodes
Constants ¶
const ( // DefaultEdgeLabel is the default edge label. DefaultEdgeLabel = "HypherEdge" // DefaultEdgeWeight is the default edge weight. DefaultEdgeWeight = 1.0 )
const ( // DefaultNodeLabel is the default node label. DefaultNodeLabel = "HypherNode" // NoneID is non-existent ID. // Thanks Go for not having optionals! NoneID int64 = -1 )
const (
// DefaultGraphLabel is the default label.
DefaultGraphLabel = "HypherGraph"
)
Variables ¶
This section is empty.
Functions ¶
func AttrsToStringMap ¶
AttrsToStringMap attempts to convert a map to a map of strings. It first checks if the stored attribute value is stringly i.e. either of string, fmt.Stringer or fmt.GoStringer. If it is it returns its stringe representation. If the attribute value is not stringly we attempt to convert well known attributes to strings. If the attribute is neither stringly nor is it known how to convert it to a string the attribute is omitted from the returned map.
Types ¶
type Edge ¶
type Edge struct {
// contains filtered or unexported fields
}
Edge is a weighted graph edge.
func EdgeDeepCopy ¶
EdgeDeepCopy makes a deep copy of Edge and returns it
func (*Edge) Attributes ¶
Attributes returns node DOT attributes.
func (*Edge) ReversedEdge ¶
ReversedEdge returns a new edge with end points of the pair swapped.
type Graph ¶
type Graph struct { *simple.WeightedDirectedGraph // contains filtered or unexported fields }
Graph is an in-memory graph.
func (*Graph) AddNode ¶
AddNode adds a node to the graph or returns error. If the node's graph is the same as g it returns nil. Otherwise, it tries to preserve the ID of the node unless the ID is not set (NoneID) or a node with the same ID already exists in g, in which case a new ID is generated before the node is added to g. If node's graph is nil, it's set to g.
func (*Graph) Attributes ¶
Attributes returns graph DOT attributes.
func (*Graph) DOTAttributers ¶
func (g *Graph) DOTAttributers() (graph, node, edge encoding.Attributer)
DOTAttributers are graph.Graph values that specify top-level DOT attributes TODO: figure out node and edge top level attributes
func (*Graph) HasEdgeFromTo ¶
HasEdgeFromTo returns whether an edge exist between two nodoes with the given IDs.
func (*Graph) NewEdge ¶
NewEdge creates a new edge link its node in the graph. It returns the new edge or fails with error.
func (*Graph) NewNode ¶
NewNode creates a new node and adds it to the graph. It returns the new node or fails with error.
func (*Graph) Run ¶
func (g *Graph) Run(ctx context.Context, inputs map[string]hypher.Value, opts ...hypher.Option) error
Run runs the graph with the given inputs. The given inputs are set as inputs to the graph input nodes. Run executes all the graph nodes operations in the run mode passed via options. Run is a blocking call. It returns when the execution finished or if any of the executed nodes failed with error.
func (*Graph) SetEdge ¶
SetEdge adds the edge e to the graph linking the edge nodes. It adds the edge nodes to the graph if they don't already exist. It returns error if the new edge creates a graph cycle.
func (*Graph) SetOutputs ¶
SetOutputs sets graph output nodes.
func (*Graph) SubGraph ¶
SubGraph returns a sub-graph of g which contains all the nodes which are either outputNodes or are on the path to the outputNodes when starting the graph traversal in inputNodes, including the inputNodes.
func (*Graph) TopoSort ¶
TopoSort performs a topological sort of the graph. It returns nodes sorted in ascending order of their incoming edge counts (i.e. in degree) starting with nodes with zero incoming edges aka "roots". If there isn't at least one node with zero incoming edge the graph must ehter have a cycle, or have no nodes, so an empty slice is returned.
func (*Graph) TopoSortWithLevels ¶
TopoSortWithLevels does the same topological sort as TopoSort, but groups the sorted nodes to graph levels.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a graph node.
func NodeDeepCopy ¶
NodeDeepCopy makes a deep copy of Node and returns it. It does not copy node inputs or outputs.
func (*Node) Attributes ¶
Attributes returns node DOT attributes.
func (*Node) Clone ¶
Node clones a node and returns it. The cloned node has a new UID. The node ID is reset to NoneID. The graph is not copied to the cloned node. No inputs or outputs are copied either.
func (*Node) CloneTo ¶
CloneTo clones a node to graph g. The cloned node has a new UID even if g is the same as n.Graph().
func (*Node) Exec ¶
Exec executes a node Op and returns its result. It appends the output of the Op to its outputs.