Commit 50c457da authored by bguillaum's avatar bguillaum

new command lien argument

new infos field (replace the old features)

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@8173 7838e531-6607-4d57-9587-6c381814729c
parent 3d7dec0b
VERSION = 2.15.0
VERSION = 2.16.0
INSTALL_DIR = @prefix@@bindir@
DATA_DIR = @prefix@@datarootdir@/dep2pict/
......
This diff is collapsed.
This diff is collapsed.
open Printf
open Log
open Dep2pict
IFDEF BUILD_GUI THEN
open Gui
let gui ?file () = Gui.main ?file ()
let gui ?infos ?file () = Gui.main ?infos ?file ()
ELSE
let input_file = ref None
let output_file = ref None
let gui ?file () = Log.critical "Gui not available"
let gui ?infos ?file () = Log.critical "Gui not available"
END
let _ =
Log.set_active_levels [`INFO];
Log.set_info_label "DEP2PICT";
Log.set_critical_label "DEP2PICT";
Log.set_write_to_log_file false;
Log.set_info_foreground Log.f_green;
Log.set_critical_foreground Log.f_red;
Log.set_critical_background Log.b_default;
Log.set_show_time true
let version = VERSION
let _ =
Log.set_active_levels [`INFO];
Log.set_info_label "DEP2PICT";
Log.set_critical_label "DEP2PICT";
Log.set_write_to_log_file false;
Log.set_info_foreground Log.f_green;
Log.set_critical_foreground Log.f_red;
Log.set_critical_background Log.b_default;
Log.set_show_time true
let usage = String.concat "\n" [
"================================================================================";
"=-=-=-=-= dep2pict a tool to draw dependency graphs =-=-=-=-=";
"";
"Usage:";
" * dep2pict <options> -dep <dep_file> -o <output_file>";
" * dep2pict <options> -conll <conll_file> -o <output_file>";
" * dep2pict <options> input_file output_file convert input_file into output_file" ;
" * dep2pict <options> input_file run the GUI with the given file";
" * dep2pict <options> run the GUI with an empty graph";
"";
"Formats are guessed from file extension:";
" * input formats are: dep, conll, xml";
" * output formats are: png, svg, pdf, dep";
"";
"Options:";
" -png: set output format to png (this is the default)";
" -pdf: set output format to pdf";
" -svg: set output format to svg";
" -dep: set output format to dep";
" -features <string>: set features to display with CONLL input, string should contain a subset of {l,p,s,t,g,m,n} or A (for all). Default is \"\"";
" -ref: add dotted links for ellpsis";
" -v: display version number ("^version^")";
" -i | --infos <string> select infos to display: a '|' separated list of atoms from: \"lemma\", \"pos\", \"lpos\", \"all\", a feature name (default=\"pos\")";
" -p | --position <int> number of the dep structure to display when input file contains sequence (default=0)";
" -v | --version display version number ("^version^")";
" -h | --help show this help";
" -t | --tips add on_mouse_over tips in svg output (for debug purpose)";
"================================================================================";
]
type output = Png | Svg | Pdf | Dep_o
let output = ref Png
type input = Dep | Conll | Xml of int
let input = ref Dep
let debug = ref false
let eps_ref = ref false
let conll_features = ref ""
let _ =
let rec opt = function
| [] -> ()
| "-v"::_ -> printf "%s\n%!" version; exit 0
| "-help"::_ -> printf "%s\n%!" usage; exit 0
| "-conll"::file::tail -> input_file := Some file; input := Conll; opt tail
| "-dep"::file::tail -> input_file := Some file; opt tail
(* NB: the xml option is used by parconine: arg is an integer, the xml_file is given with the -dep option *)
| "-xml"::n::tail -> input := Xml (int_of_string n); opt tail
| "-o"::file::tail -> output_file := Some file; opt tail
| "-png"::tail -> output := Png; opt tail
| "-svg"::tail -> output := Svg; opt tail
| "-pdf"::tail -> output := Pdf; opt tail
| "-out_dep"::tail -> output := Dep_o; opt tail
let input_file = ref None
let output_file = ref None
| "-features"::feats::tail -> conll_features := feats; opt tail
| "-ref"::tail -> eps_ref := true; opt tail
let position = ref 0
let tips = ref false
let infos = ref []
let rec parse_arg = function
| [] -> ()
| "-v"::_ | "--version"::_ -> printf "%s\n%!" version; exit 0
| "-h"::_ | "--help"::_ -> printf "%s\n%!" usage; exit 0
| "-i"::i::tail
| "--infos"::i::tail -> infos := Str.split (Str.regexp " *| *") i
| "-p"::i::tail
| "--position"::i::tail -> position := (int_of_string i); parse_arg tail
| "-t"::tail | "--tips"::tail -> tips := true; parse_arg tail
| s::_ when s.[0] = '-' -> Log.fcritical "Unknwon option \"%s\"" s
| anon :: tail ->
begin
match !input_file with
| None -> input_file := Some anon
| Some _ ->
match !output_file with
| None -> output_file := Some anon
| Some _ -> Log.fcritical "At most two anonymous arguments are allowed, don't know what to do with \"%s\"" anon
end;
parse_arg tail
type format = Dep | Conll | Xml | Png | Svg | Pdf
exception Found of format
let get_format file =
try
List.iter
(fun (ext, fmt) ->
if Filename.check_suffix file ext
then raise (Found fmt)
) [ ("dep", Dep); ("conll",Conll); ("xml",Xml); ("png",Png); ("svg",Svg); ("pdf",Pdf) ];
Log.fcritical "Unkwnow file extension for file \"%s\"" file
with Found fmt -> fmt
| "-d"::tail -> debug := true; opt tail
| others::tail -> Log.fcritical "%s : option unknown!\n%s" others usage
in opt (List.tl (Array.to_list Sys.argv));
let _ =
let () = parse_arg (List.tl (Array.to_list Sys.argv)) in
match (!input_file, !output_file) with
| (None, None) -> gui ()
| (None, Some _) -> Log.critical "No input file."
| (Some file,_) when not (Sys.file_exists file) -> Log.fcritical "The file %s doesn't exist." file
| (Some file, None) -> gui ~file ()
| (None, None) -> gui ~infos:(!infos) ()
| (Some file,_) when not (Sys.file_exists file) -> Log.fcritical "The input file %s doesn't exist." file
| (Some file, None) -> gui ~infos:(!infos) ~file ()
| (Some in_file, Some out_file) ->
try
(match (!input, !output) with
| (Xml i, Png) -> ignore (Dep2pict.fromXmlFileToPng in_file out_file i)
| (Dep, Png) -> ignore (Dep2pict.fromDepFileToPng in_file out_file)
| (Conll, Png) -> ignore (Dep2pict.fromConllFileToPng ~features:!conll_features ~eps_ref:!eps_ref in_file out_file)
| (Xml i, Svg) -> ignore (Dep2pict.fromXmlFileToSvgFile ~debug:(!debug) in_file out_file i)
| (Dep, Svg) -> ignore (Dep2pict.fromDepFileToSvgFile ~debug:(!debug) in_file out_file)
| (Conll, Svg) -> ignore (Dep2pict.fromConllFileToSvgFile ~debug:(!debug) ~features:!conll_features ~eps_ref:!eps_ref in_file out_file)
| (Xml i, Pdf) -> ignore (Dep2pict.fromXmlFileToPdf in_file out_file i)
| (Dep, Pdf) -> ignore (Dep2pict.fromDepFileToPdf in_file out_file)
| (Conll, Pdf) -> ignore (Dep2pict.fromConllFileToPdf ~features:!conll_features ~eps_ref:!eps_ref in_file out_file)
begin
try
match (get_format in_file, get_format out_file) with
| (Xml, Png) -> ignore (Dep2pict.fromXmlFileToPng in_file out_file !position)
| (Dep, Png) -> ignore (Dep2pict.fromDepFileToPng in_file out_file)
| (Conll, Png) -> ignore (Dep2pict.fromConllFileToPng ~infos:!infos in_file out_file)
| (Xml, Svg) -> ignore (Dep2pict.fromXmlFileToSvgFile ~debug:(!tips) in_file out_file !position)
| (Dep, Svg) -> ignore (Dep2pict.fromDepFileToSvgFile ~debug:(!tips) in_file out_file)
| (Conll, Svg) -> ignore (Dep2pict.fromConllFileToSvgFile ~debug:(!tips) ~infos:!infos in_file out_file)
| (Xml, Pdf) -> ignore (Dep2pict.fromXmlFileToPdf in_file out_file !position)
| (Dep, Pdf) -> ignore (Dep2pict.fromDepFileToPdf in_file out_file)
| (Conll, Pdf) -> ignore (Dep2pict.fromConllFileToPdf ~infos:!infos in_file out_file)
| (Conll, Dep_o) -> Dep2pict.fromConllFileToDep ~features:!conll_features ~eps_ref:!eps_ref in_file out_file
| (_, Dep_o) -> Log.fcritical "Conversion from Xml or Dep into Dep is not implemented. Please contact developers if your really need it!"
);
| (Conll, Dep) -> Dep2pict.fromConllFileToDep ~infos:!infos in_file out_file
| (Dep, Dep)
| (Xml, Dep) -> Log.fcritical "Conversion from Xml or Dep into Dep is not implemented. Please contact developers if your really need it!"
| (_, Xml) -> Log.fcritical "Conversion to Xml is not implemented. Please contact developers if your really need it!"
| (Pdf, _) -> Log.fcritical "pdf in not a valid input format"
| (Svg, _) -> Log.fcritical "svg in not a valid input format"
| (Png, _) -> Log.fcritical "png in not a valid input format"
| (_, Conll) -> Log.fcritical "conll in not a valid output format"
with
| Dep2pict.Parse_error msgs -> List.iter (fun (l,m) -> printf "Line %d: %s\n" l m) msgs; Log.fcritical "Parse error"
| Dep2pict.Id_already_in_use_ id -> Log.fcritical "Id already in use : %s" id
| Dep2pict.Unknown_index id -> Log.fcritical "Can't find index: %s" id
| Dep2pict.Loop_in_dep msg -> Log.fcritical "Loop in dependency : %s" msg
end;
Log.finfo "File %s generated." out_file
| (None, Some _) -> Log.bug "Some output without input!"
Log.finfo "File %s generated." out_file
with
| Dep2pict.Parse_error msgs -> List.iter (fun (l,m) -> printf "Line %d: %s\n" l m) msgs; Log.fcritical "Parse error"
| Dep2pict.Id_already_in_use_ id -> Log.fcritical "Id already in use : %s" id
| Dep2pict.Unknown_index id -> Log.fcritical "Can't find index: %s" id
| Dep2pict.Loop_in_dep msg -> Log.fcritical "Loop in dependency : %s" msg
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