Documentation
¶
Overview ¶
Package dictdb reads dictd-format dictionaries: a sorted .index of headwords and a .dict.dz body compressed for random access.
Index ¶
- func Clean(entry string) string
- func Lemmas(word string) []string
- func Wrap(s string, width int) []string
- type DB
- type Dictionary
- type Gloss
- type ReaderAtSizer
- type Result
- type Set
- func (s *Set) Add(name string, open func() (Dictionary, error))
- func (s *Set) AddDir(dir, name string) error
- func (s *Set) AddFS(fsys fs.FS, name, indexPath, bodyPath string)
- func (s *Set) Covers(word string) (db, headword string, ok bool)
- func (s *Set) Define(word string) []Result
- func (s *Set) Names() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clean ¶
Clean turns one raw dictionary entry into plain text fit for a terminal. It is safe to run on entries from any of the databases: WordNet and FOLDOC use none of these conventions, so for them it is very nearly a no-op.
func Lemmas ¶
Lemmas returns the base forms to try for a word, best first, when the word itself has no entry.
This matters more than it might seem. /usr/share/dict/words is a spell checker's list, so it carries every inflection -- "abacuses", "overacts", "smoggiest" -- while a dictionary files definitions under the lemma. Around half of all apparent misses are really an inflected form of a headword that is present, so trying the base forms lifts coverage of the word list from roughly 62% to 90%.
The rules are deliberately generous: a wrong guess costs one failed binary search, and the caller keeps the first candidate that actually resolves.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is one dictionary: an index of headwords over a dictzip body.
type Dictionary ¶
type Dictionary interface {
Name() string
Title() string
Lookup(word string) ([]string, error)
Has(word string) bool
}
Dictionary is one source of definitions. Both a dictd database and the generated gloss file satisfy it.
type Gloss ¶
type Gloss struct {
// contains filtered or unexported fields
}
Gloss is a dictionary of one-line entries, used for the names and places that a conventional dictionary does not define.
It exists because the word list carries thousands of surnames and towns -- "Hendricks", "Jaipur" -- that GCIDE and WordNet have no entry for. Confirming that such a spelling is a real surname, and roughly how common, is the useful answer for those; a full dictionary entry neither exists nor is wanted.
Only words that nothing else defines are included, so the file stays at tens of kilobytes rather than the tens of megabytes of the sources it is built from.
func ReadGloss ¶
ReadGloss parses the tab-separated, gzipped gloss file: one word and its text per line, sorted by word.
type ReaderAtSizer ¶
ReaderAtSizer is what a dictionary body must provide: random access and a known size. Both an *os.File and a bytes.Reader over embedded data qualify.
type Result ¶
type Result struct {
DB string // which dictionary, e.g. "gcide"
Title string // its human-readable name
Word string // the headword actually matched, which may be a lemma
Text string // the definition, cleaned for display
}
Result is one definition found for a word.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is an ordered group of dictionaries, consulted in turn.
Order is the whole point: GCIDE is asked first because its 1913 prose is what makes the tool pleasant, and WordNet follows because GCIDE predates most modern vocabulary. The specialist databases come last and cover what neither general dictionary has -- acronyms, computing terms.
Dictionaries are opened lazily. Parsing a 4MB index costs real time, so a dictionary that is never consulted is never read.
func (*Set) Add ¶
func (s *Set) Add(name string, open func() (Dictionary, error))
Add registers a dictionary under a name, to be opened on first use.
func (*Set) AddDir ¶
AddDir registers a dictionary from a directory of dictd files, so an installed dict-gcide or dict-wn is used in preference to the embedded copy.
func (*Set) AddFS ¶
AddFS registers a dictionary held in an fs.FS, which is how the embedded copies are reached. The whole body is read into memory because an fs.File offers no random access; the index is streamed.
func (*Set) Covers ¶
Covers reports whether the word can be defined, and under which headword, without decompressing anything. It exists for measuring coverage over a whole word list, where inflating every entry would be wasteful.