-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_csv.ml
More file actions
66 lines (52 loc) · 1.52 KB
/
read_csv.ml
File metadata and controls
66 lines (52 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
open String
open Str
open Expr
exception Null
(** lecture d'un fichier csv en entrée *)
let decoupe_ligne : string -> string list = fun s ->
Str.split (Str.regexp ",") s
let read_file nom =
let file = open_in nom in
let rec to_idstring liste =
match liste with
|[] -> []
|x::xs -> (Name(x))::(to_idstring xs)
in
let result=[to_idstring (decoupe_ligne(input_line file))]; in
let rec auxi file result =
try
let result = (to_idstring (decoupe_ligne(input_line file)))::result in
auxi file result;
with End_of_file ->
begin
close_in file;
result
end
in
auxi file result
let rec print_tuple t = match t with
|a::b ->
begin
match a with
|Name(aa) ->
begin print_string aa ;print_string "\t"; print_tuple b end
|Id(i1,i2) -> begin print_string i1; print_string ("."); print_string i2; print_string(" "); print_tuple b end
end
| _ -> print_string "\n"
let rec print_tuple_col t = match t with
|a::b -> begin print_tuple a; print_tuple_col b end
|_ -> ()
let rev l =
let rec aux l acc = match l with
|[] -> acc
|t::q -> aux q (t::acc) in aux l []
let rec revmat l = match l with
|[] -> []
|t::q -> rev t :: revmat q
let rec transpose list =
match list with
| [] -> []
| [] :: xss -> transpose xss
| (x::xs) :: xss ->
(x :: List.map List.hd xss) :: transpose (xs :: List.map List.tl xss);;
(*let _ = print_tuple_col(revmat(transpose (read_file "employes.csv"))) ;;*)