relation

package
v0.0.0-...-03ea0d3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limit

type Limit struct {
	Incl  bool   `json:"incl"`  // True if limit is inclusive
	Value string `json:"value"` // Value of limit bound
}

Limit defines a lower or upper bound of a numerical relation.

type Relation

type Relation struct {
	ID           variables.ID   `json:"id,omitempty"`
	Name         string         `json:"name"`            // Relation name, typically the variable name
	DisplayName  string         `json:"-"`               // Variable display name
	Unit         string         `json:"unit,omitempty"`  // Variable unit
	Value        []string       `json:"value,omitempty"` // Valid values of categorical relation
	Lower        *Limit         `json:"lower,omitempty"` // Lower bound of numerical relation condition
	Upper        *Limit         `json:"upper,omitempty"` // Upper bound of numerical relation condition
	VariableType variables.Type `json:"variableType"`    // Type of relation
	Score        float64        `json:"score"`           // Confidence estimate of the relation representation being correct
}

Relation defines a boolean, nominal, ordinal, or numerical criterion.

func New

func New() *Relation

New creates a new relation.

func NewCategorical

func NewCategorical(v *variables.Variable, answer []string, score float64) *Relation

NewCategorical creates a new relation of type boolean, nominal, or ordinal.

func Parse

func Parse(s string) *Relation

Parse parsers the json string to the relation.

func (*Relation) HumanReadable

func (r *Relation) HumanReadable() string

HumanReadable converts the relation to the human readable form.

func (*Relation) JSON

func (r *Relation) JSON() string

JSON converts the relation to the json string.

func (*Relation) Less

func (r *Relation) Less(q *Relation) bool

Less compares two numerical relations by their limits.

func (*Relation) Negate

func (r *Relation) Negate(valueRange []string)

Negate negates the relation.

func (*Relation) Normalize

func (r *Relation) Normalize(valueRange []string)

Normalize normalizes the relation by making the relation content consistent with the variable type.

func (*Relation) SetScore

func (r *Relation) SetScore(score float64)

SetScore sets the confidence score that the relation is parsed correctly.

func (*Relation) SetUnitField

func (r *Relation) SetUnitField(v *variables.Variable)

SetUnitField sets the variable unit to the default value if the unit missing.

func (*Relation) SetVariableFields

func (r *Relation) SetVariableFields(v *variables.Variable)

SetVariableFields sets the variable display name and type per variable id.

func (*Relation) Split

func (r *Relation) Split() Relations

Split splits the combination relation into individual relations. Because such relations may not have a valid ID, the split operation needs to be done before validation.

func (*Relation) Transform

func (r *Relation) Transform()

Transform transforms criteria relations by converting parsed values to strings of valid literals. If a valid literal cannot be inferred, the confidence score of the relation is set to zero. Indifferent nominal relations are removed by setting the confidence score to zero.

func (*Relation) Valid

func (r *Relation) Valid() bool

Valid returns false if the relation's name is empty, the ordinal variable has an empty value set, or the numerical variable has no limits.

type Relations

type Relations []*Relation

Relations defines a slice of relations.

func NewRelations

func NewRelations() Relations

NewRelations creates an empty slice of relations.

func (*Relations) Dedupe

func (rs *Relations) Dedupe()

Dedupe removes the duplicate relations.

func (Relations) Empty

func (rs Relations) Empty() bool

Empty returns true if the relations has no relation elements.

func (Relations) JSON

func (rs Relations) JSON() string

JSON converts the the relations slice to the json string.

func (Relations) MinScore

func (rs Relations) MinScore() float64

MinScore returns the minimum score of the relations.

func (Relations) Negate

func (rs Relations) Negate()

Negate negates the relations.

func (*Relations) Process

func (rs *Relations) Process()

Process splits the relations if needed, sets the correct types, normalizes and removes invalid relations.

func (Relations) SetScore

func (rs Relations) SetScore(score float64)

SetScore sets the confidence score that the relations are parsed correctly.

func (Relations) Sort

func (rs Relations) Sort()

Sort sorts relations by their id.

func (Relations) Transform

func (rs Relations) Transform()

Transform transforms the relations.

func (Relations) VariableIDs

func (rs Relations) VariableIDs() []variables.ID

VariableIDs returns the variable ids contained in the relations.

Jump to

Keyboard shortcuts

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