Make the tree/text interface more flexible to various text index.
authorKim Nguyễn <kn@lri.fr>
Wed, 14 Mar 2012 13:01:49 +0000 (14:01 +0100)
committerKim Nguyễn <kn@lri.fr>
Wed, 14 Mar 2012 13:01:49 +0000 (14:01 +0100)
src/tree.ml

index 0b2070b..9c6eff3 100644 (file)
@@ -247,7 +247,6 @@ external tree_last_child : tree -> [`Tree] Node.t -> [`Tree] Node.t = "caml_xml_
 let last_child t n = tree_last_child t.doc n
 
 
-
 external tree_next_sibling : tree -> [`Tree] Node.t -> [`Tree] Node.t = "caml_xml_tree_next_sibling"  "noalloc"
 let next_sibling t n = tree_next_sibling t.doc n
 
@@ -688,17 +687,17 @@ type query_result = { bv : bit_vector;
 external tree_flush : tree -> Unix.file_descr -> unit = "caml_xml_tree_flush"
 let flush t fd = tree_flush t.doc fd
 
-external text_prefix : tree -> string -> query_result = "caml_text_collection_prefix_bv"
-let text_prefix t s = text_prefix t.doc s
+external text_prefix : tree -> string -> bool -> query_result = "caml_text_collection_prefix_bv"
+let text_prefix t s b = text_prefix t.doc s b
 
-external text_suffix : tree -> string -> query_result = "caml_text_collection_suffix_bv"
-let text_suffix t s = text_suffix t.doc s
+external text_suffix : tree -> string -> bool -> query_result = "caml_text_collection_suffix_bv"
+let text_suffix t s b = text_suffix t.doc s b
 
-external text_equals : tree -> string -> query_result = "caml_text_collection_equals_bv"
-let text_equals t s = text_equals t.doc s
+external text_equals : tree -> string -> bool -> query_result = "caml_text_collection_equals_bv"
+let text_equals t s b = text_equals t.doc s b
 
-external text_contains : tree -> string -> query_result = "caml_text_collection_contains_bv"
-let text_contains t s = text_contains t.doc s
+external text_contains : tree -> string -> bool -> query_result = "caml_text_collection_contains_bv"
+let text_contains t s b = text_contains t.doc s b
 
 
 module Predicate = Hcons.Make (
@@ -727,7 +726,7 @@ let query_fun = function
 let _pred_cache = Hashtbl.create 17
 ;;
 let mk_pred query s =
-  let f = query_fun query in
+  let f = query_fun query  in
   let memo = ref (fun _ _ -> failwith "Undefined") in
   memo := begin fun tree node ->
     let results =
@@ -735,7 +734,7 @@ let mk_pred query s =
          Not_found ->
            time ~count:1 ~msg:(Printf.sprintf "Computing text query %s(%s)"
                                  (string_of_query query) s)
-             (f tree) s
+             (f tree) s true
     in
     let bv = results.bv in
     memo := begin fun _ n ->
@@ -752,15 +751,15 @@ let mk_pred query s =
   Predicate.make memo
 
 
-let full_text_prefix t s = (text_prefix t s).pos
+let full_text_prefix t s = (text_prefix t s true).pos
 
-let full_text_suffix t s = (text_suffix t s).pos
+let full_text_suffix t s = (text_suffix t s true).pos
 
-let full_text_equals t s = (text_equals t s).pos
+let full_text_equals t s = (text_equals t s true).pos
 
-let full_text_contains t s = (text_contains t s).pos
+let full_text_contains t s = (text_contains t s true).pos
 
 let full_text_query q t s =
-  let res = (query_fun q) t s in
+  let res = (query_fun q) t s true in
   Hashtbl.replace _pred_cache (q,s) res;
   res.pos