Safe Haskell | None |
---|
The module provides functions for working with the binary representation of the historical dictionary of Polish.
It is intended to be imported qualified, to avoid name clashes with Prelude functions, e.g.
import qualified NLP.HistPL.Lexicon as H
Use save
and load
functions to save/load
the entire dictionary in/from a given directory.
To search the dictionary, open the binary directory with an
open
function. For example, during a GHCi
session:
>>>
hpl <- H.open "srpsdp.bin"
Set the OverloadedStrings extension for convenience:
>>>
:set -XOverloadedStrings
To search the dictionary use the lookup
function, e.g.
>>>
entries <- H.lookup hpl "dufliwego"
You can use functions defined in the NLP.HistPL.Types module to query the entries for a particular feature, e.g.
>>>
map (H.text . H.lemma) entries
[["dufliwy"]]
Finally, if you need to follow an ID pointer kept in one entry
as a reference to another one, use the loadI
or tryLoadI
functions.
- data HistPL
- data Code
- type Key = Key UID
- type UID = Int
- tryOpen :: FilePath -> IO (Maybe HistPL)
- open :: FilePath -> IO HistPL
- lookup :: HistPL -> Text -> IO [(LexEntry, Code)]
- lookupMany :: HistPL -> [Text] -> IO [(LexEntry, Code)]
- nthSuffix :: HistPL -> Text -> Int -> Maybe Text
- withPrefix :: HistPL -> Text -> Int
- dictKeys :: Proxy p => HistPL -> () -> Producer p Key IO ()
- tryLoadK :: HistPL -> Key -> IO (Maybe LexEntry)
- loadK :: HistPL -> Key -> IO LexEntry
- dictIDs :: Proxy p => HistPL -> () -> Producer p Text IO ()
- tryLoadI :: HistPL -> Text -> IO (Maybe LexEntry)
- loadI :: HistPL -> Text -> IO LexEntry
- save :: Proxy p => FilePath -> () -> Consumer p (Maybe (LexEntry, Set Text)) IO ()
- load :: Proxy p => HistPL -> () -> Producer p (Key, LexEntry) IO ()
- module NLP.HistPL.Types
Dictionary
A binary dictionary holds additional info of type a
for every entry and additional info of type b
for every
word form.
Code of a word form origin. See the save
function to
learn why do we provide this information.
Key
Open
tryOpen :: FilePath -> IO (Maybe HistPL)Source
Open the binary dictionary residing in the given directory. Return Nothing if the directory doesn't exist or if it doesn't constitute a dictionary.
open :: FilePath -> IO HistPLSource
Open the binary dictionary residing in the given directory. Raise an error if the directory doesn't exist or if it doesn't constitute a dictionary.
Query
By Form
lookup :: HistPL -> Text -> IO [(LexEntry, Code)]Source
Lookup the form in the dictionary.
The resultant list constitutes a map from entries to Code
s.
lookupMany :: HistPL -> [Text] -> IO [(LexEntry, Code)]Source
Lookup a set of forms in the dictionary.
The resultant list constitutes a map from entries to Code
s.
By Prefix
nthSuffix :: HistPL -> Text -> Int -> Maybe TextSource
Get suffix of the i
-th form starting with a given prefix.
withPrefix :: HistPL -> Text -> IntSource
Compute the number of entries with a given prefix.
By Key
tryLoadK :: HistPL -> Key -> IO (Maybe LexEntry)Source
Load lexical entry given its key. Return Nothing
if there
is no entry with such a key.
loadK :: HistPL -> Key -> IO LexEntrySource
Load lexical entry given its key. Raise error if there is no entry with such a key.
By ID
tryLoadI :: HistPL -> Text -> IO (Maybe LexEntry)Source
Load lexical entry given its ID. Return Nothing
if there
is no entry with such ID.
loadI :: HistPL -> Text -> IO LexEntrySource
Load lexical entry given its ID. Raise error if there is no entry with such a key.
Conversion
save :: Proxy p => FilePath -> () -> Consumer p (Maybe (LexEntry, Set Text)) IO ()Source
Construct dictionary from a list of lexical entries and save it in
the given directory. To each entry an additional set of forms can
be assigned. The stream of entry pairs should be terminated by the
Nothing
value.
load :: Proxy p => HistPL -> () -> Producer p (Key, LexEntry) IO ()Source
A producer of all dictionary entries.
Modules
NLP.HistPL.Types module exports hierarchy of data types stored in the binary dictionary.
module NLP.HistPL.Types