Rework the testing script.
[tatoo.git] / src / tatoo.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                               TAToo                                 *)
4 (*                                                                     *)
5 (*                     Kim Nguyen, LRI UMR8623                         *)
6 (*                   Université Paris-Sud & CNRS                       *)
7 (*                                                                     *)
8 (*  Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (*  Recherche Scientifique. All rights reserved.  This file is         *)
10 (*  distributed under the terms of the GNU Lesser General Public       *)
11 (*  License, with the special exception on linking described in file   *)
12 (*  ../LICENSE.                                                        *)
13 (*                                                                     *)
14 (***********************************************************************)
15
16 (*
17   Time-stamp: <Last modified on 2013-03-13 21:29:17 CET by Kim Nguyen>
18 *)
19
20 let doc =
21   let fd = open_in Sys.argv.(1) in
22   let d = Tree.Naive.load_xml_file fd in
23   close_in fd; d
24
25
26 let query =
27   let arg2 = Sys.argv.(2) in
28   Xpath.Parser.parse (Ulexing.from_latin1_string arg2)
29
30 let auto =
31   Xpath.Compile.path query
32
33 open Format
34
35 let () =
36   fprintf err_formatter "Query: %a\n%!" Xpath.Ast.print_path query;
37   fprintf err_formatter "Automata: %a\n%!" Auto.Ata.print auto;
38   fprintf err_formatter "Evaluating automaton:\n%!";
39   let module Naive = Auto.Eval.Make(Tree.Naive) in
40   let t1 = Unix.gettimeofday() in
41   let results = Naive.eval auto doc (Tree.Naive.root doc) in
42   let teval = (Unix.gettimeofday () -. t1) *. 1000. in
43   let t1 = Unix.gettimeofday () in
44   output_string stdout "<xml_result>\n";
45   List.iter (fun n ->
46     Tree.Naive.print_xml stdout doc n;
47     output_char stdout '\n'
48   ) results;
49   output_string stdout "</xml_result>\n";
50   let tprint = (Unix.gettimeofday () -. t1) *. 1000. in
51   flush stdout;
52   fprintf err_formatter "evaluation time: %fms\nserialization time: %fms\n%!" teval tprint