Skip to content
Snippets Groups Projects
Commit 0dc083bd authored by pm3g19's avatar pm3g19
Browse files

Fixed issue with lines starting with comma

parent db44722d
No related branches found
No related tags found
No related merge requests found
Steven , Steve , Butcher
Dudley , Dudley , Timms
Gillian , Gillian , Carter
\ No newline at end of file
jian,shi
andrew,sogokon
julian,rathke
\ No newline at end of file
...@@ -2,6 +2,7 @@ module CSV where ...@@ -2,6 +2,7 @@ module CSV where
import System.IO import System.IO
import Data.List import Data.List
import Debug.Trace
readCSV :: FilePath -> IO [[String]] readCSV :: FilePath -> IO [[String]]
readCSV fname = do readCSV fname = do
...@@ -9,16 +10,19 @@ readCSV fname = do ...@@ -9,16 +10,19 @@ readCSV fname = do
return $ readCSVString str return $ readCSVString str
readCSVString :: String -> [[String]] readCSVString :: String -> [[String]]
readCSVString whole = [splitElem ',' (line++" " ) | line <- splitElem '\n' whole] readCSVString whole = [split ',' (' ':line ++ " ") | line <- split '\n' whole]
splitElem :: Eq a => a -> [a] -> [[a]] split :: Eq a => a -> [a] -> [[a]]
splitElem elem = split (/=elem)
split :: (a -> Bool) -> [a] -> [[a]] split c l = (\(l, _, _) -> reverse $ map reverse l) $ head $ dropWhile notEnd $ iterate split_ ([], [], l)
split p l = case span p l of where
([], _) -> [] split_ (la, wa, []) = (wa:la, [], [])
(match, []) -> [match] split_ (la, wa, c':l_tail) | c == c' = (wa:la, [], l_tail)
(match, _:rem') -> match:split p rem' | otherwise = (la, c':wa, l_tail)
notEnd (_, [], []) = False
notEnd _= True
split1 a = span (==a)
print2DList :: [[String]] -> IO () print2DList :: [[String]] -> IO ()
print2DList = putStrLn.toCSVString print2DList = putStrLn.toCSVString
......
This diff is collapsed.
1 ,5 ,4 ,
2 , ,2 ,
3 ,7 ,1 ,2
4 ,8 , ,
\ No newline at end of file
David , Beckham
Pele ,
Diego , Maradona
Cristiano, Ronaldo
Ronaldinho ,
\ No newline at end of file
This diff is collapsed.
1 ,6 ,4 ,7
2 ,8 ,5 ,3
2 , , ,1
4 , ,2 ,3
\ No newline at end of file
1 ,5 ,4 ,0
2 , 0,2 ,0
3 ,7 ,1 ,2
4 ,8 , 0,0
\ No newline at end of file
1 ,6 ,4 ,7
2 ,8 ,5 ,3
2 ,0,0,1
4 ,0,2 ,3
\ No newline at end of file
hello ,tree
big ,apple
hello,world
he,good
hello,good bye
.in
SampleSet:4
.out
let f = \(r) -> r[1] == "hello";
filter[SampleSet](f);
\ No newline at end of file
.in
A:2, # declare input files and their numbers of cols in .in section
B:2
.out # statements for the query are in .out section
A x B; # returns the cartesian product of the two sets (conjunction)
\ No newline at end of file
.in
A:3
.out
filter( \(r) -> r[1] == r[2]);
map (\(r) -> r[3,1]);
\ No newline at end of file
.in
P: 4,
Q: 4
.out
P x Q;
filter(\(r) -> r[1] == r[5]);
let f = \(a,y) -> if (isEmpty(a)) then y else a;
map (\(r) -> [r[1], f(r[2], r[6]), f(r[3], r[7]), f(r[4], r[8])]);
\ No newline at end of file
.in
P42 :2
.out
filter (\(r) -> not(isEmpty(r[2]) ) );
\ No newline at end of file
.in
A:1
.out
map{A}(\(r) -> [r[1],"0",r[1]] );
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment