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