-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Tools to handle StarDict dictionaries.
--   
--   Tools to handle StarDict dictionaries.
@package dictionaries
@version 0.2.0.4


module NLP.Dictionary

-- | Core type class that provides interface to dictionaries.
class Dictionary a
getEntries :: Dictionary a => Text -> a -> IO [Text]


-- | <h1>Description</h1>
--   
--   Common functions and types for StarDict dictionaries.
module NLP.Dictionary.StarDict.Common

-- | Exceptions that are thrown when something with this module went wrong.
data StarDictException

-- | Thrown when information file (.ifo) has unsupported format.
WrongIfoFormat :: FilePath -> String -> StarDictException

-- | Thrown when index file (.idx, .idx.gz) is not found.
IndexNotFound :: FilePath -> StarDictException

-- | Thrown when index file has unsupported format.
WrongIndexFormat :: FilePath -> String -> StarDictException

-- | Thrown when dictionary file (.dict, .dict.dz) has unsupported format.
DictionaryNotFound :: FilePath -> StarDictException

-- | Given .ifo file name and list of extensions, returns first existing
--   file with the same basename.
checkFiles :: IfoFilePath -> [FilePath] -> IO (Maybe 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.
checkGZFiles :: IfoFilePath -> [FilePath] -> [FilePath] -> IO (Maybe (Either FilePath FilePath))

-- | Representation of .ifo file.
data IfoFile
IfoFile :: ByteString -> String -> Text -> Int -> Int -> Maybe Int -> Maybe Int -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe UTCTime -> Maybe String -> Maybe String -> IfoFile

-- | Corresponds to the first string in the file.
[ifoMagicData] :: IfoFile -> ByteString

-- | Corresponds to version field.
[ifoVersion] :: IfoFile -> String

-- | Corresponds to bookname field.
[ifoBookName] :: IfoFile -> Text

-- | Corresponds to wordcount field.
[ifoWordCount] :: IfoFile -> Int

-- | Corresponds to idxfilesize field.
[ifoIdxFileSize] :: IfoFile -> Int

-- | Corresponds to idxoffsetbits field.
[ifoIdxOffsetBits] :: IfoFile -> Maybe Int

-- | Corresponds to synwordcount field.
[ifoSynWordCount] :: IfoFile -> Maybe Int

-- | Corresponds to author field.
[ifoAuthor] :: IfoFile -> Maybe Text

-- | Corresponds to email field.
[ifoEmail] :: IfoFile -> Maybe Text

-- | Corresponds to website field.
[ifoWebsite] :: IfoFile -> Maybe Text

-- | Corresponds to description field.
[ifoDescription] :: IfoFile -> Maybe Text

-- | Corresponds to date field.
[ifoDate] :: IfoFile -> Maybe UTCTime

-- | Corresponds to sametypesequence field.
[ifoSameTypeSequence] :: IfoFile -> Maybe String
[ifoDictType] :: IfoFile -> Maybe String

-- | Type synonym to distinguish usage of paths.
type IfoFilePath = FilePath

-- | Date format of <a>ifoDate</a> in IfoFile.
ifoDateFormat :: String

-- | Read .ifo file at the given path.
readIfoFile :: (MonadThrow m, MonadIO m) => FilePath -> m IfoFile

-- | Generates .ifo file contents based on <a>IfoFile</a>
renderIfoFile :: IfoFile -> Text

-- | Representation of an .idx file entry.
type IndexEntry = (Text, (Int, Int))

-- | Read .idx (.idx.gz) file.
readIndexFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> Get Int -> m [IndexEntry]

-- | Generates .idx file contents based on <tt>Index</tt>.
renderIndexFile :: [IndexEntry] -> (Int -> Builder) -> ByteString

-- | Get 32-bit or 64-bit integer depending on description in the .ifo
--   file.
getIndexNumber :: Maybe Int -> Get Int

-- | Put 32-bit or 64-bit integer depending on description in the .ifo
--   file.
putIndexNumber :: Maybe Int -> (Int -> Builder)

-- | Returns path of decompressed dictionary.
checkDataFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> m FilePath

-- | Possible dictionary entry formats.
data DataEntry
UTF8Text :: Text -> DataEntry
LocaleText :: Text -> DataEntry
Pango :: Text -> DataEntry
Phonetics :: Text -> DataEntry
XDXF :: Text -> DataEntry
CJK :: Text -> DataEntry
PowerWord :: Text -> DataEntry
MediaWiki :: Text -> DataEntry
HTML :: Text -> DataEntry
Resource :: [FilePath] -> DataEntry
WAVEAudio :: ByteString -> DataEntry
Picture :: ByteString -> DataEntry
Reserved :: ByteString -> DataEntry

-- | Type of function to transform dictionary entries to a text.
type Renderer = DataEntry -> Text

-- | Returns parser based on description in .ifo file.
mkDataParser :: Maybe String -> Get [DataEntry]

-- | Classtype for stardict dictionaries.
class (Dictionary d) => StarDict d
getIfoFile :: StarDict d => d -> IfoFile
mkDictionary :: (StarDict d, MonadThrow m, MonadIO m) => Tagged d IfoFilePath -> Renderer -> m d
instance GHC.Show.Show NLP.Dictionary.StarDict.Common.DataEntry
instance GHC.Classes.Eq NLP.Dictionary.StarDict.Common.DataEntry
instance GHC.Generics.Generic NLP.Dictionary.StarDict.Common.IfoFile
instance GHC.Show.Show NLP.Dictionary.StarDict.Common.IfoFile
instance GHC.Classes.Eq NLP.Dictionary.StarDict.Common.IfoFile
instance GHC.Show.Show NLP.Dictionary.StarDict.Common.StarDictException
instance GHC.Classes.Eq NLP.Dictionary.StarDict.Common.StarDictException
instance Control.DeepSeq.NFData NLP.Dictionary.StarDict.Common.IfoFile
instance GHC.Exception.Exception NLP.Dictionary.StarDict.Common.StarDictException


-- | <h1>Description</h1>
--   
--   Tools for StarDict dictionaries. This module (re)exports core classes
--   that are needed to work with dictionaries. To create dictionary, use
--   <a>mkDictionary</a> method together with <tt>tag</tt> from one of
--   implementations:
--   
--   <pre>
--   import NLP.Dictionary.StarDict (StarDict(..))
--   import qualified NLP.Dictionery.StarDict.Regular as SDR
--   
--   ...
--   
--     dictionary &lt;- mkDictionary (SDR.tag "<i>path</i>to<i>a</i>dictionary.ifo") renderer
--   
--   </pre>
module NLP.Dictionary.StarDict

-- | Possible dictionary entry formats.
data DataEntry
UTF8Text :: Text -> DataEntry
LocaleText :: Text -> DataEntry
Pango :: Text -> DataEntry
Phonetics :: Text -> DataEntry
XDXF :: Text -> DataEntry
CJK :: Text -> DataEntry
PowerWord :: Text -> DataEntry
MediaWiki :: Text -> DataEntry
HTML :: Text -> DataEntry
Resource :: [FilePath] -> DataEntry
WAVEAudio :: ByteString -> DataEntry
Picture :: ByteString -> DataEntry
Reserved :: ByteString -> DataEntry

-- | Type of function to transform dictionary entries to a text.
type Renderer = DataEntry -> Text

-- | Classtype for stardict dictionaries.
class (Dictionary d) => StarDict d
getIfoFile :: StarDict d => d -> IfoFile
mkDictionary :: (StarDict d, MonadThrow m, MonadIO m) => Tagged d IfoFilePath -> Renderer -> m d


-- | <h1>Description</h1>
--   
--   Implementation of an in-memory dictionary. All the entries will be
--   loaded in the beginning into RAM, thus allowing faster access for the
--   next queries.
module NLP.Dictionary.StarDict.InMemory

-- | Tag for ifoPath to distinct dictionary type.
tag :: IfoFilePath -> Tagged Implementation IfoFilePath
instance GHC.Generics.Generic NLP.Dictionary.StarDict.InMemory.Implementation
instance Control.DeepSeq.NFData NLP.Dictionary.StarDict.InMemory.Implementation
instance NLP.Dictionary.Dictionary NLP.Dictionary.StarDict.InMemory.Implementation
instance NLP.Dictionary.StarDict.Common.StarDict NLP.Dictionary.StarDict.InMemory.Implementation


-- | <h1>Description</h1>
--   
--   Tools for StarDict dictionaries. Every call of <a>getEntries</a> will
--   perform file reading operation to retrieve requested data. For faster
--   access see <a>InMemory</a>.
module NLP.Dictionary.StarDict.Regular

-- | Tag for ifoPath to distinct dictionary type.
tag :: IfoFilePath -> Tagged Implementation IfoFilePath
instance GHC.Generics.Generic NLP.Dictionary.StarDict.Regular.Implementation
instance Control.DeepSeq.NFData NLP.Dictionary.StarDict.Regular.Implementation
instance NLP.Dictionary.Dictionary NLP.Dictionary.StarDict.Regular.Implementation
instance NLP.Dictionary.StarDict.Common.StarDict NLP.Dictionary.StarDict.Regular.Implementation
