module Aux (redAtt, selavN, gtAtec ) where -- (c) 2007 Hans van Thiel -- Version 0.1 License GPL import Reduce ( redCons ) import Data.Array import Data.List ( delete ) -- module: auxiliary functions for Main -- reduction for a consequent attribute, coded by Codec -- execute the reduction on all attribute-value pairs -- the result matches each reduction with its consequent redAtt :: [(Int,Int)] -> [[(Int,Int)]] -> [([[(Int,Int)]], (Int,Int))] redAtt avls src = zip (map ((flip redCons) src) avls) avls -------------------------------------------------------------- -- get the index of an attribute string selAtt :: String -> Array Int [String] -> Int selAtt att attvarr = slAtt att (indices attvarr) attvarr where slAtt at [] arr = error "Attribute not found..." slAtt at (x:xs) arr | att == (head (arr ! x)) = x | otherwise = slAtt at xs arr -- get the coded attribute-value pairs from the attribute index selAV :: Int -> Array Int [String] -> [(Int,Int)] selAV ai attvarr = let avstr = attvarr ! ai vais = [1..(length avstr)-1] in [(ai, x) | x <- vais ] -- get the coded attribute-value pairs from the attribute name selavN :: String -> Array Int [String] -> [(Int,Int)] selavN atn attvarr = selAV ai attvarr where ai = selAtt atn attvarr -- get antecedent and consequent attribute indices from consequent index gtAtec :: Int -> Array Int [String] -> ([Int],Int) gtAtec cns attvarr = ((delete cns ils),cns) where ils = indices attvarr -----------------------------------------------------