From 1d6a3a063ccce5c746801045601b5d96bb2804b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Wed, 14 Mar 2012 14:01:49 +0100 Subject: [PATCH] Make the tree/text interface more flexible to various text index. --- src/tree.ml | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/tree.ml b/src/tree.ml index 0b2070b..9c6eff3 100644 --- a/src/tree.ml +++ b/src/tree.ml @@ -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 -- 2.17.1