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 Printf.eprintf "Parsing document : %!";
27 let v = time Tree.Binary.parse_xml_uri filename in
31 Printf.eprintf "Parsing query : ";
34 XPath.Parser.parse_string query
36 Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
38 Printf.eprintf "Compiling query : ";
39 let auto = time XPath.Compile.compile query in
40 XPath.Ast.print Format.err_formatter query;
41 Format.eprintf "\n%!";
42 (* Format.eprintf "Internal rep of the tree is :\n%!";
43 Tree.Binary.dump v; *)
44 Printf.eprintf "TopDown (No BackTrack) : \n";
45 time (fun v -> ignore (TopDown.accept auto v)) v;
46 Printf.eprintf "Number of nodes in the result set : %i\n" (BST.cardinal auto.result);
52 Printf.eprintf "Serializing results : ";
54 let oc = open_out f in
55 output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
56 BST.iter (fun t -> Tree.Binary.print_xml_fast oc t;
57 output_char oc '\n') auto.result) ();
59 Printf.eprintf "Total time : %fms\n Coherence : %i\n%!" (total_time())
62 let argc = Array.length Sys.argv;;
63 if (argc < 3 || argc >4)
65 (prerr_endline ("usage : " ^ Sys.argv.(0) ^ " <document> \'query\'[ <output> ]");
70 main Sys.argv.(1) Sys.argv.(2) (if argc == 4 then Some Sys.argv.(3) else None) ;;
72 Printf.eprintf "\n=================================================\nDEBUGGING\n%!";
73 Tree.DEBUGTREE.print_stats Format.err_formatter;;