Esempio n. 1
0
            public virtual void RecordScore(IKBestViterbiParser parser, PrintWriter pw)
            {
                double score = parser.GetBestScore();

                totScore += score;
                n++;
                if (pw != null)
                {
                    pw.Print(str + " score: " + nf.Format(score));
                    if (runningAverages)
                    {
                        pw.Print(" average score: " + nf.Format(totScore / n));
                    }
                    pw.Println();
                }
            }
        internal LexicalizedParserQuery(LexicalizedParser parser)
        {
            this.op = parser.GetOp();
            BinaryGrammar      bg         = parser.bg;
            UnaryGrammar       ug         = parser.ug;
            ILexicon           lex        = parser.lex;
            IDependencyGrammar dg         = parser.dg;
            IIndex <string>    stateIndex = parser.stateIndex;
            IIndex <string>    wordIndex  = new DeltaIndex <string>(parser.wordIndex);
            IIndex <string>    tagIndex   = parser.tagIndex;

            this.debinarizer     = new Debinarizer(op.forceCNF);
            this.boundaryRemover = new BoundaryRemover();
            if (op.doPCFG)
            {
                if (op.testOptions.iterativeCKY)
                {
                    pparser = new IterativeCKYPCFGParser(bg, ug, lex, op, stateIndex, wordIndex, tagIndex);
                }
                else
                {
                    pparser = new ExhaustivePCFGParser(bg, ug, lex, op, stateIndex, wordIndex, tagIndex);
                }
            }
            else
            {
                pparser = null;
            }
            if (op.doDep)
            {
                dg.SetLexicon(lex);
                if (!op.testOptions.useFastFactored)
                {
                    dparser = new ExhaustiveDependencyParser(dg, lex, op, wordIndex, tagIndex);
                }
                else
                {
                    dparser = null;
                }
            }
            else
            {
                dparser = null;
            }
            if (op.doDep && op.doPCFG)
            {
                if (op.testOptions.useFastFactored)
                {
                    MLEDependencyGrammar mledg = (MLEDependencyGrammar)dg;
                    int numToFind = 1;
                    if (op.testOptions.printFactoredKGood > 0)
                    {
                        numToFind = op.testOptions.printFactoredKGood;
                    }
                    bparser = new FastFactoredParser(pparser, mledg, op, numToFind, wordIndex, tagIndex);
                }
                else
                {
                    IScorer scorer = new TwinScorer(pparser, dparser);
                    //Scorer scorer = parser;
                    if (op.testOptions.useN5)
                    {
                        bparser = new BiLexPCFGParser.N5BiLexPCFGParser(scorer, pparser, dparser, bg, ug, dg, lex, op, stateIndex, wordIndex, tagIndex);
                    }
                    else
                    {
                        bparser = new BiLexPCFGParser(scorer, pparser, dparser, bg, ug, dg, lex, op, stateIndex, wordIndex, tagIndex);
                    }
                }
            }
            else
            {
                bparser = null;
            }
            subcategoryStripper = op.tlpParams.SubcategoryStripper();
        }