stardict

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: MIT Imports: 14 Imported by: 0

README

GO STARDICT

To download and install this package run:

go get -u github.com/kapmahc/stardict

Source docs: http://godoc.org/github.com/kapmahc/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)
  • Syn files are not processed
  • 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

This section is empty.

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(d string) ([]*Dictionary, error)

Open open directories

func (*Dictionary) GetBookName

func (d *Dictionary) GetBookName() string

GetBookName returns book name

func (*Dictionary) GetWordCount

func (d *Dictionary) GetWordCount() uint64

GetWordCount returns number of words in the dictionary

func (*Dictionary) IterKeywords added in v0.4.0

func (d *Dictionary) IterKeywords(f func(string))

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

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

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

func (*Dictionary) SearchContains added in v0.3.0

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

SearchContains: search all translations for keywords that contain the query

func (*Dictionary) SearchPrefix added in v0.3.0

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

SearchPrefix: search all translations for keywords that start with query

func (*Dictionary) Translate

func (d *Dictionary) Translate(item string) (items []*Translation)

Translate translates given item

type Idx

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

Idx implements an in-memory index for a dictionary

func NewIdx

func NewIdx() *Idx

NewIdx initializes idx struct

func ReadIndex

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

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

func (*Idx) Add

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

Add adds an item to in-memory index

func (Idx) Get

func (idx Idx) Get(item string) []Sense

Get gets all translations for an item

type Info

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

Info contains dictionary options

func ReadInfo

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

ReadInfo reads ifo file and collects dictionary options

type SearchResult added in v0.3.0

type SearchResult struct {
	Keyword string
	Items   []*TranslationItem
}

type Sense

type Sense = [2]uint64

Sense has information belonging to single item position in dictionary

type Translation

type Translation struct {
	Parts []*TranslationItem
}

Translation contains translation items

type TranslationItem

type TranslationItem struct {
	Type rune
	Data []byte
}

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