The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



TExtractor


The class TExtractor implements an information extraction engine which can be used to extract numeric or string data from complex strings. The principle of TExtractor is quite simple: the input string (property SourceString) is processed by a set of commands which are passed to the extraction engine via the property ExtractionCommands. The results of the extraction are returned by triggering an OnEmit event. This event passes the name and the contents of a variable which has been calculated from the input string.

In addition the results can also be stored in the public variable Emission, if the property EmitToAssocArray is set to TRUE.

The extraction commands always operate on the source string using the current position of the execution pointer. The execution pointer can be moved along the source string using several of the commands (such as "pos", "inc", or "find"). TExtractor allows you to define up to a maximum of ME_STACKSIZE (currently 100) variables which can be filled with information obtained from the source string. The variables are Variants (see Delphi manual) and need not be declared - they are created automatically whenever a command references one for the first time. These variables can then be used for calculations using the built-in equation interpreter (which is based on TMathExpression; see the property Expression for details on the available functions).

Hint: The class TExtractor is not available under Delphi 5.

Example: Following is a short example script which extracts the geographical latitude from a string produced by a GPS recorder of an airplane:

The recorder delivers the following comma delimited data (time, latitude, north/south, longitude, east/west, date); the latitude is given by a substring whose first two digits represent the degrees, the rest being arc-minutes:

140054,4934.708,N,00949.363,E,070403

In order to extract the latitude as decimal degrees one could use the following commands for TExtractor:

## find the first comma in the string;
find (1, ',');
inc(1);
## copy the first two digits to the variable "Deg";
copy (2, Deg);
## copy the next 6 characters to the variable "Min";
copy (6, Min);
## find the north/south indicator and copy it to "LatSign";
find (1, ',');
inc (1);
copy (1,LatSign);
makelc (LatSign);
## compare LatSign against 's';
strcomp(issouth=LatSign, 's');
## calculate and emit the Latitude;
emit (Latitude=(Deg+Min/60)*2*(issouth+0.5));
Please note a simple but efficient trick in the last line: as the variables are of the type Variant the boolean variable "issouth" can be treated as a numeric variable, as well (true = -1, false = 0). Thus we can create a negative sign for southern latitudes simply by multiplying the variable "issouth" with a suitable factor.



Last Update: 2023-Feb-06