示例#1
0
        public override void run(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(Help);
            }
            else
            {
                ParserModel model = (new ParserModelLoader()).load(new File(args[args.Length - 1]));

                int?beamSize = CmdLineUtil.getIntParameter("-bs", args);
                if (beamSize == null)
                {
                    beamSize = AbstractBottomUpParser.defaultBeamSize;
                }

                int? numParses = CmdLineUtil.getIntParameter("-k", args);
                bool showTopK;
                if (numParses == null)
                {
                    numParses = 1;
                    showTopK  = false;
                }
                else
                {
                    showTopK = true;
                }

                double?advancePercentage = CmdLineUtil.getDoubleParameter("-ap", args);

                if (advancePercentage == null)
                {
                    advancePercentage = AbstractBottomUpParser.defaultAdvancePercentage;
                }

                opennlp.tools.parser.Parser parser = ParserFactory.create(model, beamSize.Value, advancePercentage.Value);

                ObjectStream <string> lineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput));

                PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
                perfMon.start();

                try
                {
                    string line;
                    while ((line = lineStream.read()) != null)
                    {
                        if (line.Length == 0)
                        {
                            Console.WriteLine();
                        }
                        else
                        {
                            Parse[] parses = parseLine(line, parser, numParses.Value);

                            for (int pi = 0, pn = parses.Length; pi < pn; pi++)
                            {
                                if (showTopK)
                                {
                                    Console.Write(pi + " " + parses[pi].Prob + " ");
                                }

                                parses[pi].show();

                                perfMon.incrementCounter();
                            }
                        }
                    }
                }
                catch (IOException e)
                {
                    CmdLineUtil.handleStdinIoError(e);
                }

                perfMon.stopAndPrintFinalResult();
            }
        }