Copyright | (c) 2016 Al Zohali |
---|---|
License | BSD3 |
Maintainer | Al Zohali <zohl@fmap.me> |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
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
.
- data StarDict = StarDict {}
- data StarDictException
- mkDictionary :: (MonadThrow m, MonadIO m) => IfoFilePath -> Renderer -> m StarDict
- mkDataParser :: Maybe String -> Get [DataEntry]
- data DataEntry
- type Renderer = DataEntry -> Text
- checkFiles :: IfoFilePath -> [FilePath] -> IO (Maybe FilePath)
- checkGZFiles :: IfoFilePath -> [FilePath] -> [FilePath] -> IO (Maybe (Either FilePath FilePath))
- data IfoFile = IfoFile {
- ifoMagicData :: ByteString
- ifoVersion :: String
- ifoBookName :: Text
- ifoWordCount :: Int
- ifoIdxFileSize :: Int
- ifoIdxOffsetBits :: Maybe Int
- ifoSynWordCount :: Maybe Int
- ifoAuthor :: Maybe Text
- ifoEmail :: Maybe Text
- ifoWebsite :: Maybe Text
- ifoDescription :: Maybe Text
- ifoDate :: Maybe UTCTime
- ifoSameTypeSequence :: Maybe String
- ifoDictType :: Maybe String
- type IfoFilePath = FilePath
- readIfoFile :: (MonadThrow m, MonadIO m) => FilePath -> m IfoFile
- indexNumberParser :: IfoFile -> Get Int
- ifoDateFormat :: String
- type Index = Map Text (Int, Int)
- type IndexEntry = (Text, (Int, Int))
- readIndexFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> Get Int -> m Index
- checkDataFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> m FilePath
Documentation
Representation of the dictionary.
data StarDictException Source #
Exceptions that are thrown when something with this module went wrong.
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.
Possible dictionary entry formats.
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.
Representation of .ifo file.
IfoFile | |
|
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.
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.