Skip to content

Instantly share code, notes, and snippets.

@xnyhps
Created February 28, 2012 22:42
Show Gist options
  • Select an option

  • Save xnyhps/1935782 to your computer and use it in GitHub Desktop.

Select an option

Save xnyhps/1935782 to your computer and use it in GitHub Desktop.
instance Eq MutterWord where
a == b = case a `compare` b of { EQ -> True; _ -> False }
instance Ord MutterWord where
compare EndOfLine EndOfLine = EQ
compare EndOfLine _ = LT
compare _ EndOfLine = GT
compare (MutterWord (map toLower . filter isAlpha -> a)) (MutterWord (map toLower . filter isAlpha -> b)) = if (or $ map (\x -> a `elem` x && b `elem` x) [articles, pronouns]) then EQ else compare a b
where articles = ["de", "het", "een"]
pronouns = ["hij", "zij"]
runMutter :: String -> ModuleLB Quotes
runMutter str = do
st <- readMS
qs <- io (search (T.pack nm) (T.pack pat) st)
if length qs == 0 then do {
r <- random insult ;
box $ "No quotes found. " ++ r
} else do {
i <- io randomIO ;
g <- io getStdGen ;
let corpus = concatMap (\x -> EndOfLine : (map MutterWord $ words $ T.unpack $ snd x)) qs in box $ "... " ++ (concat $ intersperse " " $ map fromWord $ filter (/= EndOfLine) $ take 35 $ Markov.run 1 corpus (i `mod` (length corpus)) g) ++ " ..."
}
where (nm, p) = break isSpace str
pat = if null p then p else tail p
fromWord (MutterWord s) = s
--
-- the @quote command, takes a user nm to choose a random quote from
--
runQuote :: String -> ModuleLB Quotes
runQuote str = do {
st <- readMS ;
qs <- io (search (T.pack nm) (T.pack pat) st) ;
if traceShow qs $ null qs then do {
r <- random insult ;
box $ "No quotes for this person. " ++ r
}
else box . display =<< random qs
}
where (nm, p) = break isSpace str
pat = if null p then p else tail p
display (k, msg) = traceShow saying $ (if T.null k then " " else who ++ " says: ") ++ saying
where saying = T.unpack msg
who = T.unpack k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment