Commit 748c152b authored by bguillaum's avatar bguillaum

small fixes interface & stats

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@6852 7838e531-6607-4d57-9587-6c381814729c
parent 16cbc5a3
......@@ -131,7 +131,7 @@ module G_fs = struct
let get_main ?main_feat t =
let main_list = match main_feat with
| None -> []
| Some string -> Str.split (Str.regexp "( *; *)\\|#") string in
| Some string -> Str.split (Str.regexp "\\( *; *\\)\\|#") string in
let rec loop = function
| [] -> (None, t)
......
......@@ -338,7 +338,7 @@ module G_graph = struct
(fun node_id node ->
match G_node.merge_key src_gid tar_gid node with
| Some n -> n
| None -> Error.run ~loc "[Graph.shift_edges] create duplicate edge"
| None -> Error.run ~loc "[Graph.shift_in] create duplicate edge"
) graph.map
in {graph with map = new_map}
......@@ -349,7 +349,7 @@ module G_graph = struct
let tar_node = Gid_map.find tar_gid graph.map in
if Massoc.mem_key tar_gid (G_node.get_next src_node)
then Error.run ~loc "[Graph.shift_edges] dependency from src to tar";
then Error.run ~loc "[Graph.shift_out] dependency from src to tar";
let new_map =
Gid_map.mapi
......@@ -361,7 +361,7 @@ module G_graph = struct
then
match G_node.shift_out src_node tar_node with
| Some n -> n
| None -> Error.run ~loc "[Graph.shift_edges] common successor"
| None -> Error.run ~loc "[Graph.shift_out] common successor"
else node (* other nodes don't change *)
) graph.map
in {graph with map = new_map}
......
......@@ -118,8 +118,6 @@ IFDEF DEP2PICT THEN
let id = sprintf "id_%d" (i+1) in
(* fprintf html_ch "<a style=\"cursor:pointer;\" onClick=\"if (document.getElementById('%s').style.display == 'none') { document.getElementById('%s').style.display = 'block'; document.getElementById('p_%s').innerHTML = 'Hide applied rules'; } else { document.getElementById('%s').style.display = 'none';; document.getElementById('p_%s').innerHTML = 'Show applied rules'; }\"><b><p id=\"p_%s\">Show applied rules</p></b></a>\n" id id id id id id; *)
fprintf html_ch "<a style=\"cursor:pointer;\"\n";
fprintf html_ch " onClick=\"if (document.getElementById('%s').style.display == 'none')\n" id;
fprintf html_ch " { document.getElementById('%s').style.display = 'block'; document.getElementById('p_%s').innerHTML = 'Hide applied rules'; }\n" id id;
......@@ -447,17 +445,53 @@ module Corpus_stat = struct
IntMap.add sol (StringSet.add base_name old) t.amb in
{ t with map = new_map; num = t.num+1; amb=new_amb; }
let save_html ~title ~grs_file ~html ~output_dir t =
let ratio nb = (float nb) /. (float t.num) *. 100. in
let out_ch = open_out (Filename.concat output_dir "index.html") in
let unfoldable_set out_ch ?(bound=10) html id file_set =
let counter = ref 0 in
let css = "<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">" in
StringSet.iter
(fun file ->
if !counter = bound
then fprintf out_ch "<div id=\"%s\" style=\"display:none;\">\n" id;
incr counter;
let link = if html then sprintf "<a href=\"%s.html\">%s</a>" file file else file in
fprintf out_ch "%s &nbsp;&nbsp;\n" link
) file_set;
if (!counter > bound)
then
begin
fprintf out_ch "</div>\n";
let if_part = sprintf "document.getElementById('%s').style.display = 'block'; document.getElementById('p_%s').innerHTML = '- Show first %d -';" id id bound in
let else_part = sprintf "document.getElementById('%s').style.display = 'none'; document.getElementById('p_%s').innerHTML = '+ Show all +';" id id in
fprintf out_ch " <div>\n";
fprintf out_ch " <a style=\"cursor:pointer;\" onClick=\"if (document.getElementById('%s').style.display == 'none') { %s } else { %s }\">\n" id if_part else_part;
fprintf out_ch " <b><p id=\"p_%s\">+ Show all +</p></b>\n" id;
fprintf out_ch " </a>\n";
fprintf out_ch " </div>\n";
end
let save_html ~title ~grs_file ~html ~output_dir t =
(* a fucntion to get the ration wrt the full set [t] *)
let ratio nb = (float nb) /. (float t.num) *. 100. in
(* put the css file the [output_dir] *)
ignore(Sys.command("cp "^(Filename.concat DATA_DIR "style.css")^" "^(Filename.concat output_dir "style.css")));
fprintf out_ch "<head>\n%s\n<title>%s</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head>\n" css title;
(* output of index.html *)
let out_ch = open_out (Filename.concat output_dir "index.html") in
fprintf out_ch "<head>\n";
fprintf out_ch " <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">\n";
fprintf out_ch " <title>%s</title>\n" title;
fprintf out_ch " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
fprintf out_ch "</head>\n";
fprintf out_ch "<h1>%s</h1>\n" title;
fprintf out_ch "<b>Grs file</b>:<a href =\"%s\">%s</a>\n<br/>\n" (Filename.basename grs_file) (Filename.basename grs_file);
fprintf out_ch "<b>%d Sentences</b><br/>\n<br/>\n" t.num;
......@@ -484,54 +518,23 @@ module Corpus_stat = struct
StringMap.iter
(fun rule (occ_num, file_set) ->
let file_list = StringSet.elements file_set in
let tmp = ref "" in
let counter = ref 0 in
let rec compute list = match list with
| [] -> ()
| h::[] ->
if (!counter = 10) then (
tmp := sprintf "%s<div id=\"%s_%s\" style=\"display:none;\">\n" !tmp modul rule
);
incr counter;
if html
then tmp := sprintf "%s\n <a href=\"%s.html\">%s</a> &nbsp; &nbsp;" !tmp h h
else tmp := sprintf "%s\n %s &nbsp; &nbsp;" !tmp h
| h::t ->
if (not (List.mem h t)) then ( (*avoid doublons*)
if (!counter = 10) then (
tmp := sprintf "%s<div id=\"%s_%s\" style=\"display:none;\">\n" !tmp modul rule
);
incr counter;
if html
then tmp := sprintf "%s\n <a href=\"%s.html\">%s</a>&nbsp;&nbsp;" !tmp h h
else tmp := sprintf "%s\n %s&nbsp;&nbsp;" !tmp h
);
compute t
in compute file_list;
if file_list = [] then tmp := "&nbsp;";
let file_num = List.length file_list in
let id = sprintf "%s_%s" modul rule in
let file_num = StringSet.cardinal file_set in
fprintf out_ch "<tr>\n";
fprintf out_ch "<td class=\"first_stats\" valign=top>%s</td>\n" rule;
fprintf out_ch "<td class=\"stats\" valign=top>%d</td>\n" occ_num;
fprintf out_ch "<td class=\"stats\" valign=top>%d</td>\n" file_num;
fprintf out_ch "<td class=\"stats\" valign=top>%.2f%%</td>\n" (ratio file_num);
fprintf out_ch "<td class=\"stats\">%s" !tmp;
if (!counter > 10)
then (
fprintf out_ch "</div><a style=\"cursor:pointer;\" onClick=\"if (document.getElementById('%s_%s').style.display == 'none') { %s } else { %s }\"><b><p id=\"p_%s_%s\">+ Show all +</p></b></a>\n"
modul rule
(sprintf "document.getElementById('%s_%s').style.display = 'block'; document.getElementById('p_%s_%s').innerHTML = '- Show first ten -';" modul rule modul rule)
(sprintf "document.getElementById('%s_%s').style.display = 'none';; document.getElementById('p_%s_%s').innerHTML = '+ Show all +';" modul rule modul rule)
modul rule;
);
fprintf out_ch "</td></tr>\n";
fprintf out_ch " <td class=\"first_stats\" valign=top>%s</td>\n" rule;
fprintf out_ch " <td class=\"stats\" valign=top>%d</td>\n" occ_num;
fprintf out_ch " <td class=\"stats\" valign=top>%d</td>\n" file_num;
fprintf out_ch " <td class=\"stats\" valign=top>%.2f%%</td>\n" (ratio file_num);
fprintf out_ch " <td class=\"stats\">\n";
(if file_num = 0
then fprintf out_ch " &nbsp;"
else unfoldable_set out_ch html id file_set);
fprintf out_ch " </td>\n";
fprintf out_ch "</tr>\n";
) rules;
) t.modules;
......@@ -544,22 +547,24 @@ module Corpus_stat = struct
IntMap.iter
(fun num set ->
let id = sprintf "amb_%d" num in
let num_files = StringSet.cardinal set in
fprintf out_ch "<tr>\n";
fprintf out_ch "<td class=\"first_stats\">%d</td>\n" num;
fprintf out_ch "<td class=\"stats\" colspan=2>%d</td>\n" num_files;
fprintf out_ch "<td class=\"stats\">%.2f%%</td>\n" (ratio num_files);
fprintf out_ch "<td class=\"stats\">";
StringSet.iter
(fun (file) ->
if html
then fprintf out_ch "<a href=\"%s.html\">%s</a><br/>" file file
else fprintf out_ch "%s<br/>" file
) set;
fprintf out_ch "</td>\n";
fprintf out_ch "</tr>") t.amb
fprintf out_ch " <td class=\"first_stats\">%d</td>\n" num;
fprintf out_ch " <td class=\"stats\" colspan=2>%d</td>\n" num_files;
fprintf out_ch " <td class=\"stats\">%.2f%%</td>\n" (ratio num_files);
fprintf out_ch " <td class=\"stats\">";
(* StringSet.iter *)
(* (fun (file) -> *)
(* if html *)
(* then fprintf out_ch "<a href=\"%s.html\">%s</a><br/>" file file *)
(* else fprintf out_ch "%s<br/>" file *)
(* ) set; *)
unfoldable_set out_ch html id set;
fprintf out_ch " </td>\n";
fprintf out_ch "</tr>\n") t.amb
end;
......
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