various improvements, corrected logic errors
This commit is contained in:
25
phase2.hs
25
phase2.hs
@@ -8,12 +8,21 @@ import Control.Monad(when)
|
||||
main :: IO()
|
||||
main = do
|
||||
args <- getArgs
|
||||
when (2 /= length args) (error "Usage: phase2 <file.csv> <threshold>")
|
||||
let filename = head args
|
||||
when (3 /= length args) (error "Usage: phase2 <table.csv> <frequents.csv> <threshold>")
|
||||
let threshold = read $ last args
|
||||
file <- readFile filename
|
||||
case parseCSV file of
|
||||
Left _ -> error "Could not parse out.csv"
|
||||
Right val -> do
|
||||
let table = map (ItemSet. Set.fromList .map Item) val
|
||||
print $ extractRules threshold table
|
||||
tableFile <- readFile $ head args
|
||||
freqFile <- readFile $ args !! 1
|
||||
case parseCSV tableFile of
|
||||
Left _ -> error "Could not parse table"
|
||||
Right tableFileContent ->
|
||||
case parseCSV freqFile of
|
||||
Left _ -> error "Could not parse frequent patterns"
|
||||
Right freqFileContent -> do
|
||||
putStrLn output
|
||||
when (length args > 2) $
|
||||
writeFile (args !! 2) $ output
|
||||
where
|
||||
freqPats = map (ItemSet. Set.fromList .map Item) (map tail freqFileContent)
|
||||
table = map (ItemSet. Set.fromList .map Item) tableFileContent
|
||||
rules = extractRules threshold table freqPats
|
||||
output = init $ foldr (\x old -> old++x++"\n") "" $ map show rules
|
||||
|
||||
Reference in New Issue
Block a user