1 (******************************************************************************)
2 (* SXSI : XPath evaluator *)
3 (* Kim Nguyen (Kim.Nguyen@nicta.com.au) *)
4 (* Copyright NICTA 2008 *)
5 (* Distributed under the terms of the LGPL (see LICENCE) *)
6 (******************************************************************************)
14 let t1 = Unix.gettimeofday () in
16 let t2 = Unix.gettimeofday () in
17 let t = (1000. *.(t2 -. t1)) in
19 Printf.eprintf " %fms\n%!" t ;
22 let total_time () = List.fold_left (+.) 0. !l;;
25 let main filename query output =
27 (* Just a trick to allow the C++ code to print debugging stuff first *)
28 let v = time (fun () -> let v = Tree.Binary.parse_xml_uri filename;
29 in Printf.eprintf "Parsing document : %!";v
33 Printf.eprintf "Parsing query : ";
36 XPath.Parser.parse_string query
38 Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
40 Printf.eprintf "Compiling query : ";
41 let auto = time XPath.Compile.compile query in
42 XPath.Ast.print Format.err_formatter query;
43 Format.eprintf "\n%!";
44 (* Format.eprintf "Internal rep of the tree is :\n%!";
45 Tree.Binary.dump v; *)
46 Printf.eprintf "Execution time : ";
47 time (fun v -> ignore (TopDown.accept auto v)) v;
48 Printf.eprintf "Number of nodes in the result set : %i\n" (BST.cardinal auto.result);
54 Printf.eprintf "Serializing results : ";
56 let oc = open_out f in
57 output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
58 BST.iter (fun t -> Tree.Binary.print_xml_fast oc t;
59 output_char oc '\n') auto.result) ();
61 Printf.eprintf "Total time : %fms\n Coherence : %i\n%!" (total_time())
64 let argc = Array.length Sys.argv;;
65 if (argc < 3 || argc >4)
67 (prerr_endline ("usage : " ^ Sys.argv.(0) ^ " <document> \'query\'[ <output> ]");
72 main Sys.argv.(1) Sys.argv.(2) (if argc == 4 then Some Sys.argv.(3) else None) ;;
74 Printf.eprintf "\n=================================================\nDEBUGGING\n%!";
75 Tree.DEBUGTREE.print_stats Format.err_formatter;;