remedier a la liste desordonné par l'ajout de sort a la fin de la fonction eval_query...
authorHuibo SHI <shihuibo19@gmail.com>
Wed, 19 Mar 2014 16:00:45 +0000 (17:00 +0100)
committerHuibo SHI <shihuibo19@gmail.com>
Wed, 19 Mar 2014 16:00:45 +0000 (17:00 +0100)
src/query_tree.ml
src/query_tree.mli
src/table.ml
tests/tiny2.xml

index f0b2cbc..02ed498 100644 (file)
@@ -5,8 +5,10 @@ let compteur = ref 0
 let all_nodes tree = let root = Naive_tree.root tree in
                     eval_axis tree [root] (Descendant true)
 
-let element_by_tag tree tagset = let dom = all_nodes tree in
-                             List.filter (fun c -> QNameSet.mem (Naive_tree.tag tree c) tagset ) dom
+let element_by_tag tree tagset kind = let dom = all_nodes tree in
+                             List.filter (fun c ->
+                               Tree.NodeKind.is_a (Naive_tree.kind tree c) kind &&
+                               QNameSet.mem (Naive_tree.tag tree c) tagset ) dom
 
 let rec compile_single_path p =
   let open Xpath.Ast in
@@ -16,9 +18,9 @@ let rec compile_single_path p =
 and compile_step_list p = 
     match p with
       | [] -> Start
-      | (a,(test,_),el) :: r ->
+      | (a,(test,kind),el) :: r ->
        let qtree = compile_step_list r in
-       let res = Binop ( Inter,Axis (a,qtree), Tag (test) ) in
+       let res = Binop ( Inter,Axis (a,qtree), Tag (test,kind) ) in
        List.fold_left (fun acc e ->
          Binop(Inter, acc, compile_expr e)) res el  
 
@@ -50,9 +52,9 @@ and compile_step_list p =
 
   and compile_step_list_rev p = match p with
     | [] -> Dom        
-    | (a,(test,_),el) :: r -> 
+    | (a,(test,kind),el) :: r -> 
       let qtree = compile_step_list_rev r in
-      let res = Binop (Inter , qtree, Tag(test)) in
+      let res = Binop (Inter , qtree, Tag(test,kind)) in
       let qtree2 = List.fold_left (fun acc e ->
        Binop(Inter, acc, compile_expr e)) res el in
       let a_rev = axis_rev a in
@@ -117,10 +119,12 @@ let debug tree q l =
   if !do_debug then begin
     Format.fprintf Format.std_formatter "Evaluation de: ";
     print_query_tree Format.std_formatter q;
-    Format.fprintf Format.std_formatter "\nResultat: %i"
+    Format.fprintf Format.std_formatter "\nResultat: %i\n"
     (List.length l);
     Format.pp_print_flush Format.std_formatter ();
     print_node_list tree l;
+    (*List.iter
+      (fun n -> Format.fprintf Format.std_formatter "%i, " (Naive_tree.preorder tree n)) l;*)
     Format.fprintf Format.std_formatter "\n----------------\n";
     Format.pp_print_flush Format.std_formatter ();
   end
@@ -138,7 +142,7 @@ let rec eval_query_tree tree start q =
        match q with
          | Start -> start
          | Dom ->  all_nodes tree          
-         | Tag t -> element_by_tag tree t                   
+         | Tag (t,k) -> element_by_tag tree t k                     
          | Axis (a,q1) -> let ls = eval_query_tree tree start q1 in
                           eval_axis tree ls a                     
          | Binop (op,q1,q2)-> begin
@@ -150,6 +154,7 @@ let rec eval_query_tree tree start q =
              | Diff -> diff_list tree ls1 ls2
          end
        in
+       let res = List.sort (Table.compare_node tree) res in
        Hashtbl.add table_query_tree q res;
        compteur := !compteur + (List.length res);
        res
index 2369eff..ea520c4 100644 (file)
@@ -5,7 +5,7 @@ val all_nodes : Naive_tree.t -> Naive_tree.node list
     Returns an empty list if there are no nodes in the tree.
  *)
 
-val element_by_tag : Naive_tree.t -> QNameSet.t -> Naive_tree.node list
+val element_by_tag : Naive_tree.t -> QNameSet.t -> Tree.NodeKind.t -> Naive_tree.node list
 (** [element_by_tag t tag] returns all the nodes whose tag equal to [tag] in the tree [t]. *)
 
 val compile_single_path : Xpath.Ast.single_path -> Table.query_tree 
index 8e4f2e6..ae446ea 100644 (file)
@@ -9,8 +9,19 @@ type query_tree = Binop of op * query_tree * query_tree
                  | Axis of Xpath.Ast.axis * query_tree
                  | Start 
                  | Dom
-                 | Tag of QNameSet.t
+                 | Tag of QNameSet.t * Tree.NodeKind.t
 and op = Union | Inter | Diff
+(*and query_tree = {
+  mutable desc  : query_tree_desc;
+  mutable id : int;
+  mutable hash : int;
+}
+*)
+
+
+
+
+
 
 (*28/01/2014  
   parametres : tree  l'arbre xml
@@ -29,7 +40,7 @@ let rec print_query_tree fmt q =
   match q with
       Dom -> Format.fprintf fmt "Dom"
     | Start -> Format.fprintf fmt "Start"
-    | Tag t -> Format.fprintf fmt "Tag(%a)" QNameSet.print t
+    | Tag (t,k) -> Format.fprintf fmt "Tag(%a, %a)" QNameSet.print t Tree.NodeKind.print k
     | Axis (a,q) ->
       Format.fprintf fmt "%a(%a)" Xpath.Ast.print_axis a print_query_tree q
     | Binop (op,q1,q2) -> 
@@ -102,18 +113,19 @@ and eval_star tree ls lr =
   retour : l'ensemble de noeuds qui correspondent à¥† l'axe
 *)
 
-let keep_elements t l =
+let keep_elements t l = (*
    List.filter (fun n -> match Naive_tree.kind t n with
      | Element | Text | Document | Attribute -> true | _ -> false) l
+                       *) l
 
-let keep_attributs t l =
+let keep_attributs t l = (*
   List.filter (fun n -> match Naive_tree.kind t n with
-    | Attribute ->true | _ -> false) l
+    | Attribute ->true | _ -> false) *) l
 
 let rec eval_axis tree ls a =
   let open Xpath.Ast in
        match a with
-           Self -> keep_elements tree ls
+           Self -> ls
              
          | Attribute -> let lfc = eval_move tree ls Firstchild in
                         let lc = eval_star tree lfc [Nextsibling] in
index e51233c..695097a 100644 (file)
@@ -2,11 +2,13 @@
 <closed_auctions><closed_auction><d id="shi"><e><f><g/></f></e></d><z/></closed_auction></closed_auctions>
 <regions>
 <africa><item id="item0"><location>united states</location><quantity>1</quantity><name>duteous nine eighteen</name></item></africa>
+<!--
 <asia><item id="item1"><location>united states</location><quantity>1</quantity><name>great</name></item></asia>
 <australia><item id="item2"><location>united states</location><quantity>1</quantity><name>scarce brook</name></item></australia>
 <europe><item id="item3"><location>united states</location><quantity>1</quantity><name>abhorr execution beckon rue</name></item></europe>
 <namerica><item id="item4"><location>united states</location><quantity>1</quantity><name>unsur brutish</name></item></namerica>
 <samerica><item id="item5"><location>united states</location><quantity>1</quantity><name>nakedness</name></item></samerica>
+-->
 </regions>
 <categories><category id="category0"><name>dispatch reported dotard holofernes </name></category></categories>
 </site>