X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Ftable_driver.ml;fp=src%2Ftable_driver.ml;h=9d5b2409da4dff12186021916e9b1ae26772251a;hb=f3a0235e4715d24d8e8b4053923d433e1d876851;hp=0000000000000000000000000000000000000000;hpb=d1eeb554c0977ea18d3987f2806deaeb4e501396;p=tatoo.git diff --git a/src/table_driver.ml b/src/table_driver.ml new file mode 100644 index 0000000..9d5b240 --- /dev/null +++ b/src/table_driver.ml @@ -0,0 +1,133 @@ +open Table +open Table_options +open Query_tree + +let parse_xpath p = + Xpath.Parser.parse (Ulexing.from_utf8_string p) + +let main () = + let () = Table_options.parse () in + let doc = + let fd, close_fd = match !Table_options.input_file with + None | Some "-" | Some "/dev/stdin" ->stdin,ignore (*qu'est-ce que c'est ignore?????*) + | Some input -> + let fd = open_in input in fd, fun() -> close_in fd + in + (*let inc = open_in Sys.argv.(1) in*) + let doc = Naive_tree.load_xml_file fd in + close_fd(); (*ca sert a fermer fd????*) + doc + in + let queries = + List.map ( fun q -> + parse_xpath q) + !Table_options.queries + in + let query_tree_list = + List.map (fun query -> compile_xpath query) queries + in + let cpt = ref 0 in + + List.iter ( fun q -> + + let res = eval_query_tree doc [ (Naive_tree.root doc) ] q in + print_node_list doc res; + Format.printf "---------------Fin %i\n!" !cpt; + incr cpt; + ) query_tree_list ; + + (* let output = + match !Options.output_file with + | None | Some "-" | Some "/dev/stdout" -> stdout + | Some f -> open_out f + in + List.iter (fun query -> + Logger.msg `STATS "Query: %a " Xpath.Ast.print_path query) queries; + List.iter (fun query_tree -> + Logger.msg `STATS "@[Query_tree: @\n%a@]" print_query_tree Format.std_formatter query_tree) query_tree_list; + + *) + exit 0 + + +let () = main () + + + + + + + +(* let query = Xpath.Parser.parse + (Ulexing.from_utf8_string Sys.argv.(2)) + in + Format.printf "La requete est: %a\n%!" + Xpath.Ast.print_path query; *) + + (* print_endline "Test 1 root.firstchild"; + let c1 = eval_move doc [ (Naive_tree.root doc) ] Firstchild in + print_node_list doc c1; + print_endline "Test 2 root.firstchild.firstchild"; + let c2 = eval_move doc c1 Firstchild in + print_node_list doc c2; + print_endline "Test 3 root.firstchild.firstchild.nextsibling"; + let c3 = eval_move doc c2 Nextsibling in + print_node_list doc c3; + print_endline "Test 4 root.firstchild.firstchild.nextsibling.firstchild"; + let c4 = eval_move doc c3 Firstchild in + print_node_list doc c4; + print_endline "Test 5 root.firstchild.firstchild.nextsibling.firstchild.ancestor false"; + let c5 = eval_axis doc c4 (Ancestor false) in + print_node_list doc c5; + print_endline "Test 6"; + let c6 = eval_move doc c5 Prevsibling in + print_node_list doc c6; + print_endline "Test 7"; + let c7 = eval_move doc c6 Revfirstchild in + print_node_list doc c7; + print_endline "Test 8 Child [root]"; + let c8 = eval_axis doc [Naive_tree.root doc] Child in + print_node_list doc c8; + print_endline "Test 9 Descendant [b]"; + let c9 = eval_axis doc c2 (Descendant false) in + print_node_list doc c9; + print_endline "Test 10 Descendant or self [b]"; + let c10 = eval_axis doc c2 (Descendant true) in + print_node_list doc c10; + print_endline "Test 11 FollowingSibling [b]"; + let c11 = eval_axis doc c2 FollowingSibling in + print_node_list doc c11; + print_endline "Test 12 Parent [b]"; + let c12 = eval_axis doc c2 Parent in + print_node_list doc c12; + print_endline "Test 13 Ancestor or self [b]"; + let c13 = eval_axis doc c2 (Ancestor true) in + print_node_list doc c13; + print_endline "Test 14 PrecdingSibling [b]"; + let c14 = eval_axis doc c2 PrecedingSibling in + print_node_list doc c14; + print_endline "Test 15 preceding [b]"; + let c15 = eval_axis doc c2 Preceding in + print_node_list doc c15; + print_endline "Test 16 Following [b]"; + let c16 = eval_axis doc c2 Following in + print_node_list doc c16; + print_endline "Test 17 tag [b]"; + let c17 = element_by_tag doc (QName.make "b") in + print_node_list doc c17; + print_endline "Test 18 all nodes"; + let c18 = all_nodes doc in + print_node_list doc c18; + print_endline "Test 19 compile_xpath"; *) + + + (*Format.printf "Le document contient: %i noeuds\n%!" (Naive_tree.size doc); + let c19 = compile_xpath (parse_xpath "/child::a[child::b or not(following::]") in + Format.printf ">> %a\n%!" print_query_tree c19; + print_endline "Test 20 eval_query_tree"; + let res = eval_query_tree doc [ (Naive_tree.root doc) ] c19 in + print_node_list doc res; + print_endline "Fin";*) + + +