home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / DUTCH_FN.ZIP / RESEMBLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-27  |  2.9 KB  |  102 lines

  1. /******************************
  2. * Compiled : with Microsoft C 5.1
  3. * Object   : can only be used in conjunction with Clipper summer '87
  4. * Syntax   : RESEMBLE( <expC1>, <expC2> )
  5. * Parameter: <expC1> is the string you want to test, <expC> is the string
  6.              (maybe in the database)
  7. * Return   : A digit between 0 and 1, to reflect the resemblance
  8.              between two strings.
  9.              Every character is given a point.
  10.              Most-used characters are given less points, and less-used
  11.              characters are given more points.
  12.              First <expC2> is tested to check how much points you are
  13.              able to gain.
  14.              Then, all the characters of <expC2> that reappear in <expC1>
  15.              are given points.
  16.              The quotient of those two numbers is returned as a
  17.              resemblance-index.
  18.              
  19. * Author   : Jean-Pierre van Melis, Helmond, The Netherlands
  20. * Date     : June 1, 1988
  21. * Note     : I use this function in combination with the Soundex function
  22.              to get rid off the strings that have a correct Soundex
  23.              code, but do not resemble the original string.
  24.              (if a string has the correct soundex, resemble() must
  25.              be greater than 0.5)
  26. */
  27.  
  28. #include "jplib.h"
  29.  
  30. static byte code[] =  {3,5,4,4,1,5,5,4,3,6,6,4,5,3,3,5,6,3,4,1,5,6,5,6,5,6};
  31.  
  32. /*                     A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  33. */
  34. static byte scrap1[26];
  35. static byte scrap2[26];
  36.  
  37. CLIPPER resemble()
  38.  
  39. {
  40.    quant points_possible = 0;
  41.    quant points_gained   = 0;
  42.  
  43.    quant length;
  44.    quant i;
  45.  
  46.    byte  *is_now;
  47.    byte  *should_be;
  48.  
  49.    if (PCOUNT==2 && ISCHAR(1) && ISCHAR(2))
  50.    {
  51.       is_now    = _parc(1);
  52.       should_be = _parc(2);
  53.       length    = min(_parclen(1),_parclen(2));
  54.  
  55.       if (length > 2)
  56.       {
  57.          for (i=0;i<26;i++)
  58.          {
  59.             scrap1[i] = 0;
  60.             scrap2[i] = 0;
  61.          }
  62.       
  63.          for (i=0;i<length;i++)
  64.          {
  65.             if (is_now[i] >= 'A' && is_now[i] <= 'Z')
  66.                scrap1[is_now[i] - 'A'] = 1;
  67.             else
  68.                if (is_now[i] >= 'a' && is_now[i] <= 'z')
  69.                   scrap1[is_now[i] - 'a'] = 1;
  70.  
  71.  
  72.             if (should_be[i] >= 'A' && should_be[i] <= 'Z')
  73.                scrap2[should_be[i] - 'A'] = 1;
  74.             else
  75.                if (should_be[i] >= 'a' && should_be[i] <= 'z')
  76.                   scrap2[should_be[i] - 'a'] = 1;
  77.          }        
  78.  
  79.          for (i=0;i<26;i++)
  80.          {
  81.             if (scrap2[i])
  82.             {
  83.                points_gained   += ((quant) scrap1[i] * code[i]);
  84.                points_possible += ((quant) code[i]);
  85.             }
  86.          }
  87.  
  88.          if (points_possible)
  89.             _retnd((double) points_gained/(double) points_possible);
  90.          else
  91.             _retnd(0);
  92.       }
  93.       else
  94.          _retnd(0);
  95.  
  96.    }
  97.    else
  98.       _ret();
  99.    return;
  100.  
  101. }
  102.