float ChartBase:: endFactorComp(Edge* dnrl) { int start = dnrl->start(); int finish = dnrl->loc(); int effVal = effEnd(finish); ECString tnm(dnrl->lhs()->name()); if((tnm == "S1" || tnm == "S") && finish == wrd_count_ && start == 0) return endFactor; else if(effVal==1) return endFactor; else if(effVal == 0) return midFactor; else return .95; //if effVal == 2, currently not used; }
float ChartBase:: endFactorComp(Edge* dnrl) { int start = dnrl->start(); int finish = dnrl->loc(); int effVal = effEnd(finish); ECString trmNm(dnrl->lhs()->name()); const Term* trm = Term::get(trmNm); if((trm->isRoot() || trm->isS()) && finish == wrd_count_ && start == 0) return endFactor; else if(effVal==1) return endFactor; else if(effVal == 0) return midFactor; else return .95; //if effVal == 2, currently not used; }
Bst& MeChart:: bestParseGivenHead(int posInt, const Wrd& wd, Item* itm, FullHist* h, ItmGHeadInfo& ighInfo, Val* cval, Val* gcval) { EdgeSet& es = ighInfo.first; BstMap& atm = ighInfo.second; curVal = cval; gcurVal = gcval; Bst& bst = recordedBPGH(itm, atm, h); if(bst.explored()) { if(printDebug() > 19) { int subfv[MAXNUMFS]; getHt(h, subfv); CntxArray ca(subfv); prDp(); cerr << "bpknown for " << posInt << ", " << wd << ", " << *itm << ") : " << bst.prob() << " " << ca <<endl; } curVal=gcurVal=NULL; return bst; } bst.explored() = true; curVal=gcurVal=NULL; const Term* trm = itm->term(); if(trm->terminal_p()) { Val* nval = new Val; nval->prob() = 1; nval->trm1() = itm->term()->toInt(); nval->wrd1() = itm->word()->toInt(); nval->status = TERMINALVAL; bst.addnth(nval); bst.sum() = nval->prob(); return bst; } if(printDebug() > 10) { prDp(); cerr << "bestParseGivenHead(" << posInt << ", " << wd << ", " << *itm << ")" << endl; } double bestP = 0; double sumP = 0; EdgeSetIter ei = es.begin(); for( ; ei != es.end() ; ei++) { Edge* e = *ei; if(!sufficiently_likely(e)) { continue; } float edgePg = 1; int finish = e->loc(); int effVal = effEnd(finish); if(itm->term()->isRoot()) edgePg = 1; else if(Feature::isLM) edgePg == 1; else if(effVal == 1) edgePg = endFactor; else if(effVal == 0) edgePg = midFactor; h->e = e; if(printDebug() > 20) { prDp(); cerr << "consid " << *e << endl; } gcurVal = gcval; float prob = meRuleProb(e,h); gcurVal=NULL; double nextP = prob * edgePg; double nextPs = nextP; Item* sitm; //LeftRightGotIter gi(e); MiddleOutGotIter gi(e); Val* val = new Val(e, nextPs); val->trm1() = itm->term()->toInt(); val->wrd1() = wd.toInt(); int pos = 0; depth++; h = h->extendByEdge(e); bool zeroProb = false; while( gi.next(sitm,pos) ) { //cerr << "Looking at " << *sitm << endl; if(zeroProb) { h = h->extendBySubConstit(); continue; } if(sitm->term() == Term::stopTerm) { h = h->extendBySubConstit(); continue; } if(pos == 0) { h->preTerm = posInt; h->hd = &wd; ItmGHeadInfo& ighi = sitm->posAndheads()[posInt][wd]; Bst& bst2 = bestParseGivenHead(posInt,wd,sitm,h,ighi,val,cval); curVal = gcurVal = NULL; curDir = -1; if(bst2.empty()) { zeroProb = true; } val->extendTrees(bst2,pos); nextPs *= bst2.sum(); } else { Bst& bst2 = bestParse(sitm,h,val,cval,pos); if(bst2.empty()) { zeroProb = true; } val->extendTrees(bst2,pos); nextPs *= bst2.sum(); } if(printDebug() > 39) { prDp(); cerr << "FullHist from " << *h; } h = h->extendBySubConstit(); if(printDebug() > 39) cerr << " -> " << *h << endl; } if(!zeroProb) bst.push(val); if(printDebug() > 20) { prDp(); cerr << "P(" << *e << " | " << wd << " ) = " ; cerr << bestP; cerr << "\n"; } depth--; sumP += nextPs; h->retractByEdge(); if(printDebug() > 20) { prDp(); cerr << "Val: " << *val << endl; } } Val* vbest = bst.pop(); if(vbest) bst.addnth(vbest); bst.sum() = sumP; if(printDebug() > 10) { prDp(); cerr << "Bestpgh for "<<*itm << ", " << wd << " = " << bst.prob()<< endl; } return bst; }