From 56229fb85a8ff1357b0fd1cc586a0bdea03105c7 Mon Sep 17 00:00:00 2001 From: IGI-111 Date: Tue, 7 Apr 2015 12:27:42 +0000 Subject: [PATCH] phase 1 outputs frequencies to csv --- phase1.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/phase1.hs b/phase1.hs index afb0f5a..500617a 100644 --- a/phase1.hs +++ b/phase1.hs @@ -18,10 +18,11 @@ main = do Right val -> do let table = map (ItemSet. Set.fromList .map Item) val let freqPats = concat (frequentPatterns threshold table) - mapM_ (\x -> putStrLn (show x ++ "(" ++ show (count table x) ++ ")")) freqPats + let output = formatToCSV table freqPats + putStrLn output when (length args > 2) $ - writeFile (args !! 2) $ formatToCSV freqPats + writeFile (args !! 2) $ output -formatToCSV :: [ItemSet] -> String -formatToCSV = foldr (\x old -> old ++ formatRow x ++ "\n") "" where - formatRow (ItemSet set) = init $ Set.foldr (\x old -> old ++ show x ++ ",") "" set +formatToCSV :: [ItemSet] -> [ItemSet] -> String +formatToCSV table frequents = foldr (\x old -> old ++ formatRow x ++ "\n") "" frequents where + formatRow (ItemSet set) = init $ Set.foldr (\x old -> old ++ show x ++ ",") (show (count table (ItemSet set)) ++",") set