stardict

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2017 License: MIT Imports: 11 Imported by: 5

README


The code is currently undocumented, and is certainly not idiomatic Go. Pull requests are welcome!

Samples

GO STARDICT

To download and install this package run:

go get -u https://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:

  • Whole dictionary and index are fully 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

Dictionary Functions

func NewDictionary(path string, name string) (*Dictionary, error) - returns gostardict.Dictionary struct. path - path to dictionary files, name - name of dictionary to parse

func (d Dictionary) GetBookName() string - returns dictionary' book name (from ifo file)

func (d Dictionary) GetWordCount() uint64 - returns dictionary' word count (from ifo file)

Work Opportunities

If you need a Golang developer feel free to contact with me :)

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 (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) 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 Sense

type Sense struct {
	Offset uint64
	Size   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

Jump to

Keyboard shortcuts

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