Exemplo n.º 1
0
        internal static POSSample CreatePredSample()
        {
            const string sentence = "the_DT stories_NNS about_NNS well-heeled_JJ " +
                                    "communities_NNS and_CC developers_CC";

            return(POSSample.Parse(sentence));
        }
Exemplo n.º 2
0
            public virtual void add(POSSample reference, POSSample prediction)
            {
                int length = reference.Sentence.Length;

                averageSentenceLength.add(length);

                if (minimalSentenceLength > length)
                {
                    minimalSentenceLength = length;
                }
                if (maximumSentenceLength < length)
                {
                    maximumSentenceLength = length;
                }

                string[] toks  = reference.Sentence;
                string[] refs  = reference.Tags;
                string[] preds = prediction.Tags;

                updateTagFMeasure(refs, preds);

                for (int i = 0; i < toks.Length; i++)
                {
                    add(toks[i], refs[i], preds[i]);
                }
            }
Exemplo n.º 3
0
        public void TestParse()
        {
            const string sentence = "the_DT stories_NNS about_IN well-heeled_JJ " +
                                    "communities_NNS and_CC developers_NNS";

            var sample = POSSample.Parse(sentence);

            Assert.AreEqual(sentence, sample.ToString());
        }
Exemplo n.º 4
0
        public void TestParseEmptyString()
        {
            var sample = POSSample.Parse(string.Empty);

            Assert.AreEqual(0, sample.Sentence.Length);
            Assert.AreEqual(0, sample.Tags.Length);

            var value = sample.ToString();

            Assert.IsEmpty(value);
        }
Exemplo n.º 5
0
        public override void run(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine(Help);
            }
            else
            {
                ChunkerModel model = (new ChunkerModelLoader()).load(new File(args[0]));

                ChunkerME chunker = new ChunkerME(model, ChunkerME.DEFAULT_BEAM_SIZE);

                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)
                    {
                        POSSample posSample;
                        try
                        {
                            posSample = POSSample.parse(line);
                        }
                        catch (InvalidFormatException)
                        {
                            Console.Error.WriteLine("Invalid format:");
                            Console.Error.WriteLine(line);
                            continue;
                        }

                        string[] chunks = chunker.chunk(posSample.Sentence, posSample.Tags);

                        Console.WriteLine((new ChunkSample(posSample.Sentence, posSample.Tags, chunks)).nicePrint());

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

                perfMon.stopAndPrintFinalResult();
            }
        }
Exemplo n.º 6
0
        public void TestOutcomesForSingleSentence()
        {
            const string sentence = "That_DT sounds_VBZ good_JJ ._.";

            var sample = POSSample.Parse(sentence);

            var eventStream = new POSSampleEventStream(new GenericObjectStream <POSSample>(sample));

            Assert.AreEqual("DT", eventStream.Read().Outcome);
            Assert.AreEqual("VBZ", eventStream.Read().Outcome);
            Assert.AreEqual("JJ", eventStream.Read().Outcome);
            Assert.AreEqual(".", eventStream.Read().Outcome);

            Assert.Null(eventStream.Read());
        }
Exemplo n.º 7
0
        public override void run(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine(Help);
            }
            else
            {
                POSModel model = (new POSModelLoader()).load(new File(args[0]));

                POSTaggerME tagger = new POSTaggerME(model);

                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)
                    {
                        string[] whitespaceTokenizerLine = WhitespaceTokenizer.INSTANCE.tokenize(line);
                        string[] tags = tagger.tag(whitespaceTokenizerLine);

                        POSSample sample = new POSSample(whitespaceTokenizerLine, tags);
                        Console.WriteLine(sample.ToString());

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

                perfMon.stopAndPrintFinalResult();
            }
        }
Exemplo n.º 8
0
 public void TestParseWithError()
 {
     Assert.Throws <InvalidFormatException> (() => {
         POSSample.Parse("the_DT stories");
     });
 }
Exemplo n.º 9
0
        public void TestParseEmptyToken()
        {
            var sample = POSSample.Parse("the_DT _NNS");

            Assert.AreEqual(string.Empty, sample.Sentence[1]);
        }
Exemplo n.º 10
0
        public void TestParseEmptyTag()
        {
            var sample = POSSample.Parse("the_DT stories_");

            Assert.AreEqual(string.Empty, sample.Tags[1]);
        }
Exemplo n.º 11
0
 public virtual void correctlyClassified(POSSample reference, POSSample prediction)
 {
     stats.add(reference, prediction);
 }
Exemplo n.º 12
0
        // methods inherited from EvaluationMonitor

        public virtual void missclassified(POSSample reference, POSSample prediction)
        {
            stats.add(reference, prediction);
        }
Exemplo n.º 13
0
 public void TestParseWithError()
 {
     POSSample.Parse("the_DT stories");
 }