public static void pruneParse ( final Parse parse ) { final List < Parse > nodes = new LinkedList < Parse > ( ) ; nodes . add ( parse ) ; while ( nodes . size ( ) != 0 ) { final Parse node = nodes . remove ( 0 ) ; final Parse [ ] children = node . getChildren ( ) ; if ( children . length == 1 && node . getType ( ) . equals ( children [ 0 ] . getType ( ) ) ) { final int index = node . getParent ( ) . parts . indexOf ( node ) ; children [ 0 ] . setParent ( node . getParent ( ) ) ; node . getParent ( ) . parts . set ( index , children [ 0 ] ) ; node . parent = null ; node . parts = null ; } nodes . addAll ( Arrays . asList ( children ) ) ; } }
Prune the specified sentence parse of vacuous productions .