stardict

package module
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 23 Imported by: 1

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"

	I_sametypesequence = "sametypesequence"
	I_idxoffsetbits    = "idxoffsetbits"
)

Variables

View Source
var ErrorHandler = func(err error) {
	log.Println(err)
}

Functions

func NewDictionary

func NewDictionary(path string, name string) (*dictionaryImp, 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) ([]common.Dictionary, error)

Open open directories

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, 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 DictFile added in v2.1.2

type DictFile interface {
	ReadAt(p []byte, off int64) (n int, err error)
	Close() error
}

type DirEntryFromFileInfo added in v2.2.1

type DirEntryFromFileInfo struct {
	fs.FileInfo
}

func (*DirEntryFromFileInfo) Info added in v2.2.1

func (e *DirEntryFromFileInfo) Info() (fs.FileInfo, error)

func (*DirEntryFromFileInfo) Type added in v2.2.1

func (e *DirEntryFromFileInfo) Type() fs.FileMode

type Idx

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

Idx implements an in-memory index for a dictionary

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 {
	// contains filtered or unexported fields
}

type Info

type Info struct {
	Options map[string]string
	Version string
	Is64    bool
	// contains filtered or unexported fields
}

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 WordPrefixMap

type WordPrefixMap map[rune]map[int]struct{}

func (WordPrefixMap) Add

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

Directories

Path Synopsis
cmd
Package dictzip provides a reader for files in the random access `dictzip` format.
Package dictzip provides a reader for files in the random access `dictzip` format.
Native (and fast) implementation of Austin Appleby's MurmurHash3.
Native (and fast) implementation of Austin Appleby's MurmurHash3.

Jump to

Keyboard shortcuts

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