E - Augment

Prev Next

Overview

Data augmentation (enrichment) typically involves adding further valuble information. Consider a lookup table with some economic and demographic data which you want to add to your analysis in order to provide a better statistical weighting. Or for stock market data, obtain a list of present credit ratings and key financial data of the corporation you are tracking. The functions below are the most common ones to choose:

  • table lookup() is a suitable alternative combining data from two tables into one.
  • table integrate() works similar liketable lookup(), but applies rules to combine existing data with data looked up, e.g. adding them up.
  • table process() lets you process every rows with algorithms of choice.



Wikipedia Example (continued from step 4)

Do some enrichment this table:

  • In this simple country and language example, no further enrichment is needed.

Simple Example

  // Some language specifications can be very long

  echo(new line, "Example of long contents: ", [countries:Country name,Switzerland,Languages] );
  echo(new line, "Let's cut to max. 25 characters, then remove last incomplete word and add '...' behind", new line);

  table process                  ( countries, while (find([Languages],'(')>=0)
                                                  [Languages] = trim( outside exclude ( [Languages], '(', ')' ))  );
  max[] = 25;
  table process selected rows    ( countries, [Languages]{}>max[],
                                              [Languages] = left last match( left( [Languages], max[] ), ' ') + " ..." );

  echo(new line, "Delete all countries without languages and vice versa...");
  table delete selected rows     ( countries, ['Alpha-2 code']=='' | [Languages]=='' );

  table list( countries, briefly, 8 ); // List first and last 8 rows only
Enrichtment done.
Row #: Code Text _______________________________________________________
    1:   include ( Support Library );
    2:   table load                     ( countries, temp.csv); // Hide!
    3:
    4:   // Some language specifications can be very long
    5:
    6:   echo(new line, "Example of long contents: ", [countries:Country name,Switzerland,Languages] );
                                                                             ^
Inside the started program code:
Attempting to access table with column name [Country name].
Specified table column name or number is invalid.
Code execution will stop.  Going to interactive mode
-------------------------------------------------------------------------------
Type 'help' for help, 'docs' or 'toc' for online B4P documentation.
>>
Try it yourself: Open GUI_Features_Enrichment.b4p in B4P_Examples.zip. Decompress before use.