Esempio n. 1
0
        private double[] GetExactHistories(History h, IList <Pair <int, Extractor> > extractors, IList <Pair <int, Extractor> > extractorsRare)
        {
            double[] scores   = new double[maxentTagger.ySize];
            int      szCommon = maxentTagger.extractors.Size();

            foreach (Pair <int, Extractor> e in extractors)
            {
                int       kf            = e.First();
                Extractor ex            = e.Second();
                string    val           = ex.Extract(h);
                int[]     fAssociations = maxentTagger.fAssociations[kf][val];
                if (fAssociations != null)
                {
                    for (int i = 0; i < maxentTagger.ySize; i++)
                    {
                        int fNum = fAssociations[i];
                        if (fNum > -1)
                        {
                            scores[i] += maxentTagger.GetLambdaSolve().lambda[fNum];
                        }
                    }
                }
            }
            if (extractorsRare != null)
            {
                foreach (Pair <int, Extractor> e_1 in extractorsRare)
                {
                    int       kf            = e_1.First();
                    Extractor ex            = e_1.Second();
                    string    val           = ex.Extract(h);
                    int[]     fAssociations = maxentTagger.fAssociations[kf + szCommon][val];
                    if (fAssociations != null)
                    {
                        for (int i = 0; i < maxentTagger.ySize; i++)
                        {
                            int fNum = fAssociations[i];
                            if (fNum > -1)
                            {
                                scores[i] += maxentTagger.GetLambdaSolve().lambda[fNum];
                            }
                        }
                    }
                }
            }
            return(scores);
        }
Esempio n. 2
0
 public TestSentence(MaxentTagger maxentTagger)
 {
     // origWords is only set when run with a list of HasWords; when run
     // with a list of strings, this will be null
     // TODO this always has the value of sent.size(). Remove it? [cdm 2008]
     // protected double[][][] probabilities;
     // = 0;
     System.Diagnostics.Debug.Assert((maxentTagger != null));
     System.Diagnostics.Debug.Assert((maxentTagger.GetLambdaSolve() != null));
     this.maxentTagger = maxentTagger;
     if (maxentTagger.config != null)
     {
         tagSeparator = maxentTagger.config.GetTagSeparator();
         encoding     = maxentTagger.config.GetEncoding();
         Verbose      = maxentTagger.config.GetVerbose();
     }
     else
     {
         tagSeparator = TaggerConfig.GetDefaultTagSeparator();
         encoding     = "utf-8";
         Verbose      = false;
     }
     history = new History(pairs, maxentTagger.extractors);
 }
Esempio n. 3
0
        internal virtual string ResultsString(MaxentTagger maxentTagger)
        {
            StringBuilder output = new StringBuilder();

            output.Append(string.Format("Model %s has xSize=%d, ySize=%d, and numFeatures=%d.%n", maxentTagger.config.GetModel(), maxentTagger.xSize, maxentTagger.ySize, maxentTagger.GetLambdaSolve().lambda.Length));
            output.Append(string.Format("Results on %d sentences and %d words, of which %d were unknown.%n", numSentences, numRight + numWrong, unknownWords));
            output.Append(string.Format("Total sentences right: %d (%f%%); wrong: %d (%f%%).%n", numCorrectSentences, numCorrectSentences * 100.0 / numSentences, numSentences - numCorrectSentences, (numSentences - numCorrectSentences) * 100.0 / (numSentences
                                                                                                                                                                                                                                                      )));
            output.Append(string.Format("Total tags right: %d (%f%%); wrong: %d (%f%%).%n", numRight, numRight * 100.0 / (numRight + numWrong), numWrong, numWrong * 100.0 / (numRight + numWrong)));
            if (unknownWords > 0)
            {
                output.Append(string.Format("Unknown words right: %d (%f%%); wrong: %d (%f%%).%n", (unknownWords - numWrongUnknown), 100.0 - (numWrongUnknown * 100.0 / unknownWords), numWrongUnknown, numWrongUnknown * 100.0 / unknownWords));
            }
            return(output.ToString());
        }