stardict

package module
v0.0.0-...-cf3773c Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

go-stardict

Go Reference Tests Go Report Card

A stardict dictionary library for Go.

Status

The API is currently unstable and will change. This package will use module version numbering to manage versions and compatibility.

Features

  • [x] Reading dictionary metadata.
  • [x] Reading & searching the dictionary index.
  • [x] Reading full dictionary articles.
  • [x] Efficient access for large files.
  • [x] Dictzip support.
  • [x] Support for concurrent access.
  • [ ] Synonym support (.syn file).
  • [ ] Support for tree dictionaries (.tdx file).
  • [ ] Support for Resource Storage (res/ directory).

Installation

To install this package run

go get github.com/ianlewis/go-stardict

Examples

You can search a stardict dictionary directly and list the entries.

// Open dictonaries in a directory
dictionaries, _ := stardict.OpenAll(".")

// Search the dictionaries.
for _, d := range dictionaries {
  entries, _ := d.Search("banana")
  for _, e := range entries {
    // Print out matching index entries.
    fmt.Println(e)
  }
}

References

Documentation

Overview

Package stardict implements a library for reading stardict dictionaries in pure Go.

Stardict dictionaries contain several files:

  1. An .ifo file that contains metadata about the dictionary.
  2. An .idx file that contains the dictionary index. It contains search entries and associated offsets into the .dict file. The index file can be compressed using gzip.
  3. A .dict file that contains the dictionary's main article data. The dict file can be compressed using the dictzip format.
  4. An optional .syn file that contains synonyms which link index entries.
  5. A .tdx file is present for "tree dictionaries" and is used instead of the .idx file.

More info on on the dictionary format can be found at this URL: https://github.com/huzheng001/stardict-3/blob/master/dict/doc/StarDictFileFormat

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

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

Entry is a dictionary entry.

func (*Entry) Data

func (e *Entry) Data() []*dict.Data

Data returns the entry's data entries.

func (*Entry) String

func (e *Entry) String() string

String returns a string representation of the Entry.

func (*Entry) Title

func (e *Entry) Title() string

Title return the entry's title.

type Stardict

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

Stardict is a stardict dictionary.

func Open

func Open(path string) (*Stardict, error)

Open opens a Stardict dictionary from the given .ifo file path.

func OpenAll

func OpenAll(path string) ([]*Stardict, []error)

OpenAll opens all dictionaries under a directory. This function will return all successfully opened dictionaries along with any errors that occurred.

func (*Stardict) Author

func (s *Stardict) Author() string

Author returns the dictionary author.

func (*Stardict) Bookname

func (s *Stardict) Bookname() string

Bookname returns the dictionary name.

func (*Stardict) Close

func (s *Stardict) Close() error

Close closes the dict and any underlying readers.

func (*Stardict) Description

func (s *Stardict) Description() string

Description returns the dictionary description.

func (*Stardict) Dict

func (s *Stardict) Dict() (*dict.Dict, error)

Dict returns the dictionary's dict.

func (*Stardict) Email

func (s *Stardict) Email() string

Email returns the dictionary contact email.

func (*Stardict) Index

func (s *Stardict) Index() (*idx.Idx, error)

Index returns a simple in-memory version of the dictionary's index.

func (*Stardict) IndexScanner

func (s *Stardict) IndexScanner() (*idx.Scanner, error)

IndexScanner returns a new index scanner. The caller assumes ownership of the underlying reader so Close should be called on the scanner when finished.

func (*Stardict) Search

func (s *Stardict) Search(query string) ([]*Entry, error)

Search performs a simple full text search of the dictionary for the given query and returns dictionary entries.

func (*Stardict) Version

func (s *Stardict) Version() string

Version returns the dictionary format version.

func (*Stardict) Website

func (s *Stardict) Website() string

Website returns the dictionary website url.

func (*Stardict) WordCount

func (s *Stardict) WordCount() int64

WordCount returns the dictionary word count.

Directories

Path Synopsis
cmd
Package dict implements reading .dict files.
Package dict implements reading .dict files.
Package idx implements reading .idx files.
Package idx implements reading .idx files.
Package ifo implements reading .ifo files.
Package ifo implements reading .ifo files.

Jump to

Keyboard shortcuts

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