packages feed

hist-pl-lexicon 0.6.0 → 0.6.1

raw patch · 3 files changed

+30/−31 lines, 3 filesdep ~dawgdep ~pipes

Dependency ranges changed: dawg, pipes

Files

hist-pl-lexicon.cabal view
@@ -1,5 +1,5 @@ name:               hist-pl-lexicon-version:            0.6.0+version:            0.6.1 synopsis:           A binary representation of the historical dictionary of Polish description:     The library provides a binary representation of the historical@@ -28,8 +28,8 @@                     , directory                     , filepath                     , transformers-                    , pipes >= 3.3 && < 3.4-                    , dawg >= 0.10 && < 0.11+                    , pipes >= 4.0 && < 4.1+                    , dawg >= 0.11 && < 0.12                     , hist-pl-types >= 0.1 && < 0.2                     , hist-pl-dawg >= 0.2 && < 0.3 
src/NLP/HistPL/Binary.hs view
@@ -9,7 +9,8 @@  import           Prelude hiding (lookup) import           Control.Applicative ((<$>))-import           Control.Proxy+import           Pipes+import qualified Pipes.Prelude as P import           System.FilePath ((</>)) import           Data.Binary (encodeFile, decodeFile) import qualified Data.Text as T@@ -35,12 +36,12 @@   -- | Get a list of entry identifiers stored in the dictionary.-dictIDs :: Proxy p => FilePath -> () -> Producer p T.Text IO ()-dictIDs path () = runIdentityP $ do+dictIDs :: FilePath -> Producer T.Text IO ()+dictIDs path = do     xs <- map T.pack <$> lift (getUsefulContents path)-    fromListS xs ()+    each xs   -- | Load all lexical entries in a lazy manner.-loadAll :: Proxy p => FilePath -> () -> Producer p LexEntry IO ()-loadAll path = dictIDs path >-> mapMD (load path)+loadAll :: FilePath -> Producer LexEntry IO ()+loadAll path = dictIDs path >-> P.mapM (load path)
src/NLP/HistPL/Lexicon.hs view
@@ -43,7 +43,7 @@ module NLP.HistPL.Lexicon ( -- * Dictionary-  HistPL+  HistPL (..) , Code (..) -- ** Key , Key@@ -81,10 +81,11 @@ import           Prelude hiding (lookup) import           Control.Applicative ((<$>)) import           Control.Arrow (first, second)-import           Control.Monad (unless, guard)+import           Control.Monad (unless, guard, (<=<)) import           Control.Monad.Trans.Maybe (MaybeT (..))-import           Control.Proxy-import qualified Control.Proxy.Trans.State as S+import qualified Control.Monad.Trans.State.Strict as S+import           Pipes+import qualified Pipes.Prelude as P import           System.FilePath ((</>)) import           System.Directory     ( createDirectoryIfMissing, createDirectory, doesDirectoryExist )@@ -204,9 +205,7 @@ --------------------------------------------------------  --- | A binary dictionary holds additional info of type @a@--- for every entry and additional info of type @b@ for every--- word form.+-- | A binary version of the old Polish dictionary. data HistPL = HistPL {     -- | A path to the binary dictionary.       dictPath  :: FilePath@@ -215,7 +214,7 @@     }  --- | Code of a word form origin.  See the `save` function to+-- | Code represents a word origin.  See the `save` function to -- learn why do we provide this information. data Code     = Orig  -- ^ only from historical dictionary@@ -256,11 +255,11 @@   -- | List of dictionary keys.-dictKeys :: Proxy p => HistPL -> () -> Producer p Key IO ()-dictKeys hpl () = runIdentityP $ do+dictKeys :: HistPL -> Producer Key IO ()+dictKeys hpl = do     let getPaths = getUsefulContents $ dictPath hpl </> keyDir     xs <- map parseKey <$> lift getPaths-    fromListS xs ()+    each xs   -- | Load lexical entry given its key.  Raise error if there@@ -276,11 +275,11 @@   -- | List of dictionary IDs.-dictIDs :: Proxy p => HistPL -> () -> Producer p T.Text IO ()-dictIDs hpl () = runIdentityP $ do+dictIDs :: HistPL -> Producer T.Text IO ()+dictIDs hpl = do     let getPaths = getUsefulContents $ dictPath hpl </> entryDir     xs <- map T.pack <$> lift getPaths-    fromListS xs ()+    each xs   -- | Load lexical entry given its ID.  Raise error if there@@ -344,9 +343,8 @@ -- 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.-save :: Proxy p => FilePath -> ()-     -> Consumer p (Maybe (LexEntry, S.Set T.Text)) IO ()-save binPath () = runIdentityP $ do+save :: FilePath -> Consumer (Maybe (LexEntry, S.Set T.Text)) IO ()+save binPath = do      -- Prepare directory for the dictionary.     lift $ do@@ -356,12 +354,12 @@         createDirectory $ binPath </> entryDir         createDirectory $ binPath </> keyDir -    formMap <- S.evalStateP s0 loop+    formMap <- S.evalStateT loop s0     lift $ encodeFile (binPath </> formFile) (D.weigh formMap)    where -    loop = request () >>= \x -> case x of+    loop = lift await >>= \x -> case x of         Nothing -> D.freeze . fst <$> S.get         Just (entry, forms) -> do             key <- getKey entry@@ -385,7 +383,7 @@      -- Save binary entry on a disk and update the map of forms.     saveBin key entry otherForms = do-        lift $ saveEntry binPath key entry+        lift $ lift $ saveEntry binPath key entry         let D.Key{..} = key             histForms = S.fromList (Util.allForms entry)             onlyHist  = S.difference histForms otherForms@@ -400,5 +398,5 @@   -- | A producer of all dictionary entries.-load :: Proxy p => HistPL -> () -> Producer p (Key, LexEntry) IO ()-load hpl = dictKeys hpl >-> mapMD (\x -> (x, ) <$> loadK hpl x)+load :: HistPL -> Producer (Key, LexEntry) IO ()+load hpl = dictKeys hpl >-> P.mapM (\x -> (x, ) <$> loadK hpl x)