1) modifie la definition de query_tree
authorHuibo SHI <shihuibo19@gmail.com>
Wed, 19 Mar 2014 16:57:09 +0000 (17:57 +0100)
committerHuibo SHI <shihuibo19@gmail.com>
Wed, 19 Mar 2014 16:57:09 +0000 (17:57 +0100)
2) ajout la definition de query_tree_desc
3) ajout la fonction mk_node pour initialiser la query_tree
4) mettre la fonction mk_node dans bon endroit.

src/query_tree.ml
src/table.ml
tests/tiny2.xml

index 02ed498..5999df6 100644 (file)
@@ -10,6 +10,8 @@ let element_by_tag tree tagset kind = let dom = all_nodes tree in
                                Tree.NodeKind.is_a (Naive_tree.kind tree c) kind &&
                                QNameSet.mem (Naive_tree.tag tree c) tagset ) dom
 
+let mk_node q = {desc = q; id = -1; hash = -1}
+
 let rec compile_single_path p =
   let open Xpath.Ast in
       match p with
@@ -17,24 +19,24 @@ let rec compile_single_path p =
       
 and compile_step_list p = 
     match p with
-      | [] -> Start
+      | [] -> mk_node Start
       | (a,(test,kind),el) :: r ->
        let qtree = compile_step_list r in
-       let res = Binop ( Inter,Axis (a,qtree), Tag (test,kind) ) in
+       let res = mk_node ( Binop ( Inter,mk_node( Axis (a,qtree)),mk_node (Tag (test,kind) )) ) in
        List.fold_left (fun acc e ->
-         Binop(Inter, acc, compile_expr e)) res el  
+         mk_node (Binop(Inter, acc, compile_expr e))) res el  
 
   and compile_expr  (e : Xpath.Ast.expr )  = match e with
     | Fun_call (f, [ e0 ]) when (QName.to_string f) = "not" ->
       let qtree = compile_expr e0 in
-      Binop (Diff , Dom, qtree)
+      mk_node (Binop (Diff , mk_node (Dom), qtree))
 
     | Binop (e1,op,e2) -> let qtree1 = compile_expr e1 in
                          let qtree2 = compile_expr e2 in 
                          begin
                            match op with 
-                             | Or -> Binop (Union , qtree1,qtree2)
-                             | And -> Binop (Inter ,qtree1,qtree2)
+                             | Or -> mk_node (Binop (Union , qtree1,qtree2))
+                             | And -> mk_node (Binop (Inter ,qtree1,qtree2))
                              | _ -> failwith "Unknown operator"
                          end
     | Path p -> compile_path_rev p
@@ -44,21 +46,21 @@ and compile_step_list p =
     match p with
       | [] -> assert false
       | [p] -> compile_single_path_rev p  
-      | p::r -> List.fold_left (fun acc p -> Binop (Union , acc, compile_single_path_rev p) ) (compile_single_path_rev p) r
+      | p::r -> List.fold_left (fun acc p -> mk_node (Binop (Union , acc, compile_single_path_rev p)) ) (compile_single_path_rev p) r
        
   and compile_single_path_rev p = 
     match p with
-      | Absolute p | Relative p -> compile_step_list_rev p (*(List.rev p)*)
+      | Absolute p | Relative p -> compile_step_list_rev p 
 
   and compile_step_list_rev p = match p with
-    | [] -> Dom        
+    | [] -> mk_node Dom        
     | (a,(test,kind),el) :: r -> 
       let qtree = compile_step_list_rev r in
-      let res = Binop (Inter , qtree, Tag(test,kind)) in
+      let res = mk_node (Binop (Inter , qtree,mk_node (Tag(test,kind)))) in
       let qtree2 = List.fold_left (fun acc e ->
-       Binop(Inter, acc, compile_expr e)) res el in
+       mk_node (Binop(Inter, acc, compile_expr e))) res el in
       let a_rev = axis_rev a in
-      Axis (a_rev , qtree2)
+      mk_node (Axis (a_rev , qtree2))
                                                
       
     and axis_rev a =
@@ -83,7 +85,7 @@ and compile_step_list p =
 let compile_xpath p = match p with
   | [] -> assert false
   | [p] -> compile_single_path p
-  | p::r -> List.fold_left (fun acc p -> Binop (Union , acc, compile_single_path p) ) (compile_single_path p) r
+  | p::r -> List.fold_left (fun acc p -> mk_node (Binop (Union , acc, compile_single_path p) )) (compile_single_path p) r
 
 let comp_node t n1 n2 = (Naive_tree.preorder t n1) < (Naive_tree.preorder t n2)
 
@@ -139,7 +141,7 @@ let rec eval_query_tree tree start q =
        Hashtbl.find table_query_tree q
       with Not_found ->        
        let res =
-       match q with
+       match q.desc with
          | Start -> start
          | Dom ->  all_nodes tree          
          | Tag (t,k) -> element_by_tag tree t k                     
index ae446ea..3d372ec 100644 (file)
@@ -5,18 +5,20 @@ type move = Self
            | Revfirstchild
            | Prevsibling
 
-type query_tree = Binop of op * query_tree * query_tree
-                 | Axis of Xpath.Ast.axis * query_tree
-                 | Start 
-                 | Dom
-                 | Tag of QNameSet.t * Tree.NodeKind.t
+type query_tree_desc = Binop of op * query_tree * query_tree
+                      | Axis of Xpath.Ast.axis * query_tree
+                      | Start 
+                      | Dom
+                      | Tag of QNameSet.t * Tree.NodeKind.t
+
 and op = Union | Inter | Diff
-(*and query_tree = {
+
+and query_tree = {
   mutable desc  : query_tree_desc;
   mutable id : int;
   mutable hash : int;
 }
-*)
+
 
 
 
@@ -37,7 +39,7 @@ let print_node_list tree l =
   ) l
 
 let rec print_query_tree fmt q =
-  match q with
+  match q.desc with
       Dom -> Format.fprintf fmt "Dom"
     | Start -> Format.fprintf fmt "Start"
     | Tag (t,k) -> Format.fprintf fmt "Tag(%a, %a)" QNameSet.print t Tree.NodeKind.print k
index 695097a..b2aee8d 100644 (file)
@@ -1,5 +1,4 @@
-<site>
-<closed_auctions><closed_auction><d id="shi"><e><f><g/></f></e></d><z/></closed_auction></closed_auctions>
+<site><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>
 <!--