(* camlp4r ./pa_html.cmo *) (* $Id: cousins.ml,v 4.13 2004/12/14 09:30:11 ddr Exp $ *) (* Copyright (c) 1998-2005 INRIA *) open Def; open Gutil; open Util; open Config; value default_max_lev = 5; value default_max_cnt = 2000; (* Utilities *) value max_ancestor_level conf base ip max_lev = let x = ref 0 in let mark = Array.create base.data.persons.len False in let rec loop niveau ip = if mark.(Adef.int_of_iper ip) then () else do { mark.(Adef.int_of_iper ip) := True; x.val := max x.val niveau; if x.val = max_lev then () else match parents (aget conf base ip) with [ Some ifam -> let cpl = coi base ifam in do { loop (succ niveau) (father cpl); loop (succ niveau) (mother cpl) } | _ -> () ] } in do { loop 0 ip; x.val } ; value brother_label conf x = match x with [ 1 -> transl conf "siblings" | 2 -> transl conf "cousins" | 3 -> transl conf "2nd cousins" | 4 -> transl conf "3rd cousins" | n -> Printf.sprintf (ftransl conf "%s cousins") (transl_nth conf "*nth (cousin)*" (n - 1)) ] ; value rec except x = fun [ [] -> [] | [y :: l] -> if x = y then l else [y :: except x l] ] ; value children_of base u = List.fold_right (fun ifam list -> let des = doi base ifam in Array.to_list des.children @ list) (Array.to_list u.family) [] ; value siblings_by conf base iparent ip = let list = children_of base (uget conf base iparent) in except ip list ; value merge_siblings l1 l2 = let l = rev_merge (List.rev l1) l2 where rec rev_merge r = fun [ [((v, _) as x) :: l] -> rev_merge (if List.mem_assoc v r then r else [x :: r]) l | [] -> r ] in List.rev l ; value siblings conf base p = let ip = p.cle_index in match parents (aget conf base ip) with [ Some ifam -> let cpl = coi base ifam in let fath_sib = List.map (fun ip -> (ip, ((father cpl), Male))) (siblings_by conf base (father cpl) ip) in let moth_sib = List.map (fun ip -> (ip, ((mother cpl), Female))) (siblings_by conf base (mother cpl) ip) in merge_siblings fath_sib moth_sib | None -> [] ] ; value rec has_desc_lev conf base lev u = if lev <= 1 then True else List.exists (fun ifam -> let des = doi base ifam in List.exists (fun ip -> has_desc_lev conf base (lev - 1) (uget conf base ip)) (Array.to_list des.children)) (Array.to_list u.family) ; value br_inter_is_empty b1 b2 = List.for_all (fun (ip, _) -> not (List.mem_assoc ip b2)) b1 ; (* Algorithms *) value print_choice conf base p niveau_effectif = tag "form" "method=get action=\"%s\"" conf.command begin Util.hidden_env conf; Wserver.wprint "\n"; wprint_hidden_person conf base "" p; tag "select" "name=v1" begin let rec boucle i = if i > niveau_effectif then () else do { Wserver.wprint "