Documentation ¶
Index ¶
- type Provider
- type Vocabulary
- func (c *Vocabulary) Add(term string) int
- func (c *Vocabulary) ID(term string) (int, bool)
- func (c *Vocabulary) Items() []string
- func (c *Vocabulary) LongestPrefix(term string) string
- func (c *Vocabulary) Map() map[string]int
- func (c Vocabulary) MarshalBinary() ([]byte, error)
- func (c *Vocabulary) MustID(term string) int
- func (c *Vocabulary) MustTerm(id int) string
- func (c *Vocabulary) Size() int
- func (c *Vocabulary) Term(id int) (string, bool)
- func (c *Vocabulary) UnmarshalBinary(data []byte) error
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 ¶
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) 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) Map ¶
func (c *Vocabulary) Map() map[string]int
func (Vocabulary) MarshalBinary ¶
func (c Vocabulary) MarshalBinary() ([]byte, error)
MarshalBinary marshals a Vocabulary into binary form.
func (*Vocabulary) MustID ¶
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) 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 ¶
func (c *Vocabulary) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals a binary representation of a Vocabulary.