//**************************************

//     

//INCLUDE files for :Another soundex var

//     iant

//**************************************

//     

/* +++Date last modified: 05-Jul-1997 */

/*

** PHONETIC.H - Snippets header file for functions to perform

** phonetic string matching.

*/

#ifndef PHONETIC__H

#define PHONETIC__H

#include "sniptype.h"

/*

** File SOUNDEX.C

*/

char *soundex(char *instr, char *outstr);

/*

** File SOUNDEX4.C

*/

void soundex4(const char *instr, char *outstr, int N);

/*

** File SOUNDEX5.C

*/

#define SNDMAX (1 + 6 + 6*6 + 6*6*6)

#define SNDLEN (26 * SNDMAX)

int soundex5(char *instr);

/*

** File METAPHON.C

*/

/*

** MAXMETAPH is the length of the Metaphone code.

**

** Four is a good compromise value for English names. For comparing words

** which are not names or for some non-English names, use a longer code

** length for more precise matches.

**

** The default here is 5.

*/

#define MAXMETAPH 5

typedef enum {COMPARE, GENERATE} metaphlag;

Boolean_T metaphone(const char *Word, char *Metaph, metaphlag Flag);

/*

** File APPROX.C

*/

void App_init(char *pattern, char *text, int degree);

void App_next(char **start, char **end, int *howclose);

 

code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

//**************************************

//     

// Name: Another soundex variant

// Description:Modified by M. Stapleton 

//     of Graphic Bits. Uses compressed heptal 

//     - eliminates codes for non-trailing zero

//     s.

// By: Bob Stout (republished under Open

//     Content License)

//

//This code is copyrighted and has// limited warranties.Please see http://

//     www.1CPlusPlusStreet.com/xq/ASP/txtCodeI

//     d.714/lngWId.3/qx/vb/scripts/ShowCode.ht

//     m//for details.//**************************************

//     

/* +++Date last modified: 05-Jul-1997 */

/*

** S O U N D E X 5

**

** Originally from SNIPPETS, written by Bob Jarvis.

** Modified by M. Stapleton of Graphic Bits on Dec 8 1994

** Uses compressed heptal - eliminates codes for non-trailing zeros.

*/

#include 

#include 

#include "phonetic.h"

int soundex5(char *instr)

    {

    int count = 0, init, snd = 0, notlast = 1;

    int ch;

    static int table[] =

        {

        /* A B C D E F G H I J */

        0, 1, 2, 3, 0,1, 2, 0, 0, 2,

        /* K L M N O P Q R S T */

        2, 4, 5, 5, 0,1, 2, 6, 2, 3,

        /* U V W X Y Z */

        0, 1, 0, 2, 0, 2,

    };

    /* Skip leading non-alpha */

    while(*instr && (!isalpha(*instr)))

    instr++;

    if(!*instr) /* Hey! Where'd the string go? */

    return -1;

    /* Convert initial letter to int. */

    init = (char)toupper(instr[0]) - 'A';

    for(instr++; *instr && (count < 3); instr++)

        {

        if(isalpha(*instr) && (*instr != *(instr-1)))

            {

            if(NUL != (ch = table[toupper(*instr) - 'A']))

                {

                /* Convert to "compressed heptal" */

                snd = (7 - notlast) * snd + ch - notlast;

                notlast = ++count < 2;

            }

        }

    }

    /* Adjust */

    switch(count)

        {

        case 0: /* default:Shouldn't get here! */

        snd = 0;

        break;

        case 1:

        snd += 1;

        break;

        case 2:

        snd *= 7;

        /* Fall through */

        case 3:

        snd += 7;

        break;

    }

    return SNDMAX * init + snd;

}

#ifdef TEST

#include 

#include 

main(int argc, char *argv[])

    {

    if (argc != 2)

        {

        puts("Usage: SOUNDEX5 string");

        return EXIT_FAILURE;

    }

    printf("soundex5(\"%s\") returned %d\n", argv[1], soundex5(argv[1]));

    return EXIT_SUCCESS;

}

#endif /* TEST */