示例#1
0
 protected static void PrintMainUsage(string msg)
 {
     Allcea.PrintUsage(msg,
                       "<command> [-h] [...]",
                       "command  the command to run."
                       + "\n-h       shows this help message.",
                       "The available commands are (run '" + Allcea.CLI_NAME_AND_VERSION + " <command> -h' for specific help):"
                       + "\n  estimate  to estimate relevance judgments."
                       + "\n  evaluate  to evaluate systems with estimated judgments."
                       + "\n  next      to obtain the net batch of documents to judge."
                       + "\n  simulate  to simulate the iterative execution of 'estimate', 'evaluate' and 'next'."
                       + "\n  features  to output the features computed by a particular estimator."
                       );
 }
示例#2
0
        protected static void PrintUsage(string msg, string command, Options options, string footer)
        {
            HelpFormatter formatter = new HelpFormatter()
            {
                SyntaxPrefix = ""
            };
            StringWriter wr = new StringWriter();

            wr.Write(command + " ");
            formatter.PrintUsage(wr, Int32.MaxValue, null, options);
            string usageOptions = wr.ToString().Trim();

            wr.Dispose();
            string optionsString = formatter.RenderOptions(new StringBuilder(), Int32.MaxValue, options, 0, 2).ToString();

            Allcea.PrintUsage(msg, usageOptions, optionsString, footer);
        }
示例#3
0
        public static void Main(string[] args)
        {
            //DateTime now = DateTime.Now;
            args = @"simulate -b 5 -n 1 -t rel -i ..\..\..\etc\$$year$$-runs.txt -j ..\..\..\etc\$$year$$-judgments.txt -e mout -p meta=..\..\..\etc\metadata.txt".Replace("$$year$$", args[0]).Split();

            if (args.Length > 0)
            {
                // Check CLI command name
                string          commandName = args[0].ToLower();
                AbstractCommand command     = null;
                switch (commandName)
                {
                case "-h":
                    Allcea.PrintMainUsage(null);
                    Environment.Exit(0);
                    break;

                case "estimate": command = new EstimateCommand(); break;

                case "evaluate": command = new EvaluateCommand(); break;

                case "next": command = new NextCommand(); break;

                case "simulate": command = new SimulateCommand(); break;

                case "features": command = new FeaturesCommand(); break;

                default:
                    Console.Error.WriteLine("'" + commandName + "' is not a valid Allcea command. See '" + Allcea.CLI_NAME_AND_VERSION + " -h'.");
                    Environment.Exit(1);
                    break;
                }
                // Parse CLI options
                Options options = command.Options;
                // help? Cannot wait to parse CLI options because it will throw exception before
                if (options.HasOption("h") && args.Contains("-h"))
                {
                    Allcea.PrintUsage(null, commandName, options, command.OptionsFooter);
                }
                else
                {
                    try {
                        Parser      parser = new BasicParser();
                        CommandLine cmd    = parser.Parse(options, args.Skip(1).ToArray());
                        // If we have extra CLI options the Parse method doesn't throw exception. Handle here
                        if (cmd.Args == null || cmd.Args.Length != 0)
                        {
                            throw new ParseException("Unused option(s): " + string.Join(",", cmd.Args));
                        }
                        // Run command
                        command.CheckOptions(cmd);
                        command.Run();
                    } catch (ParseException pe) {
                        Console.Error.WriteLine((pe.Message.EndsWith(".") ? pe.Message : pe.Message + ".")
                                                + " See '" + Allcea.CLI_NAME_AND_VERSION + " " + commandName + " -h'.");
                        Environment.Exit(1);
                    } catch (Exception ex) {
                        Console.Error.WriteLine(ex.Message);
                        Environment.Exit(1);
                    }
                }
            }
            else
            {
                // No CLI options
                Allcea.PrintMainUsage(null);
                Environment.Exit(1);
            }
            //Console.Error.WriteLine(DateTime.Now.Subtract(now).TotalMilliseconds);
        }