Documentation
¶
Overview ¶
Package tokenize converts license text into normalized integer tokens.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ID ¶
type ID uint32
ID identifies a normalized word in a Vocabulary.
const Unknown ID = 0
Unknown is the ID assigned to words absent from a Vocabulary.
type Vocabulary ¶
type Vocabulary struct {
// contains filtered or unexported fields
}
Vocabulary is an immutable mapping from normalized words to integer IDs.
func NewVocabulary ¶
func NewVocabulary(texts [][]byte) (*Vocabulary, error)
NewVocabulary builds a deterministic vocabulary from texts. IDs are assigned in normalized lexical order and start at one, leaving zero for Unknown.
func NewVocabularyFromWords ¶
func NewVocabularyFromWords(words []string) (*Vocabulary, error)
NewVocabularyFromWords loads an already normalized and sorted vocabulary.
func (*Vocabulary) Len ¶
func (v *Vocabulary) Len() int
Len returns the number of known words, excluding Unknown.
func (*Vocabulary) Lookup ¶
func (v *Vocabulary) Lookup(word string) (ID, bool)
Lookup returns the ID for a normalized word.
func (*Vocabulary) Tokenize ¶
func (v *Vocabulary) Tokenize(input []byte) Tokens
Tokenize normalizes input and maps every word to an ID and byte range.
func (*Vocabulary) Word ¶
func (v *Vocabulary) Word(id ID) string
Word returns the normalized word for id, or an empty string for an unknown ID.
func (*Vocabulary) Words ¶
func (v *Vocabulary) Words() []string
Words returns the normalized words in ID order, excluding Unknown.