phase 1 outputs frequencies to csv

This commit is contained in:
IGI-111
2015-04-07 12:27:42 +00:00
parent a468e946e3
commit 56229fb85a

View File

@@ -18,10 +18,11 @@ main = do
Right val -> do Right val -> do
let table = map (ItemSet. Set.fromList .map Item) val let table = map (ItemSet. Set.fromList .map Item) val
let freqPats = concat (frequentPatterns threshold table) 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) $ when (length args > 2) $
writeFile (args !! 2) $ formatToCSV freqPats writeFile (args !! 2) $ output
formatToCSV :: [ItemSet] -> String formatToCSV :: [ItemSet] -> [ItemSet] -> String
formatToCSV = foldr (\x old -> old ++ formatRow x ++ "\n") "" where formatToCSV table frequents = foldr (\x old -> old ++ formatRow x ++ "\n") "" frequents where
formatRow (ItemSet set) = init $ Set.foldr (\x old -> old ++ show x ++ ",") "" set formatRow (ItemSet set) = init $ Set.foldr (\x old -> old ++ show x ++ ",") (show (count table (ItemSet set)) ++",") set