phase 2 output is formatted and only the 10 best rules by lift are written

This commit is contained in:
IGI-111
2015-04-10 12:34:13 +00:00
parent ddffd9a8f1
commit 810a48184c
2 changed files with 6 additions and 6 deletions

View File

@@ -42,7 +42,7 @@ empty = ItemSet (Set.fromList [])
data Rule = Rule ItemSet ItemSet deriving (Eq) data Rule = Rule ItemSet ItemSet deriving (Eq)
instance Show Rule where instance Show Rule where
show (Rule a b) = show a ++ "->" ++ show b show (Rule a b) = show a ++ "," ++ show b
instance Freq Rule where instance Freq Rule where
frequency table (Rule (ItemSet set1) (ItemSet set2)) = frequency table $ frequency table (Rule (ItemSet set1) (ItemSet set2)) = frequency table $

View File

@@ -2,6 +2,7 @@ import CSVParser
import DataModel import DataModel
import ExtractRules import ExtractRules
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.List as List
import System.Environment(getArgs) import System.Environment(getArgs)
import Control.Monad(when) import Control.Monad(when)
@@ -9,7 +10,7 @@ main :: IO()
main = do main = do
args <- getArgs args <- getArgs
when (3 > length args) (error "Usage: phase2 table.csv frequents.csv threshold [out.assoc]") when (3 > length args) (error "Usage: phase2 table.csv frequents.csv threshold [out.assoc]")
let threshold = read $ last args let threshold = read $ args !! 2
tableFile <- readFile $ head args tableFile <- readFile $ head args
freqFile <- readFile $ args !! 1 freqFile <- readFile $ args !! 1
case parseCSV tableFile of case parseCSV tableFile of
@@ -18,13 +19,12 @@ main = do
case parseCSV freqFile of case parseCSV freqFile of
Left _ -> error "Could not parse frequent patterns" Left _ -> error "Could not parse frequent patterns"
Right freqFileContent -> do Right freqFileContent -> do
--putStrLn output print $ zip rules $ map (lift table) rules
print $ zip rules (map (lift table) rules)
when (length args > 3) $ when (length args > 3) $
writeFile (args !! 3) output writeFile (args !! 3) output
where where
freqPats = map ((ItemSet. Set.fromList .map Item) . tail) freqFileContent freqPats = map ((ItemSet. Set.fromList .map Item) . tail) freqFileContent
table = map (ItemSet. Set.fromList .map Item) tableFileContent table = map (ItemSet. Set.fromList .map Item) tableFileContent
rules = extractRules threshold table freqPats rules = List.sortBy (\x y -> compare (lift table y) (lift table x)) $ extractRules threshold table freqPats
output = init $ foldr ((\x old -> old++x++"\n").show) "" rules output = init $ foldr ((\x old -> old ++ x ++ "\n").show) "" $ take 10 rules