stardict

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 17 Imported by: 0

README

GO STARDICT

To download and install this package run:

go get -u github.com/ilius/go-stardict

Source docs: http://godoc.org/github.com/ilius/go-stardict

Disclaimer Sample code can be found in dict_test.go.

Project Overview

The project was started as an attempt to read stardict dictionaries in language learning webservice and grew into a tool supporting several dictionary formats.

Current limitations:

  • Index file is loaded into memory for fast random access
  • DictZip format is not supported, it is processed as a simple GZip format (means that no random blocks access is supported as in DictZip)
  • There's no recovering from errors (means that dictionaries should be well formed)

Not tested but should be working in theory (I didn't find dictionaries with those properties in place):

  • 64bit offsets
  • multi typed dictionary fields

Thanks

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type Dict

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

Dict implements in-memory dictionary

func ReadDict

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

ReadDict reads dictionary into memory

func (Dict) GetSequence

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

GetSequence returns data at the given offset

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 added in v0.3.0

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

Open open directories

func (*Dictionary) BookName added in v1.0.0

func (d *Dictionary) BookName() string

BookName returns book name

func (*Dictionary) EntryCount added in v1.0.0

func (d *Dictionary) EntryCount() uint64

EntryCount returns number of entries in the dictionary

func (*Dictionary) ResourceDir added in v0.4.0

func (d *Dictionary) ResourceDir() string

func (*Dictionary) ResourceURL added in v0.4.0

func (d *Dictionary) ResourceURL() string

func (*Dictionary) Search added in v1.0.0

func (d *Dictionary) Search(query string, cutoff int) []*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 added in v1.0.0

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) BookName added in v1.0.0

func (info Info) BookName() string

func (Info) Description added in v1.0.0

func (info Info) Description() string

func (Info) IndexFileSize added in v1.0.0

func (info Info) IndexFileSize() uint64

func (Info) MaxIdxBytes added in v1.0.0

func (info Info) MaxIdxBytes() int

func (Info) WordCount added in v1.0.0

func (info Info) WordCount() uint64

WordCount returns number of words in the dictionary

type SearchResult added in v0.3.0

type SearchResult struct {
	Terms []string
	Items []*TranslationItem
	Score uint8
}

type Translation

type Translation struct {
	Parts []*TranslationItem
}

Translation contains translation items

type TranslationItem

type TranslationItem struct {
	Data []byte
	Type rune
}

TranslationItem contain single translation item

Directories

Path Synopsis
cmd
sdcvgo command

Jump to

Keyboard shortcuts

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