dictionary

package
v0.0.78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2021 License: Apache-2.0 Imports: 17 Imported by: 5

Documentation

Overview

Chinese-English dictionary database search functions

Chinese-English dictionary file and network loading functions

Package for looking up words and multiword expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDict

func LoadDict(ctx context.Context, database *sql.DB,
	appConfig config.AppConfig) (map[string]dicttypes.Word, error)

LoadDict loads all words from the database

func LoadDictFile added in v0.0.66

func LoadDictFile(appConfig config.AppConfig) (map[string]dicttypes.Word, error)

LoadDictFile loads all words from static files

func LoadDictURL added in v0.0.66

func LoadDictURL(appConfig config.AppConfig, url string) (map[string]dicttypes.Word, error)

Loads all words from a URL

func ValidateDict added in v0.0.18

func ValidateDict(wdict map[string]dicttypes.Word, validator Validator) error

ValidateDict check the Chinese-English for errors

Types

type Dictionary added in v0.0.66

type Dictionary struct {
	// Forward dictionary, lookup by Chinese word
	Wdict       map[string]dicttypes.Word
	HeadwordIds map[int]dicttypes.Word
}

Dictionary is a struct to hold word dictionary indexes

func NewDictionary added in v0.0.66

func NewDictionary(wdict map[string]dicttypes.Word) Dictionary

type NotesProcessor added in v0.0.67

type NotesProcessor struct {
	// contains filtered or unexported fields
}

Processes notes with a regular expression

func NewNotesProcessor added in v0.0.67

func NewNotesProcessor(patternList, replaceList string) NotesProcessor

newNotesProcessor creates a new notesProcessor Param

patternList a list of patterns to match regular expressions, quoted and delimited by commas
replaceList a list of replacement regular expressions, same cardinality

func (NotesProcessor) Process added in v0.0.67

Process checks all senses in the word and replaces note using the regex

type Results

type Results struct {
	Words []dicttypes.Word
}

Encapsulates term lookup recults

type Searcher added in v0.0.5

type Searcher struct {
	// contains filtered or unexported fields
}

Searcher looks up Chinese words by either Chinese or English.

If the dictionary searcher cannot connect to the database then it will run in degraded mode by looking up Chinese words form dictionary file.

func NewSearcher added in v0.0.5

func NewSearcher(ctx context.Context, database *sql.DB) *Searcher

NewSearcher initialize SQL statements

func (*Searcher) FindWordsByEnglish added in v0.0.5

func (searcher *Searcher) FindWordsByEnglish(ctx context.Context,
	query string) ([]dicttypes.WordSense, error)

FindWordsByEnglish returns the word senses with English approximate or Pinyin exact match

func (*Searcher) Initialized added in v0.0.17

func (s *Searcher) Initialized() bool

Initialized returns true if there were no error in initialization.

func (*Searcher) LookupSubstr added in v0.0.5

func (searcher *Searcher) LookupSubstr(ctx context.Context,
	query, topic_en, subtopic_en string) (*Results, error)

Lookup a term based on a substring and a topic

type Validator added in v0.0.18

type Validator interface {
	Validate(pos, domain string) error
}

Performs validation of dictionary entries. Use NewValidator to create a Validator.

func NewValidator added in v0.0.18

func NewValidator(posReader io.Reader, domainReader io.Reader) (Validator, error)

Crates a Validator with the given readers Params:

posReader Reader to load the valid parts of speech from
domainReader Reader to load the valid subject domains

Returns:

An initialized Validator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL