public static boolean isProjective ( int [ ] parents ) { for ( int i = 0 ; i < parents . length ; i ++ ) { int pari = ( parents [ i ] == ParentsArray . WALL_POSITION ) ? parents . length : parents [ i ] ; int minI = i < pari ? i : pari ; int maxI = i > pari ? i : pari ; for ( int j = 0 ; j < parents . length ; j ++ ) { if ( j == i ) { continue ; } int parj = ( parents [ j ] == ParentsArray . WALL_POSITION ) ? parents . length : parents [ j ] ; if ( minI < j && j < maxI ) { if ( ! ( minI <= parj && parj <= maxI ) ) { return false ; } } else { if ( ! ( parj <= minI || parj >= maxI ) ) { return false ; } } } } return true ; }
Checks that a dependency tree represented as a parents array is projective .