Beispiel #1
0
int
tree_size(TreeHist* treeh)
{
    static int bucs[9] = {1, 3, 6, 10, 15, 21, 28, 36, 999};
    InputTree* tree = treeh->tree;
    int sz = tree->finish() - tree->start();
    for(int i = 0 ; i < 9 ; i++)
        if(sz <= bucs[i]) return i;
    assert("Never get here");
    return -1;
}
Beispiel #2
0
int
tree_B(TreeHist* treeh, int blInd)
{
    InputTree* tree = treeh->tree;
    int i;
    int pos = treeh->pos;
    int hpos = treeh->hpos;
    //cerr << "tb1 " << pos << " " << hpos << " " << *tree << endl;
    int sz = tree->subTrees().size();
    int wpos;
    assert(pos <= sz);
    //cerr << "tb " << pos << " " << hpos << " " << sz << endl;
    if(pos < 0) wpos = tree->start()-1;
    else if(sz == 0) wpos = tree->start()-1;
    else if(pos == sz) wpos = tree->finish();
    else
    {
        InputTreesIter iti = tree->subTrees().begin();
        i = 0;
        for( ; iti != tree->subTrees().end() ; iti++)
        {
            if(i < pos) {
                i++;
                continue;
            }
            InputTree* st = *iti;
            if(pos < hpos) wpos = st->start()-1;
            else if(pos > hpos) wpos = st->finish();
            else if(blInd) wpos = st->start()-1;
            else wpos = st->finish();
            //cerr << "tbf " << *st << " " << wpos << endl;
            break;
        }
    }
    //cerr << "tb2 " << wpos << endl;
    assert(wpos <= endPos);
    if(wpos < 0 || wpos == endPos) return Term::stopTerm->toInt();
    else return Term::get(sentence[wpos]->term())->toInt();
}