dtree

package module
v0.0.0-...-7b42fdd Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 6 Imported by: 0

README

Decision tree in Go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUndecidable      = errors.New("undecidable")
	ErrInvalidOutcome   = errors.New("invalid outcome")
	ErrInvalidCondition = errors.New("invalid condition")
)

Functions

This section is empty.

Types

type Branch

type Branch struct {
	Value interface{} `json:"value"`
	Next  *Node       `json:"next"`
}

type Condition

type Condition struct {
	Predicate string    `json:"predicate"`
	Branches  []*Branch `json:"branches"`
	// contains filtered or unexported fields
}

func NewCondition

func NewCondition(predicate string) (*Condition, error)

NewCondition returns a new Condition node. The value must be binary expression. If value accepts unary expression, it'd be ambiguous for a value=`X`. Because the value can be a boolean expression `X` (equivalent to `X == true`) or a string outcome `X`.

func (*Condition) AddBranch

func (c *Condition) AddBranch(value interface{}, nextNode *Node)

func (*Condition) Initialize

func (c *Condition) Initialize() error

func (*Condition) Next

func (c *Condition) Next(params map[string]interface{}) (*Node, error)

type Node

type Node struct {
	*Outcome
	*Condition
}

type Outcome

type Outcome struct {
	Value interface{} `json:"outcome"`
}

func NewOutcome

func NewOutcome(value interface{}) (*Outcome, error)

NewOutcome returns a new Outcome node. The value must be integer literal, float literal, string literal (with or without "").

type Tree

type Tree struct {
	Root *Node `json:"root"`
}

func NewTreeFromJson

func NewTreeFromJson(bytes []byte) (*Tree, error)

func (*Tree) Decide

func (t *Tree) Decide(params map[string]interface{}) (interface{}, error)

func (*Tree) Initialize

func (t *Tree) Initialize() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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