table digest ...

Prev Next

Function Names

table digest, table digest ignore case

Description

These functions work very similarly like table integrate(). Instead of stopping at the first match in the lookup table, this function family looks up all entries in the lookup table and includes these rows looked up in the data integration proedure. The search procedure through the lookup table will always be top-down. If only one match has been identified, then the behavior is the same as in table integrate(). In case 2 or more matching enties are found in the lookup table, then the following happens:

  • The integration procedure will be applied on the same target table row and destination columns using the operation defined by the table integration operation identifiers. Example: Using the operation identifier add: All numeric values found in the lookup table will be added to the (already existing) value in the corresponding destination column.
  • In case of no matches, the row stays unchanged, i.e. the row in the target table will not be deleted.
  • For the operation identifier average, the collected values plus the already existing value in the target table will be added to gether and divided by the number of rows found in the lookup table. This means that it is advisalbe to keep the initial value in the destination column blank or zero in order to calculate the average values proper.y.



Additional features:

  • An expression to select rows (8th function parameter) can be specified to limit the lookup process to selected rows.
  • An additional column (9th function parameter) can be specified in the lookup table to count the number of matches.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

6 - 9 (For parameter description and return values: see table integrate() )

Examples

       table initialize( nute facts, // Nutritional facts, source: ndb.nal.usda.gov
       {  {  Food, Ingredient, Portion  },
          {  potato chips,  fat,            0.34  },
          {  potato chips,  carbohydrates,  0.50  },
          {  potato chips,  sodium,         0.08  },
          {  potato chips,  proteins,       0.07  },
          {  potato chips,  others,           ''  }, // Remaining weight subtracted from above (--> operation identifer 'mul')
          {  broccoli,      water,          0.88  },
          {  broccoli,      proteins,       0.03  },
          {  broccoli,      carbohydrates,  0.06  },
          {  broccoli,      others,           ''  }, // Remaining weight subtracted from above (--> operation identifer 'mul')
          {  spring water,  water,          1.00  } } );

       table initialize( target, { { Name, Favorite Food },
          { Rafael, Broccoli     }, { Steve, Parmesan cheese }, { Stephanie, Parmesan cheese  },
          { Jane,   Potato chips }, { Nick, Potato chips },     { Fred,  Spring water         } } );


       echo("Target table before looking up with expanding contents:");
       table list ( target );

       count[] = table digest ignore case( target, Favorite Food, { Ingredient, Portion }, nute facts, Food,
                                 { Ingredient, Portion }, { overwrite, add}, true, Counter );

       echo("Lookup table:");
       table list ( nute facts );

       // Note that food portions are multiplied with the weight of the food.

       echo("After expanding (listing ingredients and calculating their weights):");
       echo("The portions are added up and yield resuts of 1 or less.");
       echo("Note: Nothing found for parmesan cheese.");
       echo("Target table after lookup (", count[], " items found):");
       table list ( target );

Output

Target table before looking up with expanding contents:
    0 : Name      | Favorite Food  
    1 : Rafael    | Broccoli       
    2 : Steve     | Parmesan cheese
    3 : Stephanie | Parmesan cheese
    4 : Jane      | Potato chips   
    5 : Nick      | Potato chips   
    6 : Fred      | Spring water   

Lookup table:
    0 : Food         | Ingredient    | Portion | Counter
    1 : potato chips | fat           | 0.34    | 2      
    2 : potato chips | carbohydrates | 0.50    | 2      
    3 : potato chips | sodium        | 0.08    | 2      
    4 : potato chips | proteins      | 0.07    | 2      
    5 : potato chips | others        |         | 2      
    6 : broccoli     | water         | 0.88    | 1      
    7 : broccoli     | proteins      | 0.03    | 1      
    8 : broccoli     | carbohydrates | 0.06    | 1      
    9 : broccoli     | others        |         | 1      
   10 : spring water | water         | 1.00    | 1      

After expanding (listing ingredients and calculating their weights):
The portions are added up and yield resuts of 1 or less.
Note: Nothing found for parmesan cheese.
Target table after lookup (15 items found):
    0 : Name      | Favorite Food   | Ingredient | Portion
    1 : Rafael    | Broccoli        | others     | 0.97   
    2 : Steve     | Parmesan cheese |            |        
    3 : Stephanie | Parmesan cheese |            |        
    4 : Jane      | Potato chips    | others     | 0.99   
    5 : Nick      | Potato chips    | others     | 0.99   
    6 : Fred      | Spring water    | water      | 1      

Try it yourself: Open LIB_Function_table_digest.b4p in B4P_Examples.zip. Decompress before use.

See also

table digest smart
table digest with rules
table digest with rules once
table lookup
table integrate
table expand