From f636f951e53b2503718d1e740ff7d967486d23f8 Mon Sep 17 00:00:00 2001 From: Huibo SHI Date: Tue, 11 Mar 2014 22:48:11 +0100 Subject: [PATCH] =?utf8?q?ajout=20d'un=20compteur=20pour=20compter=20le=20?= =?utf8?q?nombre=20de=20noeuds=20=C3=A9valu=C3=A9s=20ajout=20une=20variabl?= =?utf8?q?e=20boolean=20'count'=20dans=20le=20fichier=20table=5Foptions.ml?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/query_tree.ml | 3 ++- src/query_tree.mli | 2 ++ src/table_driver.ml | 6 +++++- src/table_options.ml | 7 +++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/query_tree.ml b/src/query_tree.ml index c513bdb..79aee48 100644 --- a/src/query_tree.ml +++ b/src/query_tree.ml @@ -1,6 +1,6 @@ open Table - +let compteur = ref 0 let all_nodes tree = let root = Naive_tree.root tree in eval_axis tree [root] (Descendant true) @@ -144,5 +144,6 @@ let rec eval_query_tree tree start q = end in debug tree q resultat; + compteur := !compteur + (List.length resultat); resultat diff --git a/src/query_tree.mli b/src/query_tree.mli index 9afa1ad..2369eff 100644 --- a/src/query_tree.mli +++ b/src/query_tree.mli @@ -1,3 +1,5 @@ +val compteur : int ref + val all_nodes : Naive_tree.t -> Naive_tree.node list (** [all_nodes t] returns all the nodes in the tree [t]. Returns an empty list if there are no nodes in the tree. diff --git a/src/table_driver.ml b/src/table_driver.ml index 1f04028..d75c5df 100644 --- a/src/table_driver.ml +++ b/src/table_driver.ml @@ -32,7 +32,11 @@ let main () = print_node_list doc res; print_string "\n" ) query_tree_list ; - + + let _ = if !Table_options.count then + Format.fprintf Format.std_formatter "there are %i nodes\n" !Query_tree.compteur; + in + (* let output = match !Options.output_file with | None | Some "-" | Some "/dev/stdout" -> stdout diff --git a/src/table_options.ml b/src/table_options.ml index 22122b3..f2b0016 100644 --- a/src/table_options.ml +++ b/src/table_options.ml @@ -1,15 +1,18 @@ open Arg - +let count = ref false let input_file : string option ref = ref None let output_file : string option ref = ref None let queries = ref [] + let set_string_option r s = r := Some s let specs = align [ - + "-c", Set count, + " write the number of results only"; + "--count", Set count, " "; "-d", String (set_string_option input_file), " specify the input document file [default stdin]"; "--doc", String (set_string_option input_file), " "; -- 2.17.1