vocabulary

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	Vocabulary() *Vocabulary
}

Provider is an interface for exposing a vocabulary.

type Vocabulary

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

Vocabulary is a vocabulary of term/ID associations.

func New

func New(terms []string) *Vocabulary

New returns a new vocabulary populated with the terms.

func NewFromFile

func NewFromFile(path string) (*Vocabulary, error)

NewFromFile returns a new vocabulary populated with the content of a file.

func (*Vocabulary) Add

func (c *Vocabulary) Add(term string) int

Add adds a term to the vocabulary and returns its ID. If a term was already in the corpus, it just returns the ID.

func (*Vocabulary) ID added in v0.2.0

func (c *Vocabulary) ID(term string) (int, bool)

ID returns the ID of a term and whether or not it was found in the vocabulary.

func (*Vocabulary) Items

func (c *Vocabulary) Items() []string

Items returns all items.

func (*Vocabulary) LongestPrefix

func (c *Vocabulary) LongestPrefix(term string) string

LongestPrefix returns the longest term in the vocabulary that is the prefix of the input term

func (Vocabulary) MarshalBinary added in v0.4.0

func (c Vocabulary) MarshalBinary() ([]byte, error)

MarshalBinary marshals a Vocabulary into binary form.

func (*Vocabulary) MustID added in v0.2.0

func (c *Vocabulary) MustID(term string) int

MustID returns the ID of a term. It panics if the term is not in the vocabulary.

func (*Vocabulary) MustTerm

func (c *Vocabulary) MustTerm(id int) string

MustTerm returns the term given the ID. It panics if the term is not in the vocabulary.

func (*Vocabulary) Size

func (c *Vocabulary) Size() int

Size returns the size of the vocabulary.

func (*Vocabulary) Term

func (c *Vocabulary) Term(id int) (string, bool)

Term returns the term given the ID, and whether or not it was found in the vocabulary.

func (*Vocabulary) UnmarshalBinary added in v0.4.0

func (c *Vocabulary) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a binary representation of a Vocabulary.

Jump to

Keyboard shortcuts

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