dict

package
v0.0.0-...-4ad930d Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	YAML_BEGIN = "---"
	YAML_END   = "..."
)

Functions

This section is empty.

Types

type CacheMatcher

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

func (*CacheMatcher) Reset

func (m *CacheMatcher) Reset()

func (*CacheMatcher) Search

func (m *CacheMatcher) Search(key string, useColumn Column, searchVersion int, list []*Entry, resultChan chan<- MatchResultChunk, ctx context.Context)

type ChunkSource

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

func (*ChunkSource) Len

func (e *ChunkSource) Len() int

func (*ChunkSource) String

func (e *ChunkSource) String(i int) string

type Column

type Column string
const (
	COLUMN_TEXT   Column = "TEXT"
	COLUMN_CODE   Column = "CODE"
	COLUMN_WEIGHT Column = "WEIGHT"
	COLUMN_STEM   Column = "STEM"
)

func ParseInput

func ParseInput(raw string, hasStem bool) ([]string, []Column)

Parse input string to a pair of strings 支持乱序输入,如 "你好 nau 1" 或 "nau 1 你好" 解析规则:将原始内容通过空白字符分割成单元,依次判断每个单元是否是汉字、纯数字、ascii, 汉字将作为text,纯数字作为weight,其他ascii根据顺序,前面的将用空格连结合并为code,最后的为stem stem(造字码,用于造词时代替code,比如 的 编码为 u,造字为 un,当造词 我的 时,会用un代替u,最终用tuun造词 我的)

type Data

type Data struct {
	Text   string
	Code   string
	Stem   string
	Weight int
	// contains filtered or unexported fields
}

func ParseData

func ParseData(pair []string, columns *[]Column) (Data, error)

func (*Data) ResetColumns

func (d *Data) ResetColumns(cols *[]Column)

func (*Data) ToString

func (d *Data) ToString() string

func (*Data) ToStringWithColumns

func (d *Data) ToStringWithColumns(cols *[]Column) string

type Dictionary

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

func NewDictionary

func NewDictionary(fes []*FileEntries, matcher Matcher) *Dictionary

func (*Dictionary) Add

func (d *Dictionary) Add(entry *Entry)

func (*Dictionary) Delete

func (d *Dictionary) Delete(entry *Entry)

func (*Dictionary) Entries

func (d *Dictionary) Entries() []*Entry

func (*Dictionary) ExportDict

func (d *Dictionary) ExportDict(path string, columns []Column)

func (*Dictionary) Flush

func (d *Dictionary) Flush() (changed bool)

func (*Dictionary) Len

func (d *Dictionary) Len() int

func (*Dictionary) ResetMatcher

func (d *Dictionary) ResetMatcher()

func (*Dictionary) Search

func (d *Dictionary) Search(key string, useColumn Column, searchVersion int, resultChan chan<- MatchResultChunk, ctx context.Context)

type Entry

type Entry struct {
	FID uint8
	// contains filtered or unexported fields
}

func NewEntry

func NewEntry(raw []byte, fileID uint8, seek int64, size int64, cols *[]Column) *Entry

func NewEntryAdd

func NewEntryAdd(raw string, fileID uint8, data Data) *Entry

func (*Entry) Data

func (e *Entry) Data() *Data

func (*Entry) Delete

func (e *Entry) Delete()

func (*Entry) IsDelete

func (e *Entry) IsDelete() bool

func (*Entry) Raw

func (e *Entry) Raw() string

func (*Entry) ReRaw

func (e *Entry) ReRaw(raw string)

func (*Entry) Saved

func (e *Entry) Saved()

type FileEntries

type FileEntries struct {
	Err      error
	FilePath string
	RawBs    []byte
	Entries  []*Entry
	Columns  []Column
	ID       uint8
}

func LoadItems

func LoadItems(paths ...string) (fes []*FileEntries)

func (*FileEntries) Cmp

func (fe *FileEntries) Cmp(ofe any) bool

func (*FileEntries) Id

func (fe *FileEntries) Id() int

func (*FileEntries) String

func (fe *FileEntries) String() string

type MatchResult

type MatchResult struct {
	Entry *Entry
	// contains filtered or unexported fields
}

func (*MatchResult) Cmp

func (m *MatchResult) Cmp(other any) bool

func (*MatchResult) Id

func (m *MatchResult) Id() int

func (*MatchResult) String

func (m *MatchResult) String() string

type MatchResultChunk

type MatchResultChunk struct {
	Result  []*MatchResult
	Version int
}

type Matcher

type Matcher interface {
	Search(key string, useColumn Column, searchVersion int, list []*Entry, resultChan chan<- MatchResultChunk, ctx context.Context)
	Reset()
}

type ModifyType

type ModifyType int
const (
	NC ModifyType = iota // default no change
	DELETE
	MODIFY // by ReRaw
	ADD    // by NewEntryAdd
)

type YAML

type YAML map[string]any

Jump to

Keyboard shortcuts

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