ivi merging, form letters, etc.

ivi's merge facilities allow the fields of a record, or words taken from a text, to be combined with a template to form a new text or text segment. They were originally intended for two purposes: the creation of form letters, and the extraction of features from a text in order to make some kind of index or concordance. In the second case, we may envisage using one of ivi's search facilities to locate specific text features (say, all words beginning with "trans") and then generating lines which contain each "trans" word plus the four words which follow. These lines can then be sorted to create a list of "trans" words with context.

Corresponding to these intentions there are two types of template: the long template, which allows the creation of multi-line files, and the short, which permits the construction of a single line of text. The long merge template can be merged only with a record; the short with either a record or text.

Command: MErge

Purpose: Specify the short merge template

Format: ME <string>

Parameters: <string> is a merge template: a short piece of text containing field selectors of the form #<number>.

The numbered field selectors (#1, #2, etc.) refer to fields of a record (in either of the record views) or words relative to the cursor (in text view). During merge operations, they are replaced by the appropriate record fields or words.


ME the #1 visited the #3.

Operation: Short merge

Default Key: <ESC>M

Operation Number: 48

The Short merge operation takes the short template, and replaces the field selectors with words from the text starting at the cursor, or fields taken from the current record. The result is a single line which is inserted following the cursor line in corefile 16.


(1) We have a text of Alice in Wonderland, and wish to find the three words following each occurrence of the word "Alice". We want these phrases sorted in order according to the first context word. We define the template:

    ME #1 %#2  #3  #4

Now we use a FInd command, or Find restart, to locate occurrences of "Alice". Every time we discover one, we use <ESC>M to cause a line consisting of the first, second, third and fourth words ("Alice" being the first) to be sent to corefile 16. The words are separated by spaces, and the second word is preceded by the symbol %. The result is a file in which each line represents one set of context.

Using the Align operation with character %, the second words can be aligned in, say, column 10 of corefile 16. (Unnecessary in this case, since the part of the line preceding the % symbol is fixed; but we would need this extra step if we wanted the ordering to depend on the third words.) Finally we sort the text based on a sort key which begins in column 10.

The repetitive loop of operations (find, merge, align) can easily be formed into an ivi function (see Functions, etc.) so that the user can trigger the task without having to carry out each step. Part or all of the task might be done silently (see Miscellanea), to avoid/reduce repeated rewriting of the screen.

(2) A user is preparing input for a program which requires it to be in a specific form, with one set of data per line. The user may type each set of data as a record (in effect, filling out a form which asks questions about the data). The merge operation may then be used to transform the records into the lines required by the program.

Command: TEmplate

Purpose: Specify the long merge template.

Format: TE 2|<filename>

Parameters: <filename> is the name of a file which contains a long merge template. The first parameter is actually a <digit> which can also take the value 0 or 1. In this case, the command specifies a record template (see Editing Records).

A sample long merge template might look like:

    Dear #1:

    Our records indicate that you are 
    currently overdrawn by #2 dollars.
    If this is not paid in six weeks, 
    your accounts, numbered #3 and #4
    will be automatically closed, 
    and your company sued.



This is very similar to a short merge template, except that it covers multiple lines and is read from a file. The numbered field selectors once again refer to the fields of a record. Presumably, a typical record for the sample template might be:

    Mr Jones|10,000|1234567|7654321|

Operations: Long merge

Default Key: <ESC>F

Operation Number: 67

The Long merge carries out the same operation as the Short merge, but using the long template. The result is a sequence of lines which are linked into corefile 16. As previously noted this operation is restricted to merging the template with a record.

The longer form of the merge facility is intended for the production of form letters. A form letter template, including field numbers which reference the "individual" data components, is typed and stored in a file. The "individual" data is a sequence of records which is brought to a corefile (say, 1). The user carries out TE 2 to set up the form letter template, places the corefile 1 cursor on any desired record, and types <ESC>F to create the corresponding form letter.

The replacement of the field selectors by their corresponding record fields may upset paragraph format. The user may therefore insert an unusual symbol (say, &) at the start of each paragraph in the template. He/she can then scan for this symbol, delete it, and trigger a Reformat operation, before finding the next &.

Presumably,after completeing each letter, the user saves it to a disk file and clears corefile 16 before proceeding with the next letter.

The Backquote Symbol

A merge template of the form:


is taken to mean field 12 with xyz concatenated, rather than field 1 with 2xyz concatenated. To obtain the latter, we use the backquote (`):


This symbol is not copied into the merged string, but as a non-digit, acts a terminator to the field number. No way is provided for putting backquotes into merged strings!