- let tagged_desc_only t td =
- match t with
- | { doc = d; node=Node(NC n) } ->
- let vd = Ptset.to_int_vector td
- in
- { t with node= norm(tagged_desc_only d n vd) }
- | _ -> { t with node=Nil }
-
-
- let last_idx = ref 0
- let array_find a i j =
- let l = Array.length a in
- let rec loop idx x y =
- if x > y || idx >= l then Text.nil
- else
- if a.(idx) >= x then if a.(idx) > y then Text.nil else (last_idx := idx;a.(idx))
- else loop (idx+1) x y
- in
- if a.(0) > j || a.(l-1) < i then Text.nil
- else loop !last_idx i j
-
-
- let text_below t =
- let l = Array.length !contains_array in
- if l = 0 then { t with node=Nil }
- else
- match t with
- | { doc = d; node=Node(NC n) } ->
- let i,j = doc_ids t.doc n in
- let id = array_find !contains_array i j
- in
- if id == Text.nil then
- { t with node=Nil }
- else
- {t with node = Node(SC(id, Tree.next_sibling d (Tree.prev_doc d id))) }
- | _ -> { t with node=Nil }
-
- let text_next t root =
- let l = Array.length !contains_array in
- if l = 0 then { t with node=Nil }
- else
- let inf = match t with
- | { doc =d; node = Node(NC n) } -> snd(doc_ids d n)+1
- | { node = Node(SC(i,_)) } -> i+1
- | _ -> assert false
- in
- match root with
- | { doc = d; node= Node (NC n) } ->
- let _,j = doc_ids t.doc n in
-
- let id = array_find !contains_array inf j
- in
- if id == Text.nil then { doc = d; node= Nil }
- else
- {doc = d; node = Node(SC(id,Tree.next_sibling d (Tree.prev_doc d 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 tagged_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