Esempio n. 1
0
        public override ObjectStream <CorefSample> create(string[] args)
        {
            Parameters @params = ArgumentParser.parse(args, typeof(Parameters));

            CmdLineUtil.checkInputFile("Data", @params.Data);
            FileInputStream sampleDataIn = CmdLineUtil.openInFile(@params.Data);

            ObjectStream <string> lineStream = new ParagraphStream(new PlainTextByLineStream(sampleDataIn.Channel, @params.Encoding));

            return(new CorefSampleDataStream(lineStream));
        }
        /// <summary>
        /// Perform sentence detection the input stream.
        ///
        /// A newline will be treated as a paragraph boundary.
        /// </summary>
        public override void run(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine(Help);
            }
            else
            {
                SentenceModel model = (new SentenceModelLoader()).load(new File(args[0]));

                SentenceDetectorME sdetector = new SentenceDetectorME(model);

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

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

                try
                {
                    string para;
                    while ((para = paraStream.read()) != null)
                    {
                        string[] sents = sdetector.sentDetect(para);
                        foreach (string sentence in sents)
                        {
                            Console.WriteLine(sentence);
                        }

                        perfMon.incrementCounter(sents.Length);

                        Console.WriteLine();
                    }
                }
                catch (IOException e)
                {
                    CmdLineUtil.handleStdinIoError(e);
                }

                perfMon.stopAndPrintFinalResult();
            }
        }
Esempio n. 3
0
        public override void run(string[] args)
        {
            if (0 == args.Length)
            {
                Console.WriteLine(Help);
            }
            else
            {
                DoccatModel model = (new DoccatModelLoader()).load(new File(args[0]));

                DocumentCategorizerME doccat = new DocumentCategorizerME(model);

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

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

                try
                {
                    string document;
                    while ((document = documentStream.read()) != null)
                    {
                        double[] prob     = doccat.categorize(WhitespaceTokenizer.INSTANCE.tokenize(document));
                        string   category = doccat.getBestCategory(prob);

                        DocumentSample sample = new DocumentSample(category, document);
                        Console.WriteLine(sample.ToString());

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

                perfMon.stopAndPrintFinalResult();
            }
        }