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 v query output =
26 let _ = Tag.init (Tree.Binary.tag_pool v) in
27 Printf.eprintf "Parsing query : ";
30 XPath.Parser.parse_string query
32 Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
34 Printf.eprintf "Compiling query : ";
35 let auto = time XPath.Compile.compile query in
36 XPath.Ast.print Format.err_formatter query;
37 Printf.eprintf "Execution time : ";
38 let result = time (BottomUpNew.run auto) v in
39 Printf.eprintf "Number of nodes in the result set : %i\n" (List.length result);
45 Printf.eprintf "Serializing results : ";
47 let oc = open_out f in
48 output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
49 List.iter (fun t -> Tree.Binary.print_xml_fast oc t;
50 output_char oc '\n') result) ();
52 Printf.eprintf "Total time : %fms\n Coherence : %i\n%!" (total_time())
56 Options.parse_cmdline();;
59 if (Filename.check_suffix !Options.input_file ".srx")
62 Printf.eprintf "Loading from file : ";
63 time (Tree.Binary.load ~sample:!Options.sample_factor )
64 (Filename.chop_suffix !Options.input_file ".srx");
68 time (fun () -> let v = Tree.Binary.parse_xml_uri !Options.input_file;
69 in Printf.eprintf "Parsing document : %!";v
72 if !Options.save_file <> ""
74 Printf.eprintf "Writing file to disk : ";
75 time (Tree.Binary.save v) !Options.save_file;
79 main v !Options.query !Options.output_file;;
83 Printf.eprintf "\n=================================================\nDEBUGGING\n%!";
84 Format.eprintf "\nAutomaton is:\n%!";
85 Ata.dump Format.err_formatter auto;
86 Tree.DEBUGTREE.print_stats Format.err_formatter;;