Commit f5c66e2c authored by pm3g19's avatar pm3g19
Browse files

Fixed issue with lines starting with comma

parent 0098d213
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
import System.IO
import Data.List
import Debug.Trace
readCSV :: FilePath -> IO [[String]]
readCSV fname = do
......@@ -9,16 +10,19 @@ readCSV fname = do
return $ readCSVString str
readCSVString :: String -> [[String]]
readCSVString whole = [splitElem ',' (line++" " ) | line <- splitElem '\n' whole]
splitElem :: Eq a => a -> [a] -> [[a]]
splitElem elem = split (/=elem)
readCSVString whole = [split ',' (' ':line ++ " ") | line <- split '\n' whole]
split :: Eq a => a -> [a] -> [[a]]
split :: (a -> Bool) -> [a] -> [[a]]
split p l = case span p l of
([], _) -> []
(match, []) -> [match]
(match, _:rem') -> match:split p rem'
split c l = (\(l, _, _) -> reverse $ map reverse l) $ head $ dropWhile notEnd $ iterate split_ ([], [], l)
where
split_ (la, wa, []) = (wa:la, [], [])
split_ (la, wa, c':l_tail) | c == c' = (wa:la, [], l_tail)
| otherwise = (la, c':wa, l_tail)
notEnd (_, [], []) = False
notEnd _= True
split1 a = span (==a)
print2DList :: [[String]] -> IO ()
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment