Source

ocaml-lib / suffix_tree.ml

Diff from to

File suffix_tree.ml

 (**
-   Suffix trees with incremental addition and removal of strings.
+   Suffix trees.
+
+   Suffix trees with incremental addition and removal of strings
    plus incremental maintenance of maximal factors.
+
+
+   Author: S-Aébastien Ferré <ferre@irisa.fr>.-b
+
+   License: LGPL
 *)
 
 (* for test *)
 (*
-#load "unix.cma";;
-#load "str.cma";;
-#load "nums.cma";;
-#load "common.cmo";;
 #load "cis.cmo";;
 #load "lSet.cmo";;
 *)
 
+(* copied from module Common *)
+
+let rec fold_while : ('a -> 'a option) -> 'a -> 'a =
+  fun f e ->
+    match f e with
+    | None -> e
+    | Some e' -> fold_while f e'
+
+let rec mapfind : ('a -> 'b option) -> 'a list -> 'b =
+  fun f -> function
+  | [] -> raise Not_found
+  | x::l -> match f x with
+      | None -> mapfind f l
+      | Some y -> y
+
+(* end of copy *)
+
 module type PARAM =
   sig
-(*    val is_visible : string -> bool *)
     val get_visible : string -> int * int
+	(** [get_visible s] returns the sizes of the prefix and suffix of [s]
+	   that can be removed from [s] without damage to its meaning. *)
   end
 
 module type T =
     let rec max_restrictions st node =
       let res1 = max_restrictions_aux st (LSet.empty ()) (path_restrictions st node) in
       let _, res2 =
-	Common.fold_while
+	fold_while
 	  (fun (res1, res2) ->
 	    match res1 with
 	    | [] -> None
       let factor = find_factor st str in
       match has_end st factor with
       | Some leafs ->
-	  Common.mapfind
+	  mapfind
 	    (fun leaf ->
 	      let (strid,pos) = suffix st leaf in
 	      if pos = 0 then Some strid else None) (* there should be only one *)
 let _ =
   ignore (add st "formal concept analysis");
   ignore (add st "logical concept analysis");
-  ignore (add st "conceptual graphs");;
+  ignore (add st "conceptual graphs");
+  tree st;;
 *)