private Vector getDistinctSortedY ( Vector distinctY , Vector piecesEachY , ArrayList < TextPiece > wordsOfAPage , TableCandidate tc ) { int pieceNumThisPage = wordsOfAPage . size ( ) ; float x_columnToGetYs = m_docInfo . getMinX ( ) ; float endX_columnToGetYs = m_docInfo . getMiddleX ( ) ; if ( ( tc . isWideTable ( ) == false ) && ( tc . getCaptionX ( ) >= m_docInfo . getMiddleX ( ) ) ) { x_columnToGetYs = m_docInfo . getMiddleX ( ) ; endX_columnToGetYs = m_docInfo . getMaxX ( ) ; } float [ ] sortY = new float [ pieceNumThisPage ] ; for ( int bb = 0 ; bb < pieceNumThisPage ; bb ++ ) { if ( ( wordsOfAPage . get ( bb ) . getX ( ) >= x_columnToGetYs ) && ( wordsOfAPage . get ( bb ) . getEndX ( ) <= endX_columnToGetYs ) ) { sortY [ bb ] = wordsOfAPage . get ( bb ) . getY ( ) ; } } Arrays . sort ( sortY ) ; int bb = 0 ; float lastY = 0.0f ; while ( bb < pieceNumThisPage ) { if ( distinctY . size ( ) > 0 ) lastY = ( ( Float ) distinctY . lastElement ( ) ) . floatValue ( ) ; if ( ( sortY [ bb ] - lastY ) >= m_docInfo . getAverageLineGap ( ) / 2.0 ) distinctY . addElement ( new Float ( sortY [ bb ] ) ) ; bb ++ ; } return distinctY ; }
We do not sort the text pieces according to Y values in the WHOLE page because if a document contains more than one column and the table is within one document column this action will bring the text pieces in other document columns as noise texts . By default we sort Y coordinate values based on the text pieces in the left part of the page If we find a table is not a wide table and located in the right part we only process the right half of the page