From: Lucca Hirschi Date: Fri, 13 Jul 2012 11:30:09 +0000 (+0200) Subject: solve.ml solves series of queries and ouptut onlt selected nodes + examples from... X-Git-Tag: Core+FS_tested~4^2 X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=commitdiff_plain;h=908fd26b0dd93060dec75d797b49b2c78e631da7 solve.ml solves series of queries and ouptut onlt selected nodes + examples from XPath-FT --- diff --git a/correct_test b/correct_test new file mode 100755 index 0000000..d28ee73 --- /dev/null +++ b/correct_test @@ -0,0 +1 @@ +./solve.native ./tests/docs/XPath-FT.xml -f ./tests/queries/XPath-FT.queries \ No newline at end of file diff --git a/src/solve.ml b/src/solve.ml new file mode 100644 index 0000000..d898bab --- /dev/null +++ b/src/solve.ml @@ -0,0 +1,77 @@ +(***********************************************************************) +(* *) +(* TAToo *) +(* *) +(* Kim Nguyen, LRI UMR8623 *) +(* Université Paris-Sud & CNRS *) +(* *) +(* Copyright 2010-2012 Université Paris-Sud and Centre National de la *) +(* Recherche Scientifique. All rights reserved. This file is *) +(* distributed under the terms of the GNU Lesser General Public *) +(* License, with the special exception on linking described in file *) +(* ../LICENSE. *) +(* *) +(***********************************************************************) + + +(** use: [./test xml_file -f XPath_queries_file] + one query per line [XPath_querie_file] +*) + +open Format + +let doc () = + let fd = open_in Sys.argv.(1) in + let d = Tree.load_xml_file fd in + close_in fd; + fprintf err_formatter "Parse Tree OK ! "; + d + + +let query () = + let arg2 = Sys.argv.(2) in + if arg2 = "-f" + then let fq = open_in Sys.argv.(3) in + let rec list_qu fq list = + try + (match XPath.parse_file fq with + | q -> list_qu fq (q::list) + | _ -> list) + with _ -> list in + let list = list_qu fq [] in + close_in fq; + fprintf err_formatter "Parse query OK ! "; + list + else failwith "Use -f" + +let build_asta query = + let asta = Compil.trans query in + fprintf err_formatter "Compil OK ! "; + asta + +let compute_run doc query = + let run = Run.compute doc query in + fprintf err_formatter "Run OK ! \n"; + run + +let () = + Format.pp_set_margin err_formatter 80; + let doc = doc () in + output_string stderr "##### Doc with positions #####\n"; + Tree.print_xml_preorder stderr doc (Tree.root doc); + let queries = query () in + let rec solve_queries = function + | [] -> () + | query :: tl -> + let asta = build_asta query in + let selected_nodes = Run.selected_nodes doc asta in + fprintf err_formatter "Query: %a\n" + XPath.Ast.print query; + let rec print_selec fmt l = match l with + | [x] -> fprintf fmt "%s" (string_of_int x) + | x :: tl -> fprintf fmt "%s" ((string_of_int x)^"; ");print_selec fmt tl + | [] -> fprintf fmt "%s" "ø" in + fprintf err_formatter "@.@. # Selected nodes: {%a}@." + print_selec selected_nodes in + solve_queries queries; + exit 0 diff --git a/tests/docs/XPath-FT.xml b/tests/docs/XPath-FT.xml new file mode 100644 index 0000000..90aef04 --- /dev/null +++ b/tests/docs/XPath-FT.xml @@ -0,0 +1 @@ +clergywomandecadentgentilityhappy-go-lucky manjigsawkerchiefThe letter L is followed by the letter:which is followed by the letter:ovenware

plentiful

quarrelsome
sagetatteredvoluptuarywriggle
yawnzuzzurellone
diff --git a/tests/queries/XPath-FT.queries b/tests/queries/XPath-FT.queries new file mode 100644 index 0000000..bf29a0d --- /dev/null +++ b/tests/queries/XPath-FT.queries @@ -0,0 +1,8 @@ +/descendant::L +/descendant::L/descendant::* +/descendant::L/following-sibling::* +/descendant::L/self::* +/descendant::*[L] +/descendant::*[descendant::L] +/descendant::*[following-sibling::L] +/descendant::*[self::L] \ No newline at end of file