Library Functions -- $%PRODUCE^STRING

Approved for inclusion in a future ANSI M[UMPS] language standard as part of the library for String Handling.

This function returns a translated version of the value of its parameter.

This function could be used to reduce multiple separators to single ones:

KILL SPEC
; Two blanks will be reduced to a single one
SET SPEC(1,1)=" ",SPEC(1,2)=" "
; translate all relevant separators into blanks
SET X=$TRANSLATE(X,"!?,.;:()"," ")
; and reduce multiple blanks to singletons
SET X=$%PRODUCE^STRING(X,.SPEC)

A soundex algorithm for English names:

1. Remove non-alpha and convert lower case to upper case
2. Examine first letters
PH --> F
CE --> S
KN --> N
WR --> R
C --> K
3. Ignore all other vowels (A, E, I, O and U)
4. Then replace
MP --> M
ST --> S
DG --> D
TCH --> CH
GHT --> HT
5. Then make the following equivalent
B, F, P and V
C, G, J, K, Q, S, X and Z
D and T
M and N
6. Finally, remove multiple consecutive occurences of the same character

SOUNDEX(A) NEW B,C,UP,LOW,I,S1,S2
 SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 SET LOW="abcdefghijklmnopqrstuvwxyz"
 SET A=$TRANSLATE(A,LOW_"-., ()'",UP)
 FOR I=1:1:5 SET C(I,1)=$PIECE("PH C CE KN WR"," ",I)
 FOR I=1:1:5 SET C(I,2)=$PIECE("F. K S. N. R."," ",I)
 SET I=$%REPLACE^STRING($EXTRACT(A,1,2),.C)
 SET $EXTRACT(A,1,2)=I
 SET A=$TRANSLATE(A,"AEIOUY.")
 FOR I=1:1:5 DO
 . SET C(I,1)=$PIECE("MP ST DG TCH GHT"," ",I)
 FOR I=1:1:5 DO
 . SET C(I,2)=$PIECE("M. S. D. CH. HT." ",I)
 SET A=$%REPLACE^STRING(A,.C)
 SET S1="BFPVCGJKQSXZDTMN."
 SET S2="BBBBCCCCCCCCDDMM"
 SET A=$TRANSLATE(A,S1,S2)
 FOR I=1:1:26 DO
 . SET C(I,1)=$CHAR(64+I,64+I)
 . SET C(I,2)=$CHAR(64+I)
 SET A=$%PRODUCE^STRING(A,.C)
 QUIT A

The MDC has approved code to approximate the return value of this function. Implementors are encouraged to provide more accurate and efficient code). Click here to view or download the code for this function. Click here to view or download the code for all M[UMPS] Library Functions.


This document is © Ed de Moel, 1995-2005.
It is part of a book by Ed de Moel that is published under the title "M[UMPS] by Example" (ISBN 0-918118-42-5).
Printed copies of the book are no longer available.

This document describes the various library functions that are defined for the M[UMPS] programming language.

The information in this document is NOT authoritative and subject to be modified at any moment.
Please consult the appropriate (draft) language standard for an authoritative definition.

In this document, information is included that will appear in future standards.
The MDC cannot guarantee that these 'next' standards will indeed appear.