ast

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PtrBool

func PtrBool(b bool) *bool

func PtrFloat

func PtrFloat(f float64) *float64

Types

type Accessor

type Accessor struct{ Path []string }

type And

type And []Operator

type BoostRuleOneOf

type BoostRuleOneOf struct {
	ConstBoost *ConstBoost `json:"boost,omitempty"`
	ValueBoost *ValueBoost `json:"valueBoost,omitempty"`
}

type BoostWhenFieldRuleOneOf

type BoostWhenFieldRuleOneOf struct {
	Boost *float64 `json:"boost,omitempty"`
	// multiply score by value in field
	MultiplyUsingFieldValue *bool `json:"multiply,omitempty"`

	// There can be more operations supported
	When FieldRuleOneOf `json:"when"`
}

type ConstBoost

type ConstBoost struct {
	Boost float64 `json:"boost"`
	RuleOneOf
}

type DescriptionOfBestResult

type DescriptionOfBestResult struct {
	AtLeastOneOf   []BoostWhenFieldRuleOneOf `json:"atLeastOneOf"`
	MustMatchOneOf []FieldRuleOneOf          `json:"mustMatchOneOf"`
}

type Eq

type Eq struct{ L, R Value }

type EqTo

type EqTo struct{ V any }

type Field

type Field string

func (Field) ToPath

func (f Field) ToPath() []string

type FieldRuleOneOf

type FieldRuleOneOf struct {
	Field Field           `json:"field,omitempty"`
	Eq    interface{}     `json:"eq,omitempty"`
	Gt    interface{}     `json:"gt,omitempty"`
	Or    *FieldRuleOneOf `json:"or,omitempty"`
	And   *FieldRuleOneOf `json:"and,omitempty"`
	Not   *FieldRuleOneOf `json:"not,omitempty"`
}

func (FieldRuleOneOf) ToOperation

func (a FieldRuleOneOf) ToOperation() Operator

type FiledBoostRule

type FiledBoostRule map[Field]BoostRuleOneOf

type FiledRule

type FiledRule map[Field]RuleOneOf

type GrThan

type GrThan struct{ V any }

type Gt

type Gt struct{ L, R Value }

type HumanFriendlyRules

type HumanFriendlyRules struct {
	// OneOf implies OR for list of rules - AtLeastOneOf
	// Lack  of it implies AND for list of rules - MustMatch
	AtLeastOneOf []FiledBoostRule `json:"atLeastOneOf"`
	MustMatch    []FiledRule      `json:"mustMatch"`
}

func (HumanFriendlyRules) MustMatchToOperation

func (ast HumanFriendlyRules) MustMatchToOperation() Operator

type InterpretValueAST

type InterpretValueAST struct {
	V MapAny
}

func (*InterpretValueAST) VisitAccessor

func (e *InterpretValueAST) VisitAccessor(v *Accessor) any

func (*InterpretValueAST) VisitLit

func (e *InterpretValueAST) VisitLit(v *Lit) any

type IntrprateOperatorAST

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

func NewInterpreter

func NewInterpreter() *IntrprateOperatorAST

func (*IntrprateOperatorAST) Eval

func (e *IntrprateOperatorAST) Eval(ast Operator, data MapAny) bool

func (*IntrprateOperatorAST) Value

func (e *IntrprateOperatorAST) Value(v Value, data MapAny) (value interface{}, found bool)

func (*IntrprateOperatorAST) VisitAnd

func (e *IntrprateOperatorAST) VisitAnd(v *And) any

func (*IntrprateOperatorAST) VisitEq

func (e *IntrprateOperatorAST) VisitEq(v *Eq) any

func (*IntrprateOperatorAST) VisitGt

func (e *IntrprateOperatorAST) VisitGt(v *Gt) any

func (*IntrprateOperatorAST) VisitNot

func (e *IntrprateOperatorAST) VisitNot(v *Not) any

func (*IntrprateOperatorAST) VisitOr

func (e *IntrprateOperatorAST) VisitOr(v *Or) any

type Lit

type Lit struct{ Value any }

type MapAny

type MapAny = map[string]any

type Not

type Not struct{ Operator }

type Or

type Or []Operator

type OrFields

type OrFields map[string]SyntaxSugar

type RuleOneOf

type RuleOneOf struct {
	Eq interface{} `json:"eq,omitempty"`
	Gt interface{} `json:"gt,omitempty"`
}

type ScoreCalculationFromDescriptionOfBestResult

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

func NewScoreCalculatorFromDescriptionOfBestResult

func NewScoreCalculatorFromDescriptionOfBestResult() *ScoreCalculationFromDescriptionOfBestResult

func (*ScoreCalculationFromDescriptionOfBestResult) Calculate

Calculate is based on rule that - must match - then allow should match calculation, otherwise score is 0 - should - takes and adds score from all should rules - result is final score for given data record

type ScoreCalculationFromHumanFriendlyRules

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

func NewScoreCalculatorFromHumanFriendlyRules

func NewScoreCalculatorFromHumanFriendlyRules() *ScoreCalculationFromHumanFriendlyRules

func (*ScoreCalculationFromHumanFriendlyRules) Calculate

Calculate is based on rule that - must match - then allow should match calculation, otherwise score is 0 - should - takes and adds score from all should rules - result is final score for given data record

type TranslateSyntaxASTtoOperatorAST

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

func (*TranslateSyntaxASTtoOperatorAST) VisitEqTo

func (a *TranslateSyntaxASTtoOperatorAST) VisitEqTo(v *EqTo) any

func (*TranslateSyntaxASTtoOperatorAST) VisitGrThan

func (a *TranslateSyntaxASTtoOperatorAST) VisitGrThan(v *GrThan) any

func (*TranslateSyntaxASTtoOperatorAST) VisitOrFields

func (a *TranslateSyntaxASTtoOperatorAST) VisitOrFields(v *OrFields) any

type ValueBoost

type ValueBoost struct {
	RuleOneOf
}

Jump to

Keyboard shortcuts

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