- type t = { doc : doc;
- node : descr }
-
- let dump { doc=t } = Tree.print_skel t
- module DocIdSet = struct
- include Set.Make (struct type t = string_content
- let compare = (-) end)
-
- end
- let get_string t (i:string_content) = Text.get_text t.doc i
- open Tree
- let node_of_t t = { doc= t;
- node = Node(NC (root t)) }
-
-
- let parse_xml_uri str = node_of_t
- (MM((parse_xml_uri str
- !Options.sample_factor
- !Options.index_empty_texts
- !Options.disable_text_collection),__LOCATION__))
-
- let parse_xml_string str = node_of_t
- (MM((parse_xml_string str
- !Options.sample_factor
- !Options.index_empty_texts
- !Options.disable_text_collection),__LOCATION__))
-
-
- let save t str = save_tree t.doc str
-
- let load ?(sample=64) str = node_of_t (load_tree str sample)
-
-
- external pool : doc -> Tag.pool = "%identity"
- let tag_pool t = pool t.doc
-
- let compare a b = match a.node,b.node with
- | Node(NC i),Node(NC j) -> compare i j
- | _, Node(NC( _ )) -> 1
- | Node(SC (i,_)),Node(SC (j,_)) -> compare i j
- | Node(NC( _ )),Node(SC (_,_)) -> -1
- | _, Node(SC (_,_)) -> 1
- | String i, String j -> compare i j
- | Node _ , String _ -> -1
- | _ , String _ -> 1
- | Nil, Nil -> 0
- | _,Nil -> -1
-
- let equal a b = (compare a b) == 0
-
- let string t = match t.node with
- | String i -> Text.get_text t.doc i
- | _ -> assert false
-
- let norm (n : [`Tree ] node ) = if is_nil n then Nil else Node (NC n)
-
- let descr t = t.node
-
- let nts = function
- Nil -> "Nil"
- | String i -> Printf.sprintf "String %i" i
- | Node (NC t) -> Printf.sprintf "Node (NC %i)" (int_of_node t)
- | Node (SC (t,i)) -> Printf.sprintf "Node (SC (%i,%i))" (int_of_node t) (int_of_node i)
-
-
- let parent n =
- let node' =
- match n.node with
- | Node(NC t) | Node(SC (_,t)) ->
- if (Tree.root n.doc) == t
- then Nil
- else Node(NC(Tree.parent n.doc t)) (* A parent node can never be a SC *)
- | _ -> assert false
- in
- { n with node = node' }
-
- let first_child n =
- let node' =
- match n.node with
- | Node (NC t) when is_leaf n.doc t ->
- let txt = my_text n.doc t in
- if Text.is_empty n.doc txt
- then Nil
- else Node(SC (txt,Tree.nil))
- | Node (NC t) ->
- let fs = first_child n.doc t in
- let txt = prev_text n.doc fs in
- if Text.is_empty n.doc txt
- then norm fs
- else Node (SC (txt, fs))
- | Node(SC (i,_)) -> String i
- | Nil | String _ -> failwith "first_child"
- in
- { n with node = node'}