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 (******************************************************************************)
10 if Tree.Binary.is_node v
12 let tag = Tree.Binary.tag v
14 let acc = aux (Ptset.add tag acc) (Tree.Binary.first_child v)
16 aux (Ptset.add tag acc) (Tree.Binary.next_sibling v)
23 if Array.length (Sys.argv) <> 2
26 Printf.printf "usage: %s file.xml\n" (Sys.argv.(0));
33 Tree.Binary.load Sys.argv.(1)
37 Tree.Binary.parse_xml_uri Sys.argv.(1)
41 Printf.printf "Error parsing document\n";
44 let _ = Tag.init (Tree.Binary.tag_pool doc)
47 let tags = (collect_tags doc)
50 let _ = Tree.Binary.test_xml_tree Format.std_formatter tags doc
53 let _ = Printf.printf "Testing //a with jumping\n"
56 let rec test_a dir t acc ctx =
57 if Tree.Binary.is_node t
60 if (Tree.Binary.tag t) == (Tag.tag "a")
61 then Ata.TS.cons t acc
64 let first = Tree.Binary.tagged_below t Ptset.empty (Ptset.singleton (Tag.tag "a"))
65 and next = Tree.Binary.tagged_next t Ptset.empty (Ptset.singleton (Tag.tag "a")) ctx
68 Printf.printf "t is :";
69 Tree.Binary.print_xml_fast stdout t;
70 Printf.printf " called from %s of " (if dir then "below" else "next");
71 Tree.Binary.print_xml_fast stdout ctx;
72 if (Tree.Binary.is_node next)
74 Printf.printf ", Next a is %!";
75 Tree.Binary.print_xml_fast stdout next;
78 Printf.printf ", Next a is empty!";
81 test_a false next (test_a true first acc t) t
85 let rec test_text dir t acc ctx =
86 if Tree.Binary.is_node t
89 if (Tree.Binary.tag t) == (Tag.pcdata)
90 then Ata.TS.cons t acc
93 let first = Tree.Binary.text_below t
94 and next = Tree.Binary.text_next t ctx
98 Printf.printf "t is :";
99 Tree.Binary.print_xml_fast stdout t;
100 Printf.printf " called from %s of " (if dir then "below" else "next");
101 Tree.Binary.print_xml_fast stdout ctx;
102 if (Tree.Binary.is_node first)
104 Printf.printf "First (text) is %!";
105 Tree.Binary.print_xml_fast stdout first;
108 Printf.printf "First (text) is empty!";
109 if (Tree.Binary.is_node next)
111 Printf.printf ", Next (text) is %!";
112 Tree.Binary.print_xml_fast stdout next;
115 Printf.printf ", Next (text) is empty!";
118 test_text false next (test_text true first acc t) ctx
122 let r = test_a true doc Ata.TS.empty doc;;
124 let _ = Printf.printf "==> %i nodes\n" (Ata.TS.length r)
125 let _ = Ata.TS.iter (fun t -> Tree.Binary.print_xml_fast stdout t; print_newline();) r
128 let _ = Tree.Binary.init_contains doc "car"
130 let r = test_text true doc Ata.TS.empty doc
131 let _ = Printf.printf "==> %i nodes\n" (Ata.TS.length r)
132 (* let _ = Ata.TS.iter (fun t -> Tree.Binary.print_xml_fast stdout t; print_newline();) r *)
137 let t1 = Unix.gettimeofday () in
139 let t2 = Unix.gettimeofday () in
140 let t = (1000. *.(t2 -. t1)) in
141 Printf.eprintf " %fms\n%!" t ;
144 let _ = Printf.eprintf "Timing full //keyword ... "
145 let x = List.length (time (Tree.Binary.time_xml_tree doc) (Tag.tag "keyword"))
146 let _ = Printf.eprintf "Timing jump //keyword ... "
147 let y = List.length (time (Tree.Binary.time_xml_tree2 doc) (Tag.tag "keyword"))
148 let _ = Printf.eprintf "coherant : %b\n" (x=y)