phase 1 outputs frequencies to csv
This commit is contained in:
11
phase1.hs
11
phase1.hs
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user