table explore

Prev Next

Function Names

table explore

Description

This function explores the table for sub-tables. It will scan through the entire table in a reading-style manner (1st row left-to-right, then 2nd row, etc.) to identify all sub-tables with contents.

Following criteria must be met for the beginning of the sub-table: X adjacent columns in one row must be non-blank. If number of starting rows is bigger than 1, then in X adjacent columns at least one of the rows must contain contents. This allows table recognition in case the header consists of multiple rows and has blank items. The end of the table is recognized by number of adjacent blank rows below the identified table.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

2-4

Parameters

No.TypeDescription
1.
input
string Name of existing table

It is assumed that this table contains one or more sub-tables.

Opt. 2
input
numeral Starting rows

This parameter specifies the number of top rows where at least one of the rows in each column must be non-blank to recognize begin of the table.
Attention: Choosing 1 will also capture single rows of data. If you know that all tables contain at least one row of data, then use 2 in order to filter away free text fields such as titles.

Default value: 1
Opt. 3
input
numeral Ending rows

This parameter specifies the number of adjacent blank rows below the last non-blank table row to identify end of table. A value of 2 or bigger tolerates blank rows inside the identified table

Default value: 1

Return value

TypeDescription
matrix of numerals Coordinates of identified sub-tables

The matrix of numerals is a set which contains 0, 1 or more sets where each of them refers to a found sub-table and contain 4 numerals:

{ { x start, y start, x end, y end }, { x start, y start, x end, y end }, ... }

x start: Column number in main where the sub-table is beginning
y start: Row number in main where the sub-table is beginning
x end: Column number in main where the sub-table is ending
y end: Row number in main where the sub-table is ending

Examples

       table load( test, "Examples\Table Explore Demo.csv" );
       table list ( test );
       coords[] = table explore ( test );

       echo("Identified ", coords[]{}," sub-tables:");
       for all ( coords[], c[], i[] )
       {
               print("    Table ", i[], ":  (", c[]{0}, ", ", c[]{1},") ... ( ", c[]{2}, ", ", c[]{3},") " );
               echo ("    ('", [test:c[]{0},c[]{1}],"', ...)" );
       }

Output

    0 : Last Name | First Name | Town      |  |           | Family Name | First Name | Town      |  | Country
    1 : Andersson | Andy       | Boston    |  |           | Andersson   | Andy       | Boston    |  | USA    
    2 : Bethel    | Betty      | Cambridge |  |           | Bethel      | Betty      | Cambridge |  | U.S.   
    3 : Charlsson | Charles    | Baltimore |  |           |             |            |           |  |        
    4 : Dickson   | Dieter     | W. DC     |  |           |             |            |           |  |        
    5 :           |            |           |  |           | Given Name  | Profession |           |  |        
    6 : Emmerich  | Elana      | Brussels  |  |           | Girolamo    | Acteur     |           |  |        
    7 :           |            |           |  | Cities    | Dominique   | Dompteur   |           |  |        
    8 :           |            |           |  | Prague    | Dimitri     | Clown      |           |  |        
    9 :           |            |           |  | Warsaw    |             |            |           |  |        
   10 :           |            |           |  | Bucharest |             |            |           |  |        
   11 :           |            |           |  | Budapest  |             |            |           |  |        
   12 :           |            |           |  | Istanbul  |             |            |           |  |        
   13 :           |            |           |  | Cairo     |             |            |           |  |        

Identified 6 sub-tables:
    Table 0:  (0, 0) ... ( 2, 4)     ('Last Name', ...)
    Table 1:  (5, 0) ... ( 7, 2)     ('Family Name', ...)
    Table 2:  (9, 0) ... ( 9, 2)     ('Country', ...)
    Table 3:  (5, 5) ... ( 6, 8)     ('Given Name', ...)
    Table 4:  (0, 6) ... ( 2, 6)     ('Emmerich', ...)
    Table 5:  (4, 7) ... ( 4, 13)     ('Cities', ...)
Try it yourself: Open LIB_Function_table_explore.b4p in B4P_Examples.zip. Decompress before use.

See also

table filter
table extract