hmark 1.0.0 → 1.2
raw patch · 3 files changed
+16/−18 lines, 3 files
Files
- COPYING +0/−13
- Text/Generators/Markov.hs +15/−4
- hmark.cabal +1/−1
COPYING view
@@ -1,13 +0,0 @@-Copyright (c) 2009, Voker57--All rights reserved.--Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:--Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.--Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.--The name of author may not be used to endorse or promote products derived from this software without specific prior written permission.--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Text/Generators/Markov.hs view
@@ -19,6 +19,7 @@ import System.IO import Control.Monad import System.Random+import Control.Exception -- | Databases set type DBS = (BDB, BDB)@@ -89,7 +90,8 @@ riff (db, rdb) sentence = do ps <- shuffle $ toPairs sentence ssentence <- shuffle sentence- + let breakword w = zipWith (take) [1..length w] (repeat w)+ let brokenSentence = sortBy (\a b -> compare (length b) (length a)) $ concat $ map (breakword) ssentence let tryBuild phs = case phs of (ph:rest) -> do phrase <- build (db, rdb) ph@@ -119,8 +121,17 @@ fwdTry <- trySimilar db ssentence if isJust fwdTry then return fwdTry- else- trySimilar rdb ssentence+ else do+ rTry <- trySimilar rdb ssentence+ if isJust rTry then+ return rTry+ else do+ -- Try with wordparts+ fwdBTry <- trySimilar db brokenSentence+ if isJust fwdBTry then+ return fwdBTry+ else+ trySimilar rdb brokenSentence -- | Reads newline-separated lines from STDIN and replies to STDOUT burstFromStdin :: DBS -> IO ()@@ -130,7 +141,7 @@ case resM of Nothing -> return () Just res -> putStrLn $ unwords res- burstFromStdin (db, rdb)) (const $ return ())+ burstFromStdin (db, rdb)) ((const $ return ()) :: SomeException -> IO ()) learnTriplet db ws = do putdup db (BS8.fromString $ intercalate " " $ take 2 ws) (BS8.fromString $ ws !! 2)
hmark.cabal view
@@ -1,5 +1,5 @@ Name: hmark-Version: 1.0.0+Version: 1.2 Synopsis: A tool and library for Markov chains based text generation. Description: A tool and library for Markov chains based text generation. Author: Voker57