public override void run(string format, string[] args)
        {
            base.run(format, args);

            mlParams = CmdLineUtil.loadTrainingParameters(@params.Params, false);
            if (mlParams == null)
            {
                mlParams = ModelUtil.createTrainingParameters(@params.Iterations.Value, @params.Cutoff.Value);
            }

            SDCrossValidator validator;

            SentenceDetectorEvaluationMonitor errorListener = null;

            if (@params.Misclassified.Value)
            {
                errorListener = new SentenceEvaluationErrorListener();
            }

            char[] eos = null;
            if (@params.EosChars != null)
            {
                eos = @params.EosChars.ToCharArray();
            }

            try
            {
                Dictionary abbreviations          = SentenceDetectorTrainerTool.loadDict(@params.AbbDict);
                SentenceDetectorFactory sdFactory = SentenceDetectorFactory.create(@params.Factory, @params.Lang, true, abbreviations, eos);
                validator = new SDCrossValidator(@params.Lang, mlParams, sdFactory, errorListener);

                validator.evaluate(sampleStream, @params.Folds.Value);
            }
            catch (IOException e)
            {
                throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.Message, e);
            }
            finally
            {
                try
                {
                    sampleStream.close();
                }
                catch (IOException)
                {
                    // sorry that this can fail
                }
            }

            FMeasure result = validator.FMeasure;

            Console.WriteLine(result.ToString());
        }
Пример #2
0
        public override void run(string format, string[] args)
        {
            base.run(format, args);

            SentenceModel model = (new SentenceModelLoader()).load(@params.Model);

            SentenceDetectorEvaluationMonitor errorListener = null;

            if (@params.Misclassified.Value)
            {
                errorListener = new SentenceEvaluationErrorListener();
            }

            SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator(new SentenceDetectorME(model), errorListener);

            Console.Write("Evaluating ... ");
            try
            {
                evaluator.evaluate(sampleStream);
            }
            catch (IOException e)
            {
                throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.Message, e);
            }
            finally
            {
                try
                {
                    sampleStream.close();
                }
                catch (IOException)
                {
                    // sorry that this can fail
                }
            }

            Console.Error.WriteLine("done");

            Console.WriteLine();

            Console.WriteLine(evaluator.FMeasure);
        }