コード例 #1
0
        /// <summary>The main method, which is essentially the same as in CRFClassifier.</summary>
        /// <remarks>The main method, which is essentially the same as in CRFClassifier. See the class documentation.</remarks>
        /// <exception cref="System.Exception"/>
        public static void Main(string[] args)
        {
            StringUtils.LogInvocationString(log, args);
            Properties props = StringUtils.ArgsToProperties(args);
            CRFBiasedClassifier <CoreLabel> crf = new CRFBiasedClassifier <CoreLabel>(props);
            string testFile = crf.flags.testFile;
            string loadPath = crf.flags.loadClassifier;

            if (loadPath != null)
            {
                crf.LoadClassifierNoExceptions(loadPath, props);
            }
            else
            {
                if (crf.flags.loadJarClassifier != null)
                {
                    // legacy support of old option
                    crf.LoadClassifierNoExceptions(crf.flags.loadJarClassifier, props);
                }
                else
                {
                    crf.LoadDefaultClassifier();
                }
            }
            if (crf.flags.classBias != null)
            {
                StringTokenizer biases = new StringTokenizer(crf.flags.classBias, ",");
                while (biases.HasMoreTokens())
                {
                    StringTokenizer bias  = new StringTokenizer(biases.NextToken(), ":");
                    string          cname = bias.NextToken();
                    double          w     = double.ParseDouble(bias.NextToken());
                    crf.SetBiasWeight(cname, w);
                    log.Info("Setting bias for class " + cname + " to " + w);
                }
            }
            if (testFile != null)
            {
                IDocumentReaderAndWriter <CoreLabel> readerAndWriter = crf.MakeReaderAndWriter();
                if (crf.flags.printFirstOrderProbs)
                {
                    crf.PrintFirstOrderProbs(testFile, readerAndWriter);
                }
                else
                {
                    if (crf.flags.printProbs)
                    {
                        crf.PrintProbs(testFile, readerAndWriter);
                    }
                    else
                    {
                        if (crf.flags.useKBest)
                        {
                            int k = crf.flags.kBest;
                            crf.ClassifyAndWriteAnswersKBest(testFile, k, readerAndWriter);
                        }
                        else
                        {
                            crf.ClassifyAndWriteAnswers(testFile, readerAndWriter, true);
                        }
                    }
                }
            }
        }
コード例 #2
0
 internal CRFBiasedClassifierOptimizer(CRFBiasedClassifier <In> _enclosing, CRFBiasedClassifier <IN> c, IDoubleUnaryOperator e)
 {
     this._enclosing   = _enclosing;
     this.crf          = c;
     this.evalFunction = e;
 }