dependency

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree is a dependency tree.

func Parse

func Parse(offset int32, tokens []*tokenize.Token) (tree Tree)

Parse parses the given tokens and returns a head-to-dependent dependency tree. Parse will panic if the tokens contain cyclic dependencies.

The offset can be used if the tokens' head indices cross sentence boundaries.

Tokens and offset can't exceed 2^32.

func (Tree) Dependencies

func (tree Tree) Dependencies(fn func(head, dependent *tokenize.Token) bool)

Dependencies iterates over every relationship and calls fn with the head and dependent token. If fn returns false, Dependencies returns.

func (Tree) Dependents

func (tree Tree) Dependents(head *tokenize.Token, fn func(*tokenize.Token) bool) bool

Dependents iterates over every dependent of head and calls fn with the token. If head has no dependents, it returns false, otherwise true.

func (Tree) Edge

func (tree Tree) Edge(uid, vid int64) graph.Edge

Edge implements the graph traverser.

func (Tree) From

func (tree Tree) From(id int64) graph.Nodes

From implements the graph traverser.

func (Tree) Head

func (tree Tree) Head(dependent *tokenize.Token) *tokenize.Token

Head returns the token dependent is headed from. If dependent is the root token, Head returns nil.

func (Tree) Root

func (tree Tree) Root() *tokenize.Token

Root returns the root token.

func (Tree) Search

func (tree Tree) Search(fn func(token *tokenize.Token) bool) (*tokenize.Token, bool)

Search iterates over all tokens and returns the found token and true if fn resolves to true. The token order is deterministic.

func (Tree) String

func (tree Tree) String() string

String returns a GraphViz DOT presentation of the tree.

func (Tree) To

func (tree Tree) To(id int64) graph.Nodes

func (Tree) Walk

func (tree Tree) Walk(fn func(t *tokenize.Token) bool)

Walk walks the tree in pre-order and calls fn on every visited node. It can be cancelled with returning false.

Jump to

Keyboard shortcuts

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