double MeChart:: triGram() { int i, wInt; double ans = 1.0; double np; FullHist fh; fh.cb = this; for(i = 0 ; i < wrd_count_ ; i++) { wInt = sentence_[i].toInt(); if(wInt > lastKnownWord) { ans *= .0006; //unknown word prob = .0006/600 = .000001 continue; } fh.pos = i; np = meProb(wInt, &fh, WWCALC); if(printDebug() > 30) cerr << "Wprob " << i << " " << wInt<< " " << np << endl; ans *= np; ans *= 600; } fh.pos = wrd_count_; ECString tmp(Bchart::HEADWORD_S1); wInt = wtoInt(tmp); np = meProb(wInt, &fh, WWCALC); ans *= np; return ans; }
Bchart:: Bchart(SentRep & sentence, int id) : ChartBase( sentence,id ), depth(0), curDir(-1), gcurVal(NULL), alreadyPopedNum( 0 ) { LARGE_INTEGER frequency, start; QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&start); pretermNum = 0; heap = new EdgeHeap(); int len = sentence.length(); lastWord[id]=lastKnownWord; int i,j; assert(len <= MAXSENTLEN); Char temp[512]; for(i = 0 ; i < len ; i++) { ECString wl = toLower(sentence[i].lexeme().c_str(), temp); int val = wtoInt(wl); sentence_[i].toInt() = val; } for(i = 0 ; i < MAXSENTLEN ; i++) for(j = 0 ; j < MAXSENTLEN ; j++) curDemerits_[i][j] = 0; }
Bchart:: Bchart(SentRep & sentence) : ChartBase( sentence ) { pretermNum = 0; heap = new EdgeHeap(); int len = sentence.length(); int i,j; assert(len <= MAXSENTLEN); char temp[512]; for(i = 0 ; i < len ; i++) { ECString wl = toLower(sentence[i].lexeme().c_str(), temp); int val = wtoInt(wl); sentence_[i].toInt() = val; } for(i = 0 ; i < MAXSENTLEN ; i++) for(j = 0 ; j < MAXSENTLEN ; j++) curDemerits_[i][j] = 0; initDenom(); }
Bchart:: Bchart(SentRep & sentence, int id) : ChartBase( sentence,id ), depth(0), curDir(-1), gcurVal(NULL), alreadyPoppedNum( 0 ) { pretermNum = 0; heap = new EdgeHeap(); int len = sentence.length(); lastWord[id]=lastKnownWord; int i,j; assert(len <= MAXSENTLEN); for(i = 0 ; i < len ; i++) { ECString wl = langAwareToLower(sentence[i].lexeme()); int val = wtoInt(wl); sentence_[i].toInt() = val; } for(i = 0 ; i < MAXSENTLEN ; i++) for(j = 0 ; j < MAXSENTLEN ; j++) curDemerits_[i][j] = 0; }
Item* Bchart:: edgesFromTree(InputTree* tree) { int b, b0; b0 = tree->num(); const Term* trm = Term::get(tree->term()); assert(trm); //cerr << "ARI " << *trm << " " << b0 << endl; if(printDebug() > 1005) cerr << "EFIE " << trm->name() << " " << b0 << endl; /* If this is a terminal node, the rhs will be a word; otherwise it will be a rule expansion consisting of several Item s. */ if(trm->terminal_p()) { ECString tmpW1 = tree->word(); char chars[512]; ECString tmpW = toLower(tmpW1.c_str(), chars); int wInt = wtoInt(tmpW); Item* lhs = add_item(b0, trm, tree->start()); lhs->start() = tree->start(); lhs->finish() = tree->finish(); Item* rhs = add_item2(b0, trm, wInt,tmpW); rhs->finish() = tree->finish(); rhs->start() = tree->start(); if(!lhs && !rhs) { return NULL; } Items subItems; subItems.push_back(stops[tree->start()]); subItems.push_back(rhs); subItems.push_back(stops[tree->finish()]); Edge* edg = add_edge(lhs, subItems); if(!edg) { return NULL; } edg->prob() = pHst(wInt,trm->toInt()); edg->num() = b0; if(printDebug() > 5) cerr << "LHS " << *lhs << " " << tmpW << edg->prob() << endl; return lhs; } else { Item* lhs = add_item(b0, trm, -1); lhs->start() = tree->start(); lhs->finish() = tree->finish(); assert(lhs); Items subItems; subItems.push_back(stops[tree->start()]); InputTreesIter iti = tree->subTrees().begin(); for( ; iti != tree->subTrees().end() ; iti++) { InputTree* stree = (*iti); cerr << "WBA "<< stree->term() << *stree << endl; Item* itm = edgesFromTree(stree); if(!itm) { return NULL; } subItems.push_back(itm); } subItems.push_back(stops[tree->finish()]); Edge* edg = add_edge(lhs, subItems); if(!edg) { return false; } edg->num() = b0; assignRProb(edg); if (printDebug() > 5) { cerr << "Saw edge " << *edg << ": p=" << edg->prob() << endl; } //cerr << "endeFE " << *edg << endl; return lhs; rPendFactor(); } }