Esempio n. 1
0
 private void ProcessResults(TestSentence testS, PrintFile wordsFile, PrintFile unknDictFile, PrintFile topWordsFile, bool verboseResults)
 {
     numSentences++;
     testS.WriteTagsAndErrors(testS.finalTags, unknDictFile, verboseResults);
     if (writeUnknDict)
     {
         testS.PrintUnknown(numSentences, unknDictFile);
     }
     if (writeTopWords)
     {
         testS.PrintTop(topWordsFile);
     }
     testS.UpdateConfusionMatrix(testS.finalTags, confusionMatrix);
     numWrong        = numWrong + testS.numWrong;
     numRight        = numRight + testS.numRight;
     unknownWords    = unknownWords + testS.numUnknown;
     numWrongUnknown = numWrongUnknown + testS.numWrongUnknown;
     if (testS.numWrong == 0)
     {
         numCorrectSentences++;
     }
     if (verboseResults)
     {
         log.Info("Sentence number: " + numSentences + "; length " + (testS.size - 1) + "; correct: " + testS.numRight + "; wrong: " + testS.numWrong + "; unknown wrong: " + testS.numWrongUnknown);
         log.Info("  Total tags correct: " + numRight + "; wrong: " + numWrong + "; unknown wrong: " + numWrongUnknown);
     }
 }
Esempio n. 2
0
            public virtual TestSentence Process(IList <TaggedWord> taggedSentence)
            {
                TestSentence testS = new TestSentence(maxentTagger);

                testS.SetCorrectTags(taggedSentence);
                testS.TagSentence(taggedSentence, false);
                return(testS);
            }
Esempio n. 3
0
        /// <summary>Test on a file containing correct tags already.</summary>
        /// <remarks>
        /// Test on a file containing correct tags already. when init'ing from trees
        /// TODO: Add the ability to have a second transformer to transform output back; possibly combine this method
        /// with method below
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        private void Test()
        {
            numSentences    = 0;
            confusionMatrix = new ConfusionMatrix <string>();
            PrintFile pf  = null;
            PrintFile pf1 = null;
            PrintFile pf3 = null;

            if (writeWords)
            {
                pf = new PrintFile(saveRoot + ".words");
            }
            if (writeUnknDict)
            {
                pf1 = new PrintFile(saveRoot + ".un.dict");
            }
            if (writeTopWords)
            {
                pf3 = new PrintFile(saveRoot + ".words.top");
            }
            bool verboseResults = config.GetVerboseResults();

            if (config.GetNThreads() != 1)
            {
                MulticoreWrapper <IList <TaggedWord>, TestSentence> wrapper = new MulticoreWrapper <IList <TaggedWord>, TestSentence>(config.GetNThreads(), new TestClassifier.TestSentenceProcessor(maxentTagger));
                foreach (IList <TaggedWord> taggedSentence in fileRecord.Reader())
                {
                    wrapper.Put(taggedSentence);
                    while (wrapper.Peek())
                    {
                        ProcessResults(wrapper.Poll(), pf, pf1, pf3, verboseResults);
                    }
                }
                wrapper.Join();
                while (wrapper.Peek())
                {
                    ProcessResults(wrapper.Poll(), pf, pf1, pf3, verboseResults);
                }
            }
            else
            {
                foreach (IList <TaggedWord> taggedSentence in fileRecord.Reader())
                {
                    TestSentence testS = new TestSentence(maxentTagger);
                    testS.SetCorrectTags(taggedSentence);
                    testS.TagSentence(taggedSentence, false);
                    ProcessResults(testS, pf, pf1, pf3, verboseResults);
                }
            }
            if (pf != null)
            {
                pf.Close();
            }
            if (pf1 != null)
            {
                pf1.Close();
            }
            if (pf3 != null)
            {
                pf3.Close();
            }
        }