-
-let text_below t =
- let l = Array.length !contains_array in
- match t.node with
- | Node(n) ->
- let i,j = tree_doc_ids t.doc n in
- let id = if l == 0 then i else (array_find !contains_array i j)
- in
-(* Printf.printf "Looking for text below node %i with tag %s in range %i %i, in array : [|\n%!"
- n (Tag.to_string (tree_tag_id t.doc n)) i j;
- Array.iter (fun i -> Printf.printf "%i " (int_of_node i )) !contains_array;
- Printf.printf "|]\nResult is %i\n%!" id; *)
- if id == nil then
- { t with node=Nil }
- else
- { t with node = Text(id, tree_next_sibling t.doc (tree_prev_doc t.doc id)) }
- | _ -> (*Printf.printf "Here\n%!"; *)
- { t with node = Nil }
-
-let text_next t root =
- let l = Array.length !contains_array in
- let inf = match t.node with
- | Node(n) -> snd(tree_doc_ids t.doc n)+1
- | Text(i,_) -> i+1
- | _ -> assert false
- in
- match root.node with
- | Node (n) ->
- let _,j = tree_doc_ids t.doc n in
- let id = if l == 0 then if inf > j then nil else inf
- else array_find !contains_array inf j
- in
- if id == nil then { t with node= Nil }
- else
- { t with node = Text(id,tree_next_sibling t.doc (tree_prev_doc t.doc id)) }
- | _ -> { t with node = Nil}
-
-
-(*
- let subtree_tags t tag =
- match t with
- { doc = d; node = Node(NC n) } ->
- subtree_tags d n tag
- | _ -> 0
-
- let select_desc_array = ref [| |]
- let idx = ref 0
-
- let init_tagged_next t tagid =
- let l = subtree_tags (root t) tagid
- in
- tagged_desc_array := Array.create l { t with node= Nil };
- let i = ref 0 in
- let rec collect t =
- if is_node t then begin
- if tag t == tagid then
- begin
- !tagged_desc_array.(!i) <- t;
- incr i;
- end;
- collect (first_child t);
- collect (next_sibling t)
- end;
- in
- collect t;
- idx := 0
-
- let print_id ppf v =
- let pr x= Format.fprintf ppf x in
- match v with
- { node=Nil } -> pr "NULLT: -1"
- | { node=String(i) } | { node=Node(SC(i,_)) } -> pr "DocID: %i" (int_of_node i)
- | { node=Node(NC(i)) } -> pr "Node: %i" (int_of_node i)
-
-
-
-(* let tagged_next t tag =
- if !idx >= Array.length !tagged_desc_array
- then {t with node=Nil}
- else
- let r = !tagged_desc_array.(!idx)
- in
- incr idx; r
-*)
-
-
- let has_tagged_foll t tag = is_node (tagged_foll t tag)
- let has_tagged_desc t tag = is_node (tagged_desc t tag)
-
- let contains t s =
- Array.fold_left (fun a i -> DocIdSet.add i a) DocIdSet.empty (Text.contains t.doc s)
-
-
- let contains_old t s =
- let regexp = Str.regexp_string s in
- let matching arg =
- try
- let _ = Str.search_forward regexp arg 0;
- in true
- with _ -> false
- in
- let rec find t acc = match t.node with
- | Nil -> acc
- | String i ->
- if matching (string t) then DocIdSet.add i acc else acc
- | Node(_) -> (find (left t )) ((find (right t)) acc)
- in
- find t DocIdSet.empty
-
-
- let contains_iter t s =
- let regexp = Str.regexp_string s in
- let matching arg =
- try
- let _ = Str.search_forward regexp arg 0;
- in true
- with _ -> false
- in
- let size = Text.size t.doc in
- let rec find acc n =
- if n == size then acc
- else
- find
- (if matching (Text.get_cached_text t.doc (Obj.magic n)) then
- DocIdSet.add (Obj.magic n) acc
- else acc) (n+1)
- in
- find DocIdSet.empty 0
-
-
-
-
- let count_contains t s = Text.count_contains t.doc s
-*)