various improvements, corrected logic errors

This commit is contained in:
IGI-111
2015-04-07 14:28:40 +00:00
parent 56229fb85a
commit 421b3e4681
3 changed files with 21 additions and 12 deletions

View File

@@ -6,8 +6,8 @@ import qualified Data.Set as Set
import qualified Data.Map as Map
import Data.Map(Map)
extractRules :: Confidence -> [ItemSet] -> [Rule]
extractRules threshold patterns = filter (\x -> threshold <= confidence patterns x) rules where
extractRules :: Confidence -> [ItemSet] -> [ItemSet] -> [Rule]
extractRules threshold table patterns = filter (\x -> threshold <= confidence table x) rules where
rules = Map.foldrWithKey (\k v old -> ruleFromSubset v k : old) [] subsets
subsets = foldr (\x old -> insertMultiple (filteredPowerset x) x old) Map.empty patterns
filteredPowerset (ItemSet set) = map (ItemSet . Set.fromList) $

View File

@@ -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