phase2 finished

This commit is contained in:
IGI-111
2015-04-05 18:57:56 +02:00
parent c108e32c89
commit ac068094a4
4 changed files with 31 additions and 11 deletions

View File

@@ -13,13 +13,14 @@ class Freq a where
data Item = Item String deriving (Eq, Ord)
instance Show Item where
show (Item a) = show a
show (Item a) = a
data ItemSet = ItemSet (Set Item) deriving (Eq, Ord)
instance Show ItemSet where
show (ItemSet x) =
foldr ((\y old -> y ++ " " ++ old).show) "" (Set.toList x)
init $ foldr ((\y old -> y ++ " " ++ old).show) "" (Set.toList x)
instance Freq ItemSet where
frequency table (ItemSet set) =

11
FreqParser.hs Normal file
View File

@@ -0,0 +1,11 @@
module ItemsParser (
parseItems,
parseItemsWithFreq
)where
import qualified Data.Map as Map
import Data.Map(Map)
import DataModel
parseItems :: String -> Either ParseError [ItemSet]
parseItemsWithFreq :: String -> Either ParseError Map ItemSet Frequency

View File

@@ -8,11 +8,20 @@ import Control.Monad(when)
main :: IO()
main = do
args <- getArgs
when (2 /= length args) (error "Usage: Main <file.csv> <threshold>")
when (2 > length args)
(error "Usage: Main <table.csv> <threshold> <outfile.csv>")
let filename = head args
let threshold = read $ last args
let threshold = read $ args !! 1
file <- readFile filename
case parseCSV file of
Left _ -> error "Could not parse out.csv"
Right val -> mapM_ (\x -> putStrLn (show x ++ "(" ++ show (count table x) ++ ")")) (concat (frequentPatterns threshold table)) where
table = map (ItemSet. Set.fromList .map Item) val
Right val -> do
let table = map (ItemSet. Set.fromList .map Item) val
let freqPats = concat (frequentPatterns threshold table)
mapM_ (\x -> putStrLn (show x ++ "(" ++ show (count table x) ++ ")")) freqPats
when (length args > 2) $
writeFile (args !! 2) $ formatToCSV freqPats
formatToCSV :: [ItemSet] -> String
formatToCSV = foldr (\x old -> old ++ formatRow x ++ "\n") "" where
formatRow (ItemSet set) = init $ Set.foldr (\x old -> old ++ show x ++ ",") "" set

View File

@@ -1,5 +1,4 @@
import CSVParser
import FrequentPatterns
import DataModel
import ExtractRules
import qualified Data.Set as Set
@@ -15,6 +14,6 @@ main = do
file <- readFile filename
case parseCSV file of
Left _ -> error "Could not parse out.csv"
Right val -> print $ extractRules threshold $
filter (/= empty) $ concat $ frequentPatterns 0.01 table where
table = map (ItemSet. Set.fromList .map Item) val
Right val -> do
let table = map (ItemSet. Set.fromList .map Item) val
print $ extractRules threshold table