private static Tree findCCparent(Tree t, Tree root) {
    if (t.isPreTerminal()) {
      if (t.value().startsWith("CC")) {
        Tree parent = t.parent(root);
        if (parent.value().startsWith("NP")) {
          List<Tree> children = parent.getChildrenAsList();
          //System.out.println(children);
          int ccIndex = children.indexOf(t);
          if (children.size() > ccIndex + 2 && notNP(children, ccIndex) && ccIndex != 0 && (ccIndex == children.size() - 1 || !children.get(ccIndex+1).value().startsWith("CC"))) {
            transformCC(parent, ccIndex);
            if (VERBOSE) {
              System.err.println("After transformCC:             " + root);
            }
            return root;
          }
        }
      }
    } else {
      for (Tree child : t.getChildrenAsList()) {
        Tree cur = findCCparent(child, root);
        if (cur != null) {
          return cur;
        }
      }
    }
    return null;
  }
private static Tree findCCparent ( Tree t , Tree root ) { if ( t . isPreTerminal ( ) ) { if ( t . value ( ) . startsWith ( "CC" ) ) { Tree parent = t . parent ( root ) ; if ( parent . value ( ) . startsWith ( "NP" ) ) { List < Tree > children = parent . getChildrenAsList ( ) ; int ccIndex = children . indexOf ( t ) ; if ( children . size ( ) > ccIndex + 2 && notNP ( children , ccIndex ) && ccIndex != 0 && ( ccIndex == children . size ( ) - 1 || ! children . get ( ccIndex + 1 ) . value ( ) . startsWith ( "CC" ) ) ) { transformCC ( parent , ccIndex ) ; if ( VERBOSE ) { System . err . println ( "After transformCC:             " + root ) ; } return root ; } } } } else { for ( Tree child : t . getChildrenAsList ( ) ) { Tree cur = findCCparent ( child , root ) ; if ( cur != null ) { return cur ; } } } return null ; }
/*
Given a tree t, if this tree contains a CC inside a NP followed by 2 nodes
(i.e. we have a flat structure that will not work for the dependencies),
it will call transform CC on the NP containing the CC and the index of the
CC, and then return the root of the whole transformed tree.
If it finds no such tree, this method returns null.