Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrEmptyIndex indicates that the index has not yet learned any ngrams. ErrEmptyIndex = errors.New("index is empty") // ErrNoResult indicates that no result could be returned. This shouldn't // really happen outside of tests. ErrNoResult = errors.New("no result found") )
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
// N is the number of grams to store per key.
N int
// Store contains the ngrams which have been indexed.
Store stores.Store
// Tokenizer is the tokenizer to use to split strings into tokens.
Tokenizer tk.Tokenizer
}
Index indexes ngrams and provides meachnisms for ngram retrieval and generation.
func NewIndex ¶
NewIndex returns a pointer to an Ngrams Index. It can be initialized with a custom store and tokenizer, otherwise the default in-memory store and latin word tokenizer will be used.
func (*Index) Babble ¶
Babble generates a random sequence of up to n ngrams. The future ngrams will be selected based on their probability. The n value total will include discrete punctuation depending on the tokenizer in use.
type Options ¶
type Options struct {
// Store contains the ngrams which have been indexed.
Store stores.Store
// Tokenizer is the tokenizer to use to split strings into tokens.
Tokenizer tk.Tokenizer
}
Options contains parameters for the ngram indexer.
type Result ¶
type Result struct {
// Prefix is the last token of the key that was matched. It is added
// to a key from the variations to make the next key, eg. Prefix+" "+VKey.
Prefix string
// Next contains the future variations of the ngram and the number of times
// they were indexed (probabilty score).
Next stores.Variations
}
Result contains the result of a ngram lookup.
Click to show internal directories.
Click to hide internal directories.