internal FastFactoredParser(ExhaustivePCFGParser pparser, MLEDependencyGrammar dg, Options op, int numToFind, IGrammarProjection projection, IIndex <string> wordIndex, IIndex <string> tagIndex) { this.pparser = pparser; this.projection = projection; this.dg = dg; this.op = op; this.numToFind = numToFind; this.wordIndex = wordIndex; this.tagIndex = tagIndex; }
protected internal override void TallyRoot(Tree lt, double weight) { // this list is in full (not reduced) tag space IList <IntDependency> deps = MLEDependencyGrammar.TreeToDependencyList(lt, wordIndex, tagIndex); foreach (IntDependency dependency in deps) { dependencyCounter.IncrementCount(dependency, weight); } }
public override IDependencyGrammar FormResult() { wordIndex.AddToIndex(LexiconConstants.UnknownWord); MLEDependencyGrammar dg = new MLEDependencyGrammar(tlpParams, directional, useDistance, useCoarseDistance, basicCategoryTagsInDependencyGrammar, op, wordIndex, tagIndex); foreach (IntDependency dependency in dependencyCounter.KeySet()) { dg.AddRule(dependency, dependencyCounter.GetCount(dependency)); } return(dg); }
/// <summary>Use the DependencyGrammar to score the tree.</summary> /// <param name="tr">A binarized tree (as returned by the PCFG parser</param> /// <returns>The score for the tree according to the grammar</returns> private double DepScoreTree(Tree tr) { // log.info("Here's our tree:"); // tr.pennPrint(); // log.info(Trees.toDebugStructureString(tr)); Tree cwtTree = tr.DeepCopy(new LabeledScoredTreeFactory(), new CategoryWordTagFactory()); cwtTree.PercolateHeads(binHeadFinder); // log.info("Here's what it went to:"); // cwtTree.pennPrint(); IList <IntDependency> deps = MLEDependencyGrammar.TreeToDependencyList(cwtTree, wordIndex, tagIndex); // log.info("Here's the deps:\n" + deps); return(dg.ScoreAll(deps)); }
internal FastFactoredParser(ExhaustivePCFGParser pparser, MLEDependencyGrammar dg, Options op, int numToFind, IIndex <string> wordIndex, IIndex <string> tagIndex) : this(pparser, dg, op, numToFind, new NullGrammarProjection(null, null), wordIndex, tagIndex) { }
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(); }