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 =
26 (* Just a trick to allow the C++ code to print debugging stuff first *)
27 let v = time (fun () -> let v = Tree.Binary.parse_xml_uri filename;
28 in Printf.eprintf "Parsing document : %!";v
31 let _ = Tag.init (Tree.Binary.tag_pool v) in
32 Printf.eprintf "Parsing query : ";
35 XPath.Parser.parse_string query
37 Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
39 Printf.eprintf "Compiling query : ";
40 let auto = time XPath.Compile.compile query in
41 XPath.Ast.print Format.err_formatter query;
42 Format.eprintf "\n%!";
43 (* Format.eprintf "Internal rep of the tree is :\n%!";
44 Tree.Binary.dump v; *)
45 Printf.eprintf "Execution time : ";
46 time (fun v -> ignore (TopDown.accept auto v)) v;
47 Printf.eprintf "Number of nodes in the result set : %i\n" (BST.cardinal auto.result);
53 Printf.eprintf "Serializing results : ";
55 let oc = open_out f in
56 output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
57 BST.iter (fun t -> Tree.Binary.print_xml_fast oc t;
58 output_char oc '\n') auto.result) ();
60 Printf.eprintf "Total time : %fms\n Coherence : %i\n%!" (total_time())
64 Options.parse_cmdline();;
66 main !Options.input_file !Options.query !Options.output_file;;
70 Printf.eprintf "\n=================================================\nDEBUGGING\n%!";
71 Tree.DEBUGTREE.print_stats Format.err_formatter;;