protected IONode < String > detectFeatures ( ImportMatrix matrix , PCMContainer pcmContainer ) { IONode < String > root = new IONode <> ( null ) ; List < IONode < String > > parents = new ArrayList <> ( ) ; // Init parents for ( int column = 0 ; column < matrix . getNumberOfColumns ( ) ; column ++ ) { parents . add ( root ) ; } // Detect features for ( int row = 0 ; row < matrix . getNumberOfRows ( ) ; row ++ ) { List < IONode < String >> nextParents = new ArrayList <> ( parents ) ; for ( int column = 0 ; column < matrix . getNumberOfColumns ( ) ; column ++ ) { IOCell currentCell = matrix . getCell ( row , column ) ; if ( currentCell == null ) { currentCell = new IOCell ( "" ) ; } IONode < String > parent = parents . get ( column ) ; boolean sameAsParent = currentCell . getContent ( ) . equals ( parent . getContent ( ) ) ; boolean sameAsPrevious = false ; boolean sameParentAsPrevious = true ; if ( column > 0 ) { IOCell previousCell = matrix . getCell ( row , column - 1 ) ; if ( previousCell == null ) { previousCell = new IOCell ( "" ) ; } sameAsPrevious = currentCell . getContent ( ) . equals ( previousCell . getContent ( ) ) ; if ( parent . getContent ( ) != null ) { sameParentAsPrevious = parent . getContent ( ) . equals ( parents . get ( column - 1 ) . getContent ( ) ) ; } } if ( ! sameAsParent && ( ! sameParentAsPrevious || ! sameAsPrevious ) ) { IONode < String > newNode = new IONode <> ( currentCell . getContent ( ) ) ; newNode . getPositions ( ) . add ( column ) ; parent . getChildren ( ) . add ( newNode ) ; nextParents . set ( column , newNode ) ; } else if ( column > 0 && sameParentAsPrevious && sameAsPrevious ) { IONode < String > previousNode = nextParents . get ( column - 1 ) ; previousNode . getPositions ( ) . add ( column ) ; nextParents . set ( column , previousNode ) ; } } parents = nextParents ; // If number of getLeaves == number of rows : break; if ( root . getLeaves ( ) . size ( ) == matrix . getNumberOfColumns ( ) ) { break ; } } return root ; }
Detect features from the information contained in the matrix and the provided direction