当前位置: 首页>>代码示例>>C++>>正文


C++ SyntaxTree::removeDef方法代码示例

本文整理汇总了C++中SyntaxTree::removeDef方法的典型用法代码示例。如果您正苦于以下问题:C++ SyntaxTree::removeDef方法的具体用法?C++ SyntaxTree::removeDef怎么用?C++ SyntaxTree::removeDef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxTree的用法示例。


在下文中一共展示了SyntaxTree::removeDef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: recDescent

/**
 * @brief Parser::recDescent recursively parses the sentence
 * using the recursive descent top-down parsing method
 * @param S the tree
 * @param c the cutoff (How many words into the sentence does it start)
 * @return True if it is successful, False otherwise
 */
bool Parser::recDescent(SyntaxTree& S, std::size_t& c){
//    cin.get();
//    cout << "S so far: " << S << endl << endl;
//    cout << "c = " << c << endl;
//    cout << "Scur: " << *S.getCurrent() << endl;
//    cout << "The phrase is " << phraseLookUp[S.getPhrase()] << endl;
    GPlist def = getNextDef(S.getPhrase(),S.getDef());
    if(def.empty() && S.getDef().empty()){
        Word W;
        if(S.atLastLeaf()){
//            cout << "S is at the last leaf" << endl;
             W = getNextWord(c + 1);
//             cout << "The word at c+1: " << W << endl;
            if(*W.getTypes().begin() != IGNORETHIS){
//                --c;
                return false;
            }
            W = getNextWord(c);
        }
        else W = getNextWord(c);
//        cout << "Got the next word: " << W << endl;
        for(WordType cT = getNextType(W,IGNORETHIS); cT != IGNORETHIS; cT = getNextType(W,cT)){
            GrammarPhrase g = WTtoGP[cT];
//            cout << "The WT converted to gp: " << phraseLookUp[g] << endl;
//            cout << "Match this: " << phraseLookUp[S.getPhrase()] << endl;
            if(S.getPhrase() == g){
//                cout << "THERE IS A MATCH" << endl;
                ++c;
                return true;
            }
        }
        return false;
    }
    if(!S.getDef().empty()) S.removeDef();

    while(!def.empty()){
        if(S.getDef().empty()) S.addDef(def);
//        cout << "S with added def: " << S << endl;
        bool check = false;
        for(std::size_t i = 0; i < S.childNum(); ++i){
//            cout << "i: " << i << endl;
            S.shiftDown(i);
//            cout << "The CHild: " << *S.getCurrent() << endl;
            check = recDescent(S,c);
            if(!check && i != 0){
                S.shiftUp();
//                cout << "Not first child" << endl;
//                cout << "Now C: " << c << endl;
//                cout << "i here: " << i << endl;
                if(S.getChildAt(i-1) && !S.getChildAt(i-1)->isLeaf()){
                    c -= rt::leaves(S.getChildAt(i-1));
                    i -= 2;
                }
                else{
                    while(i > 0 && S.getChildAt(i-1) && S.getChildAt(i-1)->isLeaf()){
                        --c;
                        --i;
                    }
                    if(i == 0){
                        S.removeDef();
                        break;
                    }
                }
//                cout << "C: " << c << endl;
//                cout << "I: " << i << endl;
                S.shiftDown(i); //Previously 0
            }
            else if(!check && i == 0){
//                cout << "First child" << endl;
                S.shiftUp();
                S.removeDef();
                break;
            }
            if(!S.getParent(S.getCurrent())){
//                cout <<"For some reason it is already all the way at root" << endl;
                if(check && S.leafNum() == _words.size()) return true;
            }
            S.shiftUp();
        }
        if(check){
//            cout << "recur returned true for all children" << endl;
            return true;
        }
        def = getNextDef(S.getPhrase(),def);
    }
//    cout << "No more defs for this phrase and no successful recur, returning false" << endl;
    return false;
}
开发者ID:NLP,项目名称:Grammatica,代码行数:95,代码来源:parser.cpp


注:本文中的SyntaxTree::removeDef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。