make_lex.ml 1.24 KB
Newer Older
huet's avatar
huet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
(**************************************************************************)
(*                                                                        *)
(*                 The Zen Computational Linguistics Toolkit              *)
(*                                                                        *)
(*                              Grard Huet                               *)
(*                                                                        *)
(* 2002 Institut National de Recherche en Informatique et en Automatique *)
(**************************************************************************)

(* Trie lexicon building from text file containing lists of words *)

module Make_lex (Encoding: sig 
  value encode : string -> Word.word;
  value decode : Word.word -> string; end) = struct

value lexicon = ref Trie.empty
;
value trie_of_strings =
  let lexicon = ref Trie.empty in process_strings 
    where rec process_strings () =
       try while True do 
         { let str = read_line () in 
           lexicon.val:=Trie.enter lexicon.val (Encoding.encode str) 
         }
       with [ End_of_file -> output_value stdout lexicon.val 
            | Trie.Redundancy -> output_string stderr "Fatal error: duplicated word\n"
            ]
;
end
;