Documentation
¶
Overview ¶
Aho–Corasick algorithm Refer to https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm https://www.youtube.com/watch?v=O7_w001f58c https://www.youtube.com/watch?v=OFKxWFew_L0
package sources defines the interface of a "dictionary", input a _string_, get the RAW content in the dictionary, might include the definitions/css files/renderers/...
Index ¶
- Constants
- Variables
- func ActiveDefinitionTokenizer() string
- func AllCss() string
- func BuildDefinitionSearchIndex(db *sql.DB, tokenizer string) error
- func Complete(query string, mode CompletionMode, limit int) []string
- func DefinitionSearchReady() error
- func DumpMDXFilesToSQLite(dbPath string, mdxPaths []string, limit int, tokenizer string) error
- func GetFromLDOCE(word string) string
- func GetMDDFile(name string) []byte
- func IsDumpComplete(dbPath string) bool
- func LoadConfig() error
- func QueryByURL(word string) string
- func QueryMDX(word string, f string) string
- func Restore()
- func Store()
- type AhoCorasick
- type CompletionMode
- type Config
- type DBDict
- type DBIExact
- type DefinitionIndexConfig
- type DefinitionMatch
- type DefinitionSearchError
- type Dict
- type DictConfig
- type Dicts
- type Exact
- type IExact
- type Map
- type MdxDict
- type RawOutput
- type SearchConfig
- type Searcher
- type Source
Constants ¶
const ( DefinitionTokenizerUnicode61 = "unicode61" DefinitionTokenizerTrigram = "trigram" )
Variables ¶
var G = &Dicts{}
var Gbold = "**"
var Gitalic = "*"
var OnMDDDumped func()
OnMDDDumped is an optional callback invoked after MDD resources are successfully extracted. Set this before calling G.Load() to write a marker file on mobile so the dump is skipped on subsequent launches.
Functions ¶
func ActiveDefinitionTokenizer ¶ added in v0.6.0
func ActiveDefinitionTokenizer() string
func AllCss ¶ added in v0.7.0
func AllCss() string
AllCss returns the concatenated CSS for all loaded dictionaries. Used by the mobile direct-render path to inject styles without an HTTP round-trip.
func BuildDefinitionSearchIndex ¶ added in v0.6.0
func Complete ¶ added in v0.6.0
func Complete(query string, mode CompletionMode, limit int) []string
func DefinitionSearchReady ¶ added in v0.6.0
func DefinitionSearchReady() error
func DumpMDXFilesToSQLite ¶ added in v0.6.0
func GetFromLDOCE ¶
func GetMDDFile ¶ added in v0.6.0
GetMDDFile looks up a resource file (e.g. "GB_hello0205.mp3") across all loaded MDD dictionaries and returns its raw bytes. Returns nil if not found.
func IsDumpComplete ¶ added in v0.6.0
IsDumpComplete returns true only when vocab.db exists and was fully written.
func LoadConfig ¶
func LoadConfig() error
func QueryByURL ¶
Types ¶
type AhoCorasick ¶
type AhoCorasick struct {
// contains filtered or unexported fields
}
func (*AhoCorasick) GetRawOutputs ¶
func (ack *AhoCorasick) GetRawOutputs(input string) []RawOutput
type CompletionMode ¶ added in v0.6.0
type CompletionMode string
const ( CompletionPrefix CompletionMode = "prefix" CompletionFuzzy CompletionMode = "fzf" )
func ParseCompletionMode ¶ added in v0.6.0
func ParseCompletionMode(mode string) CompletionMode
type Config ¶
type Config struct {
Dicts []DictConfig `json:"dicts"`
Search SearchConfig `json:"search"`
}
func DefaultConfig ¶ added in v0.6.0
func DefaultConfig() Config
func ReadConfig ¶ added in v0.6.0
type DBDict ¶ added in v0.3.0
type DBDict struct {
}
func (*DBDict) Complete ¶ added in v0.6.0
func (d *DBDict) Complete(query string, mode CompletionMode, limit int) []string
func (*DBDict) WordsWithPrefix ¶ added in v0.3.0
type DBIExact ¶ added in v0.3.0
type DBIExact struct {
}
IExact is a case in-sensitive search source, no other fuzzy searching algos.
func (*DBIExact) GetRawOutputs ¶ added in v0.3.0
type DefinitionIndexConfig ¶ added in v0.6.0
type DefinitionIndexConfig struct {
Tokenizer string `json:"tokenizer"`
}
type DefinitionMatch ¶ added in v0.6.0
func SearchDefinitions ¶ added in v0.6.0
func SearchDefinitions(query string, limit int) ([]DefinitionMatch, error)
type DefinitionSearchError ¶ added in v0.6.0
type DefinitionSearchError struct {
Reason string
}
func (*DefinitionSearchError) Error ¶ added in v0.6.0
func (e *DefinitionSearchError) Error() string
type DictConfig ¶ added in v0.0.7
type Exact ¶ added in v0.0.7
type Exact struct {
// contains filtered or unexported fields
}
Exact is a case sensitive search source, only matching the key(s) that is "exactly" the same
func (*Exact) GetRawOutputs ¶ added in v0.0.7
type IExact ¶ added in v0.2.0
type IExact struct {
// contains filtered or unexported fields
}
IExact is a case in-sensitive search source, no other fuzzy searching algos.
func (*IExact) GetRawOutputs ¶ added in v0.2.0
type MdxDict ¶
type MdxDict struct {
// SourceType
Type string
// For personal usage example, "oald9.json", or "Longman Dictionary of Contemporary English"
MdxFile string
MdxDict Dict // TODO: it's "embedded" in the searcher, maybe we can reduce mem usage when apply non-plain search algorithms.
// contains filtered or unexported fields
}
type SearchConfig ¶ added in v0.6.0
type SearchConfig struct {
DefinitionIndex DefinitionIndexConfig `json:"definition_index"`
}
type Searcher ¶
func NewDBIExact ¶ added in v0.3.0
func NewDBIExact() Searcher