int fh_ngram(FullHist* fh, int n, int l) { //cerr << "fhng " << n << " " << l << " " // << fh->pos << " " << *fh->e << endl; static int stopTermInt = -1; if(stopTermInt < 0) stopTermInt = Term::stopTerm->toInt(); int pos = fh->pos; int hpos = fh->hpos; //???; int m = pos + (n * l); if(m < 0) return stopTermInt; if(m > hpos && l > 0) { return stopTermInt; } assert(fh->cb); LeftRightGotIter* lrgi = globalGi[fh->cb->thrdid]; assert(lrgi); if(m >= lrgi->size()) return stopTermInt; Item* got = lrgi->index(m); assert(got); int ans = got->term()->toInt(); return ans; }
int edge_ngram(FullHist* fh, int n, int l) { Edge* edge = fh->e; static int stopTermInt = -1; if(stopTermInt < 0) stopTermInt = Term::stopTerm->toInt(); assert(fh->cb); LeftRightGotIter* lrgi = globalGi[fh->cb->thrdid]; assert(lrgi); int pos = fh->pos; /* the left to right position we are working on is either the far left (0) or the far right */ int hpos = edge->headPos(); int m = pos + (n * l); //wcerr << "eng " << n << " " << l << " " << fh->pos // << " " << m << " " << hpos << " " << *edge << endl; if(m < 0) return stopTermInt; if(m > hpos && l > 0) { return stopTermInt; } if(m >= lrgi->size()) return stopTermInt; Item* got = lrgi->index(m); assert(got); int ans = got->term()->toInt(); return ans; }
int fh_noopenQr(FullHist* fh) { int pos = fh->pos; assert(fh->cb); LeftRightGotIter* lrgi = globalGi[fh->cb->thrdid]; Item* got; int i; bool sawOpen = false; for(i = 0 ; i < lrgi->size() ; i++) { if(i == pos) break; got = lrgi->index(i); const Term* trm = got->term(); if(trm->isOpen()) sawOpen = true; else if(trm->isClosed()) sawOpen = false; } if(sawOpen) return 0; else return 1; }
int edge_noopenQl(FullHist* fh) { Edge* edge = fh->e; int pos = fh->pos; int hpos = edge->headPos(); LeftRightGotIter* lrgi = globalGi[fh->cb->thrdid]; Item* got; int i; bool sawOpen = false; for(i = hpos ; i >= 0 ; i--) { if(i == pos) break; //if(i <= (pos+3)) break; //??? +3 because we already know about next 3; got = lrgi->index(i); const Term* trm = got->term(); if(trm->isClosed()) sawOpen = true; else if(trm->isOpen()) sawOpen = false; } if(sawOpen) return 0; else return 1; }
int edge_noopenQr(FullHist* fh) { Edge* edge = fh->e; int pos = fh->pos; assert(fh->cb); LeftRightGotIter* lrgi = globalGi[fh->cb->thrdid]; Item* got; int i; bool sawOpen = false; for(i = 0 ; i < lrgi->size() ; i++) { if(i == pos) break; //if(i >= pos-3) break; //??? -3 because we already know about last3; got = lrgi->index(i); const Term* trm = got->term(); if(trm->isOpen()) sawOpen = true; else if(trm->isClosed()) sawOpen = false; } if(sawOpen) return 0; else return 1; }