Copyright | (c) 2016 Al Zohali |
---|---|
License | BSD3 |
Maintainer | Al Zohali <zohl@fmap.me> |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
NLP.Dictionary.StarDict.Common
Description
Description
Common functions and types for StarDict dictionaries.
- data StarDictException
- 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
- ifoDateFormat :: String
- readIfoFile :: (MonadThrow m, MonadIO m) => FilePath -> m IfoFile
- renderIfoFile :: IfoFile -> Text
- type IndexEntry = (Text, (Int, Int))
- readIndexFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> Get Int -> m [IndexEntry]
- renderIndexFile :: [IndexEntry] -> (Int -> Builder) -> ByteString
- getIndexNumber :: Maybe Int -> Get Int
- putIndexNumber :: Maybe Int -> Int -> Builder
- checkDataFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> m FilePath
- data DataEntry
- type Renderer = DataEntry -> Text
- mkDataParser :: Maybe String -> Get [DataEntry]
- class Dictionary d => StarDict d where
Documentation
data StarDictException #
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. |
Instances
checkFiles :: IfoFilePath -> [FilePath] -> IO (Maybe FilePath) #
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)) #
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.
Constructors
IfoFile | |
Fields
|
type IfoFilePath = FilePath #
Type synonym to distinguish usage of paths.
ifoDateFormat :: String #
Date format of ifoDate
in IfoFile.
readIfoFile :: (MonadThrow m, MonadIO m) => FilePath -> m IfoFile #
Read .ifo file at the given path.
renderIfoFile :: IfoFile -> Text #
Generates .ifo file contents based on IfoFile
type IndexEntry = (Text, (Int, Int)) #
Representation of an .idx file entry.
readIndexFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> Get Int -> m [IndexEntry] #
Read .idx (.idx.gz) file.
renderIndexFile :: [IndexEntry] -> (Int -> Builder) -> ByteString #
Generates .idx file contents based on Index
.
getIndexNumber :: Maybe Int -> Get Int #
Get 32-bit or 64-bit integer depending on description in the .ifo file.
putIndexNumber :: Maybe Int -> Int -> Builder #
Put 32-bit or 64-bit integer depending on description in the .ifo file.
checkDataFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> m FilePath #
Returns path of decompressed dictionary.
Possible dictionary entry formats.
class Dictionary d => StarDict d where #
Classtype for stardict dictionaries.
Minimal complete definition
Methods
getIfoFile :: d -> IfoFile #
mkDictionary :: (MonadThrow m, MonadIO m) => Tagged d IfoFilePath -> Renderer -> m d #