Commit 5e1f8dc5 authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

can count without pattern

parent bf54d325
...@@ -221,42 +221,39 @@ let clean () = ...@@ -221,42 +221,39 @@ let clean () =
let count () = let count () =
handle handle
(fun () -> (fun () ->
match !Grew_args.patterns with printf "Corpus\t# sentences";
| [] -> Log.fwarning "No pattern given (use option -patterns)" List.iter (fun p -> printf "\t%s" (p |> Filename.basename |> Filename.remove_extension)) !Grew_args.patterns;
| _ -> printf "\n";
printf "Corpus\t# sentences";
List.iter (fun p -> printf "\t%s" (p |> Filename.basename |> Filename.remove_extension)) !Grew_args.patterns; List.iter (
printf "\n"; fun json_file ->
let corpus_desc_list = Corpus_desc.load_json json_file in
List.iter ( List.iter
fun json_file -> (fun corpus_desc ->
let corpus_desc_list = Corpus_desc.load_json json_file in let config = Corpus_desc.get_config corpus_desc in
List.iter (* NB: pattern loading depends on the config -> reload for each corpus! *)
(fun corpus_desc -> let patterns = List.map (Pattern.load ~config) !Grew_args.patterns in
let config = Corpus_desc.get_config corpus_desc in let id = Corpus_desc.get_id corpus_desc in
(* NB: pattern loading depends on the config -> reload for each corpus! *) let directory = Corpus_desc.get_directory corpus_desc in
let patterns = List.map (Pattern.load ~config) !Grew_args.patterns in let marshal_file = (Filename.concat directory id) ^ ".marshal" in
let id = Corpus_desc.get_id corpus_desc in let in_ch = open_in_bin marshal_file in
let directory = Corpus_desc.get_directory corpus_desc in let data = (Marshal.from_channel in_ch : Corpus.t) in
let marshal_file = (Filename.concat directory id) ^ ".marshal" in let _ = close_in in_ch in
let in_ch = open_in_bin marshal_file in
let data = (Marshal.from_channel in_ch : Corpus.t) in printf "%s" (Filename.basename directory);
let _ = close_in in_ch in printf "\t%d" (Corpus.size data);
printf "%s" (Filename.basename directory); List.iter
printf "\t%d" (Corpus.size data); (fun pattern ->
let count =
List.iter Corpus.fold_left (fun acc _ graph ->
(fun pattern -> acc + (List.length (Graph.search_pattern ~config pattern graph))
let count = ) 0 data in
Corpus.fold_left (fun acc _ graph -> printf "\t%d" count
acc + (List.length (Graph.search_pattern ~config pattern graph)) ) patterns;
) 0 data in printf "\n%!"
printf "\t%d" count ) corpus_desc_list
) patterns; ) (!Grew_args.input_data)
printf "\n%!"
) corpus_desc_list
) (!Grew_args.input_data)
) () ) ()
(* -------------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------------- *)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment