dictionaries-0.1.0.1: Tools to handle StarDict dictionaries.

Copyright(c) 2016 Al Zohali
LicenseBSD3
MaintainerAl Zohali <zohl@fmap.me>
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

NLP.Dictionary.StarDict

Description

Description

Tools for StarDict dictionaries. To load a dictionary you should call mkDictionary with path to .ifo file and render function. Every call of getEntry will perform file reading operation to retrieve requested data. For in-memory version see InMemory.

Synopsis

Documentation

data StarDict Source #

Representation of the dictionary.

data StarDictException Source #

Exceptions that are thrown when something with this module went wrong.

Constructors

WrongIfoFormat FilePath String

Thrown when information file (.ifo) has unsupported format.

IndexNotFound FilePath

Thrown when index file (.idx, .idx.gz) is not found.

WrongIndexFormat FilePath String

Thrown when index file has unsupported format.

DictionaryNotFound FilePath

Thrown when dictionary file (.dict, .dict.dz) has unsupported format.

mkDictionary :: (MonadThrow m, MonadIO m) => IfoFilePath -> Renderer -> m StarDict Source #

Create dictionary.

mkDataParser :: Maybe String -> Get [DataEntry] Source #

Returns parser based on description in .ifo file.

type Renderer = DataEntry -> Text Source #

Type of function to transform dictionary entries to a text.

checkFiles :: IfoFilePath -> [FilePath] -> IO (Maybe FilePath) Source #

Given .ifo file name and list of extensions, returns first existing file with the same basename.

checkGZFiles :: IfoFilePath -> [FilePath] -> [FilePath] -> IO (Maybe (Either FilePath FilePath)) Source #

Given .ifo file name and two lists of extensions, returns first existing file with with the same basename and extension from the first list or (if such file doesn't exists) from the second list.

type IfoFilePath = FilePath Source #

Type synonym to distinguish usage of paths.

readIfoFile :: (MonadThrow m, MonadIO m) => FilePath -> m IfoFile Source #

Read .ifo file at the given path.

indexNumberParser :: IfoFile -> Get Int Source #

Get 32-bit or 64-bit integer depending on description in the .ifo file.

ifoDateFormat :: String Source #

Date format of ifoDate in IfoFile.

type Index = Map Text (Int, Int) Source #

Representation of an .idx file.

type IndexEntry = (Text, (Int, Int)) Source #

Representation of an .idx file entry.

readIndexFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> Get Int -> m Index Source #

Read .idx (.idx.gz) file.

checkDataFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> m FilePath Source #

Returns path of decompressed dictionary.