Exemplo n.º 1
0
InputTree*
tree_2rel_tree(TreeHist* treeh)
{
    //cerr << "t1r " << *treeh->tree << endl;
    int pos = treeh->pos;
    int hpos = treeh->hpos;
    if(pos == hpos || pos < hpos-1 || pos > hpos+1) return NULL;
    //cerr << "t2r " << *treeh->tree << endl;
    InputTree* sib;
    if(pos < hpos)
    {
        sib = tree_find(treeh, +1);
        int sibhp = headPosFromTree(sib);
        InputTree* sibch;
        if(sibhp > 0)
        {
            sibch = sib->subTrees().front();
        }
        else if(sib->subTrees().size() < 2) return NULL;
        else
        {
            InputTreesIter iti = sib->subTrees().begin();
            iti++;
            sibch = *iti;
        }
        return sibch;
    }
    else
    {
        sib = tree_find(treeh, -1);
        int sibhp = headPosFromTree(sib);
        InputTree* sibch;
        if(sibhp < sib->subTrees().size()-1)
        {
            sibch = sib->subTrees().back();
        }
        else if(sib->subTrees().size() < 2) return NULL;
        else
        {
            InputTrees::reverse_iterator iti = sib->subTrees().rbegin();
            iti++;
            sibch = *iti;
        }
        return sibch;
    }
}
Exemplo n.º 2
0
void
gatherFfCounts(InputTree* tree, int inHpos)
{
  InputTrees& st = tree->subTrees();;
  InputTrees::iterator  subTreeIter= st.begin();
  InputTree  *subTree;
  int hpos = 0;
  if(st.size() != 0) hpos = headPosFromTree(tree);
  //cerr << hpos << *tree << endl;
  int pos = 0;
  for( ; subTreeIter != st.end() ; subTreeIter++ )
    {
      subTree = *subTreeIter;
      gatherFfCounts(subTree, pos==hpos ? 1 : 0);
      pos++;
    }
  //cerr << "g " << *tree << endl;
  curTree = tree;
  TreeHist treeh(tree, 0);
  treeh.pos = pos;
  treeh.hpos = hpos;
  const Term* lhsTerm = Term::get(tree->term());
  if(lhsTerm->terminal_p())
    {
      if(Feature::whichInt == TTCALC) callProcG(&treeh);
      return;
    }
  //if(procGSwitch) cerr << "gff " << *tree << endl;
  if(Feature::whichInt == HCALC || Feature::whichInt == UCALC)
    {
      if(!inHpos) callProcG(&treeh);
      return;
    }
  if(st.size() == 1 && st.front()->term() == tree->term()) return;
  subTreeIter = st.begin();
  int cVal;
  treeh.pos = -1;
  if(Feature::whichInt == LMCALC) callProcG(&treeh);
  if(Feature::whichInt == LCALC) callProcG(&treeh);
  pos = 0;
  for( ; subTreeIter != st.end() ; subTreeIter++)
    {
      treeh.pos = pos;
      if(pos == hpos && Feature::whichInt == MCALC) callProcG(&treeh);
      if(pos < hpos && Feature::whichInt == LCALC) callProcG(&treeh);
      if(pos > hpos && Feature::whichInt == RCALC) callProcG(&treeh);
      if(pos == hpos && Feature::whichInt == RUCALC) callProcG(&treeh);
      if(pos >= hpos && Feature::whichInt == RMCALC) callProcG(&treeh);
      if(pos <= hpos && Feature::whichInt == LMCALC) callProcG(&treeh);
      pos++;
    }
  //cerr << "gg " << *tree << endl;
  treeh.pos = pos;
  if(Feature::whichInt == RCALC) callProcG(&treeh);
  if(Feature::whichInt == RMCALC) callProcG(&treeh);
}
Exemplo n.º 3
0
void
gatherFfCounts(InputTree* tree, int inHpos)
{
  int wI =Feature::whichInt;
  InputTrees& st = tree->subTrees();;
  InputTrees::iterator  subTreeIter= st.begin();
  InputTree  *subTree;
  int hpos = 0;
  if(st.size() != 0) hpos = headPosFromTree(tree);
  int pos = 0;
  for( ; subTreeIter != st.end() ; subTreeIter++ )
    {
      subTree = *subTreeIter;
      gatherFfCounts(subTree, pos==hpos ? 1 : 0);
      pos++;
    }
  //cerr << "g " << inHpos << " " << *tree << endl;
  //cerr << "t " << wI << endl;
  TreeHist treeh(tree, 0);
  treeh.pos = pos;
  treeh.hpos = hpos;
  const Term* lhsTerm = Term::get(tree->term());
  if(wI == HCALC || wI == UCALC)
    {
      if(!inHpos)
	{
	  callProcG(&treeh);
	}
      return;
    }
  if(lhsTerm->terminal_p())
    {
      if(wI == TTCALC || wI == WWCALC) callProcG(&treeh);
      return;
    }
  if(st.size() == 1 && st.front()->term() == tree->term()) return;
  //cerr << "gff " << *tree << endl;
  //if(tree->term() == "PP" && !st.empty() && st.front()->term() == "VBG")
    //  cerr << *tree << "\n" << *curS << "\n----\n"; //???;
  subTreeIter = st.begin();
  int cVal;
  treeh.pos = -1;
  if(wI == LMCALC) callProcG(&treeh);
  if(wI == LCALC) callProcG(&treeh);
  pos = 0;
  for( ; subTreeIter != st.end() ; subTreeIter++)
    {
      treeh.pos = pos;
      if(pos == hpos && wI == MCALC) callProcG(&treeh);
      if(pos < hpos && wI == LCALC) callProcG(&treeh);
      if(pos > hpos && wI == RCALC) callProcG(&treeh);
      if(pos == hpos && wI == RUCALC) callProcG(&treeh);
      if(pos >= hpos && wI == RMCALC) callProcG(&treeh);
      if(pos <= hpos && wI == LMCALC) callProcG(&treeh);
      pos++;
    }
  treeh.pos = pos;
  if(wI == RCALC) callProcG(&treeh);
  if(wI == RMCALC) callProcG(&treeh);
  //cerr << "gg " << *tree << endl;
}