stardict

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: GPL-3.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	I_bookname    = "bookname"
	I_wordcount   = "wordcount"
	I_description = "description"
	I_idxfilesize = "idxfilesize"
)

Variables

This section is empty.

Functions

func ApplyDictsOrder

func ApplyDictsOrder(order map[string]int)

func CloseDictFiles

func CloseDictFiles()

func GetInfoList

func GetInfoList() []common.Info

func Init

func Init(directoryList []string, order map[string]int)

func LookupHTML

func LookupHTML(
	query string,
	conf *config.Config,
	dictsOrder map[string]int,
) []common.QueryResult

func Reorder

func Reorder(order map[string]int)

Types

type DicListSorter

type DicListSorter struct {
	Order map[string]int
	List  []*Dictionary
}

func (DicListSorter) Len

func (s DicListSorter) Len() int

func (DicListSorter) Less

func (s DicListSorter) Less(i, j int) bool

func (DicListSorter) Swap

func (s DicListSorter) Swap(i, j int)

type Dict

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

Dict implements in-memory dictionary

func ReadDict

func ReadDict(filename string, info *Info) (*Dict, error)

ReadDict creates Dict and opens .dict file

func (*Dict) Close

func (d *Dict) Close()

func (*Dict) GetSequence

func (d *Dict) GetSequence(offset uint64, size uint64) []byte

GetSequence returns data at the given offset

func (*Dict) Open

func (d *Dict) Open() error

type Dictionary

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

Dictionary stardict dictionary

func NewDictionary

func NewDictionary(path string, name string) (*Dictionary, error)

NewDictionary returns a new Dictionary path - path to dictionary files name - name of dictionary to parse

func Open

func Open(dirPathList []string, order map[string]int) ([]*Dictionary, error)

Open open directories

func (*Dictionary) DictName

func (d *Dictionary) DictName() string

DictName returns book name

func (*Dictionary) EntryCount

func (d *Dictionary) EntryCount() uint64

EntryCount returns number of entries in the dictionary

func (*Dictionary) ResourceDir

func (d *Dictionary) ResourceDir() string

func (*Dictionary) ResourceURL

func (d *Dictionary) ResourceURL() string

func (*Dictionary) Search

func (d *Dictionary) Search(query string) []*SearchResult

Search: first try an exact match then search all translations for terms that contain the query but sort the one that have it as prefix first

type Idx

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

Idx implements an in-memory index for a dictionary

func NewIdx

func NewIdx(entryCount int) *Idx

NewIdx initializes idx struct

func ReadIndex

func ReadIndex(filename string, synPath string, info *Info) (*Idx, error)

ReadIndex reads dictionary index into a memory and returns in-memory index structure

func (*Idx) Add

func (idx *Idx) Add(term string, offset uint64, size uint64) int

Add adds an item to in-memory index

type IdxEntry

type IdxEntry struct {
	Terms  []string
	Offset uint64
	Size   uint64
}

type Info

type Info struct {
	Options  map[string]string
	Version  string
	Is64     bool
	Disabled bool
}

Info contains dictionary options

func ReadInfo

func ReadInfo(filename string) (info *Info, err error)

ReadInfo reads ifo file and collects dictionary options

func (Info) Description

func (info Info) Description() string

func (Info) DictName

func (info Info) DictName() string

func (Info) EntryCount

func (info Info) EntryCount() (int, error)

EntryCount returns number of words in the dictionary

func (Info) IndexFileSize

func (info Info) IndexFileSize() uint64

func (Info) MaxIdxBytes

func (info Info) MaxIdxBytes() int

type QueryResultImp

type QueryResultImp struct {
	*SearchResult
	// contains filtered or unexported fields
}

func (*QueryResultImp) DefinitionsHTML

func (r *QueryResultImp) DefinitionsHTML() []string

func (*QueryResultImp) DictName

func (r *QueryResultImp) DictName() string

func (*QueryResultImp) ResourceDir

func (r *QueryResultImp) ResourceDir() string

func (*QueryResultImp) Score

func (r *QueryResultImp) Score() uint8

func (*QueryResultImp) Terms

func (r *QueryResultImp) Terms() []string

type SearchResult

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

type SearchResultItem

type SearchResultItem struct {
	Data []byte
	Type rune
}

SearchResultItem contain single translation item

type WordPrefixMap

type WordPrefixMap map[rune]map[int]bool

func (WordPrefixMap) Add

func (wpm WordPrefixMap) Add(term string, termIndex int)

Jump to

Keyboard shortcuts

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