taxonomy

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: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

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

Node defines a node in a taxonomy.

func NewNode

func NewNode(s string) *Node

NewNode creates a new node.

func (*Node) AddChild

func (n *Node) AddChild(c *Node)

AddChild adds a node to the nodes children.

func (*Node) AddSynonym

func (n *Node) AddSynonym(ss ...string)

AddSynonym add a slice of synonyms to the node.

func (*Node) AddTreeNumber

func (n *Node) AddTreeNumber(tn ...string)

AddTreeNumber add a slice of tree numbers to the node.

func (*Node) Categories

func (n *Node) Categories() set.Set

Categories returns all categories of the node and its child nodes.

func (*Node) Leafs

func (n *Node) Leafs() int

Leafs is the number of synonyms of leaf nodes.

func (*Node) Name

func (n *Node) Name() string

Name returns the node's name.

func (*Node) Size

func (n *Node) Size(i, l int) int

Size is the number of nodes at level l.

func (*Node) Synonyms

func (n *Node) Synonyms() set.Set

Synonyms returns all synonyms of the node and its child nodes.

func (*Node) TreeNumbers

func (n *Node) TreeNumbers() set.Set

TreeNumbers returns all tree numbers of the node and its child nodes.

func (*Node) Update

func (n *Node) Update(m *Node) bool

Update finds and updates a node. If no matching node is found, false is returned.

type Nodes

type Nodes []*Node

Nodes defines a slice of nodes.

func LoadNodes

func LoadNodes(fnames ...string) Nodes

LoadNodes loads nodes from a file.

func NewNodes

func NewNodes() Nodes

NewNodes creates a slice of nodes.

func (Nodes) Len

func (ns Nodes) Len() int

Len returns the number of nodes.

type Normalizer

type Normalizer func(string) (string, string)

Normalizer defines a normalizer function to normalize node synonyms.

type Priority

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

Priority defines a priority queue.

func NewPriority

func NewPriority(cap int) *Priority

NewPriority creates a new priority queue.

func (*Priority) Insert

func (p *Priority) Insert(t Term)

Insert inserts a term to the queue.

func (*Priority) Size

func (p *Priority) Size() int

Size returns the number of terms in the queue.

func (*Priority) Terms

func (p *Priority) Terms() Terms

Terms returns the terms in the queue.

type Taxonomy

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

Taxonomy defines a taxonomy for a vocabulary.

func New

func New(r *Node) *Taxonomy

New creates a new taxonomy.

func (*Taxonomy) AddNode

func (t *Taxonomy) AddNode(n *Node) bool

AddNode adds a node to the taxonomy. Nodes with the same name are joined.

func (*Taxonomy) AddNodes

func (t *Taxonomy) AddNodes(ns Nodes) int

AddNodes adds nodes to the taxonomy. Nodes with the same name are joined.

func (*Taxonomy) Candidates

func (t *Taxonomy) Candidates(s string) []int

Candidates finds a set of candidate nodes for given string.

func (*Taxonomy) Info

func (t *Taxonomy) Info()

Info prints basic information about the taxonomy.

func (*Taxonomy) Match

func (t *Taxonomy) Match(s string, d float64, filter set.Set) Terms

Match matches a string to terms in the taxonomy.

func (*Taxonomy) MatchNode

func (t *Taxonomy) MatchNode(n *Node, d float64, filter set.Set) Terms

MatchNode matches a string to terms in the taxonomy.

func (*Taxonomy) Normalize

func (t *Taxonomy) Normalize(f Normalizer)

Normalize normalizes the node synonyms.

func (*Taxonomy) SetBaseIndex

func (t *Taxonomy) SetBaseIndex()

SetBaseIndex sets the index to a slice.

func (*Taxonomy) SetBuffSize

func (t *Taxonomy) SetBuffSize(b int)

SetBuffSize sets the buffer size of the search channel.

func (*Taxonomy) SetHashIndex

func (t *Taxonomy) SetHashIndex(rows, bands int)

SetHashIndex sets the indexing to LSH.

func (*Taxonomy) SetMinScore

func (t *Taxonomy) SetMinScore(p float64)

SetMinScore sets the minimum score below which terms are disregarded.

func (*Taxonomy) SetQueueCapacity

func (t *Taxonomy) SetQueueCapacity(c int)

SetQueueCapacity sets the capacity of the search priority queue.

func (*Taxonomy) Store

func (t *Taxonomy) Store(fname, sep string) error

Store stores the taxonomy to a file.

type Term

type Term struct {
	Key         string
	Normalized  string
	Value       float64
	Categories  set.Set
	TreeNumbers set.Set
}

Term defines a vocabulary term or concept with a Key (e.g., name) and Value (e.g., score).

func NewTerm

func NewTerm(k string, v float64, c set.Set, t set.Set) Term

NewTerm creates a term.

func (Term) PassFilter

func (t Term) PassFilter(filter set.Set) bool

PassFilter returns true if any of the terms categories are in filter.

func (Term) String

func (t Term) String() string

String returns a string representation of the term.

func (Term) TrimCategories

func (t Term) TrimCategories(categories set.Set) Term

TrimCategories removes categories and tree numbers that are not in the categories set.

type Terms

type Terms []Term

Terms define a slice of terms.

func Default

func Default(k, n string) Terms

Default creates a slice of terms with a 0 value term.

func NewTerms

func NewTerms(cap int) Terms

NewTerms creates a slice of terms.

func (Terms) Categories

func (ts Terms) Categories() []string

Categories returns the unique categories of the terms.

func (Terms) Dedupe

func (ts Terms) Dedupe() Terms

Dedupe de-duplicates terms by their keys. Categories and tree numbers of duplicate terms are joined.

func (Terms) Keys

func (ts Terms) Keys() []string

Keys returns the the unique keys of the terms.

func (Terms) Len

func (ts Terms) Len() int

Len returns the number of terms.

func (Terms) MaxKey

func (ts Terms) MaxKey() string

MaxKey returns the key of the term with the largest value. Terms are assumed to be sorted in reverse order by Value.

func (Terms) MaxValue

func (ts Terms) MaxValue() float64

MaxValue returns the largest value. Terms are assumed to be sorted in reverse order by Value.

func (Terms) Normalized

func (ts Terms) Normalized() string

Normalized returns the normalized key.

func (Terms) PassFilter

func (ts Terms) PassFilter(categories set.Set) Terms

PassFilter keeps terms whose categories are in categories filter.

func (Terms) SortByKey

func (ts Terms) SortByKey() Terms

SortByKey sorts terms by key.

func (Terms) SortByValue

func (ts Terms) SortByValue() Terms

SortByValue sorts terms by value in reverse order.

func (Terms) String

func (ts Terms) String() string

String returns a string representation of the terms.

func (Terms) TopDelta

func (ts Terms) TopDelta(d float64) Terms

TopDelta keep terms whose terms are within d of the top term.

func (Terms) TreeNumbers

func (ts Terms) TreeNumbers() []string

TreeNumbers returns the unique tree numbers of the terms.

Jump to

Keyboard shortcuts

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