Link to home
Start Free TrialLog in
Avatar of korsila
korsila

asked on

comparing name matching names algorithm

This algorithm considered 2 surnames in each were compared on a character-for-character basis. the following figure1 summarises the nine rules or tests used for matching the letters of two surnames; note that they all depended on the position of the letters in the names, their sequence or order, rather than on what the letters themselves were.

figure1 tests for position of letters in matching alternate surname spellings

                position in Name 1                    position ion Name 2

test1                   x                                       x
test2                   x                                       x+1
test3                  x                                        x+2
test4                  x                                        x-1
test5                  x-1                                    x
test6                  x+1                                   x
test7                  x+2                                   x
test8                  x+1                                   x+1
test9                  x+2                                  x+2

more explaination....

the first step in the algorithm(not shown in figure 1) was a check for identical names, looking at ech of the surnames as a single character string. Failing that, tyhe algorithm entered the loop shown in figure 1 and compared the two surnames letter by letter, considering each turn. As long as the two nbames were identical, the algorithm succeeded with Test1 and did not drop down through the rest of the loop. When a mismatch occurred in the letter-for letter comparison, the remaining eight tests were tried in the order shown in figure 1. A success with any of the test caused the algorithm to return to the beginning of the loop, increment the counter by 1, check for the end of the name, and proceed to go through the loop again comparing the next letters in the two names.

and that's it...
any good codes offer will be considered as the high marks.

cheers
Korsila
Avatar of imladris
imladris
Flag of Canada image

How about something like:

int compname(char *nm1,char *nm2)
{   int i,l1,l2;

    l1=strlen(nm1);
    l2=strlen(nm2);
    for(i=0; i<len; ++i)
    {   if(i<l2 && nm1[i]==nm2[i])continue;
        if(i+1<l2 && nm1[i]==nm2[i+1])continue;
        if(i+2<l2 && nm1[i]==nm2[i+2])continue;
        if(i-1<l2 && i>0 && nm1[i]==nm2[i-1])continue;
        if(i<l2 && i>0 && nm1[i-1]==nm2[i])continue;
        if(i+1<l1 && i<l2 && nm1[i+1]==nm2[i])continue;
        if(i+2<l1 && i<l2 && nm1[i+2]==nm2[i])continue;
        if(i+1<l1 && i+1<l2 && nm1[i+1]==nm2[i+1])continue;
        if(i+2<l1 && i+2<l2 && nm1[i+2]==nm2[i+2])continue;
        return(0);
    }
    return(1);
}
Avatar of korsila
korsila

ASKER

these following lines came up with som,e error messages...

for(i=0;i<len; ++i)
what is "len"????
** error "undefined"


and the problem is what is "continue"..??

**error ..unexpected symbol "continue"



many thanks anyway...i will see if i got it closed of what i expect...you will be considered as a high marks...

in the mean time, please try to sort out the errors...
Avatar of korsila

ASKER

if anyone can implement in the "Icon" programming..
I will be pleased to give the point up to 500 points.

anyway good codes will be considered as a high marks

many thanks
korsila
Quite right. len should have been l1:

int compname(char *nm1,char *nm2)
{   int i,l1,l2;

    l1=strlen(nm1);
    l2=strlen(nm2);
    for(i=0; i<l1; ++i)
    {   if(i<l2 && nm1[i]==nm2[i])continue;
        if(i+1<l2 && nm1[i]==nm2[i+1])continue;
        if(i+2<l2 && nm1[i]==nm2[i+2])continue;
        if(i-1<l2 && i>0 && nm1[i]==nm2[i-1])continue;
        if(i<l2 && i>0 && nm1[i-1]==nm2[i])continue;
        if(i+1<l1 && i<l2 && nm1[i+1]==nm2[i])continue;
        if(i+2<l1 && i<l2 && nm1[i+2]==nm2[i])continue;
        if(i+1<l1 && i+1<l2 && nm1[i+1]==nm2[i+1])continue;
        if(i+2<l1 && i+2<l2 && nm1[i+2]==nm2[i+2])continue;
        return(0);
    }
    return(1);
}


I ran this through my C Compiler without any trouble. The continue keyword indicates that execution should skip to the next loop iteration.


Is there a problem with the revised code? Is there some other clarification you need?
Avatar of korsila

ASKER

what i should include at the begining of the file..??

like ...include <string.h>
or something like that....

i will try to coimpile again and then will get back with the error messages to you...


many thanks ayway

korsila
Assumed to have been helpful.
Avatar of korsila

ASKER

your codes are ok now for compiling...!!

you impressed me quiet a lot...and i think i will give you full mark with my comment on the next problems...

but  right now, i need some more codes to sort it out..and will let you know as soon as i can get into the program...

many thanks again...

p.s. sorry for the delay of my reply and response...but am sure whenever i  get back to my program and try to run it,  i wil definitely accept your proposed answer with full mark...:)
Avatar of korsila

ASKER

Dear Imladris

sorry !! haven't been worked for a while since i last requested...however, am just getting back to work on this program again..and need your help to write the main program to call this procedure (int compname(char *nm1,char *nm2) to be used...the main program call this procedure after 2 names are entered from the screen...as below..
-----------------------------------
main program...
please enter name 1:
please enter name 2:

call the comparename function here...
to compare whether these 2 names are matched or are not matched...
----------------------------------
p.s. the result should be return " 2 names are matched"  or "2 names are not matched " after calling the procedure "int compname"

--------------------------------------
i promise as long as you write me the codes i will definitely give you full mark...
hope am not giving you too much hassle...

many thanks....

korsila
Sorry for the delay, I have been on holidays.

Here is a sample calling of the routine:

void main(int argc,char *argv[])
{   char name1[150],name2[150];

    printf("please enter name 1:\n");
    scanf("%s\n",name1);
    printf("please enter name 2:\n");
    scanf("%s\n",name2);
    if(compname(name1,name2)==0)
        printf("2 names are matched\n");
    else printf("2 names are not matched\n");
}
Avatar of korsila

ASKER

Adjusted points from 200 to 250
Avatar of korsila

ASKER

Dear imladris...

i think this line should be
if (compname(name1, name2)==0) (your code)

shouold be ...

if (compname(name1, name2)==1) --correct one..

cus whenever i enter the same names it said 2 names are not matched...!! what do you think...

however, this is what i request more..
1...
anyway i need a loop to ask the user after finishing compareing that would you like to continue to compare "yes/no" if yes the loop get back to the screen ask for entering 2 names again...

2...
how to use this program with database file with contained plenty of names in data file..
could you write the codes for this implementation...

p.s. i have already incresed the ponit up to 250 for you ..hope you can do me a favor again...

ppss..do you know anything about the Icon program???
if you can translate this program to the icon program I will put another request with the same points -250...but in the mean time please get these code which i requested above done before...
Avatar of ozo
Could you give examples of some names that should match, and some names that should not match?
Yes, you are quite right, it should have been ==1.

Here is a sample of doing it in a loop for 1):

void main(int argc,char *argv[])
{   char name1[150],name2[150],ans;

    do
    {   printf("please enter name 1:\n");
        scanf("%s\n",name1);
        printf("please enter name 2:\n");
        scanf("%s\n",name2);
        if(compname(name1,name2)==1)
            printf("2 names are matched\n");
        else printf("2 names are not matched\n");
        printf("compare again (y or n)?\n");
        scanf("%c",&ans);
    } while(ans=='y' || ans=='Y');
}


for 2), I will not be able to write code for accessing a database. There are hundreds of details to sort through to get that exactly right.
It is possible I could do some sample code for files, if you can provide an exact definition and sample of what is in the file.

and p.s.'ly, no, I know nothing about Icon.
Avatar of korsila

ASKER

then could you do the code for files...

these following details are in the file...

first name, surname, birthdate, marriage, and death records..

---------------

the thing is whenever two names are matched the program will link personal deatail together into the same profile...

forexample...

1. John , Smith 16/8/1974, married in 1986, die 1989...

2. John, Smyth , married with Sara and got two children..


when the proogram compare these 2 name ..Sith and Smyth...and it is matched(2 names are indentical) then the program must link these 2 details together..merge the detail of both "Smyth" and "Smith" together...

so you need to write one more code for lankage if those 2 names are matched...!!!

--------------------------

another thing you can do is ..to compare one name which is entered from the main screen and then compare whethere this name is matched to any names in the data file or not????? must be more efficient....find the matched name and then prinout the detail ..and after that
link the names which matched in datafile  together with the name that we enetered at the beginning...

here is a short example fromthe above request...

main program..

plese enter name: (I have entered name "Smyth")

.... now the program is to find the name which will be matched in the data file...


datafile
-----------
smith...
smit...
smiths...
--------
asssume 3 names are matched to "Smyth" so the program print out the detail of 3 names and then link them together...!!!

-----------------------------------

hope yuou can make it again this time...

p.s. if you think it's too hard I will increse more points for you...

many thanks again...

Korsila


The devil is in the details in programming. I am uncertain about a number of things. Firstly the example of the records in the file:

1. John , Smith 16/8/1974, married in 1986, die 1989...

2. John, Smyth , married with Sara and got two children..


does not correspond to the definition:

first name, surname, birthdate, marriage, and death records..

Record number 2, for instance, doesn't appear to have a birthdate. If the file contains, as the example is implying, a bunch of freeform kind of entries, writing a program to interpret that reliably is a huge task. If the information is in a fixed form, on the other hand, it is quite straightforward to write code to read it. For example:

first name, surname, birthdate, spouse first name, spouse surname, marriage date, death date

a concrete example:

John,Smith,01/01/1950,Jane,Doe,01/01/1970,01/01/1995
Rick,Black,01/01/1951,Mary,Brown,01/01/1971,01/01/1996

In this case the program knows exactly what each entry means, what form it is in, and that it is contained between commas.

The second requirement I am unclear on is the reference to merging the records. It would appear that if two "Smith"'s are found their data needs to be merged. Does this mean that the data in records can be incomplete? What if data is contradictory, i.e. the birthdate listed in the first record is different from the birthdate listed in the second record? Also, merged to where? To a printout? To another file? Would the merged entry be a single line? Two lines?

The experts-exchange forum works best for questioners that have specific questions, that experts can provide concrete answers to. It seems that you have a number of ideas about accomplishing something w.r.t. matching name information, but no concrete requirements. I would suggest that the best way to proceed would be get a concrete simple example of the kind of thing you need. You can learn from that and work at expanding it to do all the things you are interested in. Perhaps the second example would serve, namely entering a name, and checking that name against each entry in a fixed form file and printing out every match.

If, at some point in the process of expanding/enhancing the matching program you run into difficulties, you can ask more questions here, naturally.
Avatar of korsila

ASKER

Dear Imladris..

you 're absolutely right ...!! i do agree..so the data file should be something like this...! like you suggested..!


first name, surname, birthdate, spouse first name, spouse surname, marriage date, death date

                      a concrete example:

                      John,Smith,01/01/1950,Jane,Doe,01/01/1970,01/01/1995
                      Rick,Black,01/01/1951,Mary,Brown,01/01/1971,01/01/1996


The thing is i would like to merge or link 2 names that are matched..and then save into another file or print out to the screen....and the merge entry should be 2 lines of couse...




so could you ggive me some good and simple examples to work on it...
any codes which you think it is the best way to implement and handle my problem....


importantly, the "linkage procedure" between input name and any names in the datafile should be merged after matching ...

...if  2 names are matched then linked 2 names together...the merged entry can be two lines if you like...(maybe it's quiet easy to do)...

...
so my request is..

1..the code for comparing name from input  with any names in the dtafile...

and if input name is mtached to names in datafile...do linkae code(2)

2. linkage codes...for linking or merging names which are matched and then either can save into the file or can print out...

the merged entry can be 2 lines (if 2 names are matched), 3 lines, 4 and so on...depends on how many names are matched..?

it will be impressive if you can give any comment and some good codes which is similar to the requiremnt...

I know it's hard..but could you do your best for me....

many thanks...

Korsila...

p.s. should i accepted your previous answer and give you the points first before get working another requirement...!!.

Here is working code (I tested it). It does what I suggested, with the file format (file name is "names.dat") also as I suggested.

/* This program accesses a vital statistics file. It will show all matches
   for a user supplied surname.
*/

#include <stdio.h>
#include <string.h>

/* When a record (line) of the file is read in, it is parsed into its
   components, which are stored in an array. There are seven elements
   in the record (and the array) which is represented by ENUM.
   The subsequent defines specify which array element contains the
   named component: first name, last name etc.

   The use of defines makes it easier to change and read code.
*/

#define ENUM  7
#define FNAME 0
#define LNAME 1
#define BDATE 2
#define SFNAM 3
#define SLNAM 4
#define MDATE 5
#define DDATE 6

int compname(char *n1,char *n2);

/* Conceptually what happens is that the user supplies a name for matching
   and this is then compared to each record in the file, and any match
   is shown on the screen. More specifically:

   set matched to false
   open the names file
   do
      get a name from the user
      go to the beginning of the file
      while there are lines in the file, read a line
         set up strtok and get first token
         assign components of line to element array
         if supplied name equals name for this record
            if no matches yet, print header
            print record information
            set matched to true
      if no matches found, print no match message
      ask if another compare is desired
   while user entered y


   strtok is a useful standard library function that takes a string
   and breaks out the component pieces based on delimiters (comma's
   in this case).
*/

void main(int argc,char *argv[])
{      int i,matched;
      char name[150],line[500],*elm[7],*token;
      FILE *namefile;

      matched=0;
      namefile=fopen("names.dat","r");
      do
      {      printf("Please enter name to match:\n");
            gets(name);
            fseek(namefile,0L,0);
            while(fgets(line,500,namefile)!=NULL)
            {      token=strtok(line,",\n");
                  for(i=0; i<ENUM; ++i)
                  {      elm[i]=token;
                        token=strtok(NULL,",\n");
                  }
                  if(compname(name,elm[LNAME])==1)
                  {      if(matched==0)printf("First Name Last Name  Birth      First Name Last Name  Marriage   Death\n");
                        printf("%-10s %-10s %10s %-10s %-10s %10s %10s\n",elm[FNAME],elm[LNAME],elm[BDATE],
                              elm[SFNAM],elm[SLNAM],elm[MDATE],elm[DDATE]);
                        matched=1;
                  }
            }
            if(matched==0)printf("No Matches Found.\n");
            printf("Compare again (y or n)?\n");
            gets(line);
      } while(line[0]=='y' || line[0]=='Y');
      fclose(namefile);
}

int compname(char *nm1,char *nm2)
{   int i,l1,l2;

    l1=strlen(nm1);
    l2=strlen(nm2);
    for(i=0; i<l1; ++i)
    {   if(i<l2 && nm1[i]==nm2[i])continue;
        if(i+1<l2 && nm1[i]==nm2[i+1])continue;
        if(i+2<l2 && nm1[i]==nm2[i+2])continue;
        if(i-1<l2 && i>0 && nm1[i]==nm2[i-1])continue;
        if(i<l2 && i>0 && nm1[i-1]==nm2[i])continue;
        if(i+1<l1 && i<l2 && nm1[i+1]==nm2[i])continue;
        if(i+2<l1 && i<l2 && nm1[i+2]==nm2[i])continue;
        if(i+1<l1 && i+1<l2 && nm1[i+1]==nm2[i+1])continue;
        if(i+2<l1 && i+2<l2 && nm1[i+2]==nm2[i+2])continue;
        return(0);
    }
    return(1);
}


P.S. It is in general nicer not to have run on questions like this. But you've been upping the points; it'll be fine for this one.
Beh, I forgot about the tabs. EE tends to collapse them. You should restore reasonable indentation to get a good view of the code.
Avatar of korsila

ASKER

wow!! what can I say.. am impressed...you're my hero..!!:):) that's a big help..!!!

i will follow and then wil get back to you as soon as i can get the codes done...

a million thank...:) am trying to work out now..

Korsila...
Avatar of korsila

ASKER

here is some problems when i test the program...

names.dat
-------------
John,Smith,01/01/1950,Jane,Doe,01/01/1970,01/01/1995
Rick,Black,01/01/1951,Mary,Brown,01/01/1971,01/01/1996
John, Smyth,01/01/1950,Single, " ", " ", "" 
John, Smithe," ",Jane,"",""
Snae, Chakkrit,08/05/1972 ," ","  "
Snae, Chakrit, " ", "","",""
---------------------------------

1. problem: when i enter "smyth" (should begin with capital "S") the program just matched the only one name which is "Smyth"...however, when i changed to the "Smyth" as an input name..the program worked fine...so could u fix?
 it..?



more requirement...

i would like to save the names which are matched into file name after names have been compared into "match.dat"
program should be asked by user whether to save matched names into datafile or not..? (i would love to save it)


and the names which are not matched into  "unmatched.dat" but before that it print out the input name which is not matched any names in datafile...like..
this is the print out when the input name is not matched..!!
--------------------------------------
"smeot" is not matched any names in datatfile
--------------------------------------
and then ask user wether to save this name into "unmatched.dat"


hope you don't mind to implement it again..

many thanks...

Korsila..

p.s. i think no more requirement...if i still have i will put another request in a new question for you...but in the mean time i have to accept your answer next time when you come up with a good result...!!
New and improved version.
The difference between smyth and Smyth has been resolved by using compchar which uses toupper on both characters to force them both to be uppercase, thus eliminating case differences as source of mismatches.

Note also that spaces after comma's will affect the outcome. If you put three spaces in front of Smithe (e.g.:

John,   Smithe," ",Jane,"",""

it will still fail to match). This program assumes the data to be in fixed and correct form. Leading or trailing spaces are not accounted for.

I have put the questions as to whether they wanted to save results in a file at the beginning, so that they only need to be answered once.



/* This program accesses a vital statistics file. It will show all matches
   for a user supplied surname.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/* When a record (line) of the file is read in, it is parsed into its
   components, which are stored in an array. There are seven elements
   in the record (and the array) which is represented by ENUM.
   The subsequent defines specify which array element contains the
   named component: first name, last name etc.

   The use of defines makes it easier to change and read code.
*/

#define ENUM  7
#define FNAME 0
#define LNAME 1
#define BDATE 2
#define SFNAM 3
#define SLNAM 4
#define MDATE 5
#define DDATE 6

int compname(char *n1,char *n2);
int compchar(char a,char b);

/* Conceptually what happens is that the user supplies a name for matching
   and this is then compared to each record in the file, and any match
   is shown on the screen. More specifically:

   set matched to false
   open the names file
   do
      get a name from the user
      go to the beginning of the file
      while there are lines in the file, read a line
         set up strtok and get first token
         assign components of line to element array
         if supplied name equals name for this record
            if no matches yet, print header
            print record information
            set matched to true
      if no matches found, print no match message
      ask if another compare is desired
   while user entered y


   strtok is a useful standard library function that takes a string
   and breaks out the component pieces based on delimiters (comma's
   in this case).
*/

void main(int argc,char *argv[])
{      int i,matched,msave,usave;
      char name[150],line[500],*elm[7],*token;
      FILE *namefile,*mfile,*ufile;

      printf("Save matched names in matched.dat (y or n)?\n");
      gets(line);
      msave=(toupper(line[0])=='Y');
      printf("Save unmatched names in unmatched.dat (y or n)?\n");
      gets(line);
      usave=(toupper(line[0])=='Y');
      namefile=fopen("names.dat","r");
      if(msave)mfile=fopen("matched.dat","w");
      if(usave)ufile=fopen("unmatched.dat","w");
      do
      {      printf("Please enter name to match:\n");
            gets(name);
            fseek(namefile,0L,0);
            matched=0;
            while(fgets(line,500,namefile)!=NULL)
            {      token=strtok(line,",\n");
                  for(i=0; i<ENUM; ++i)
                  {      elm[i]=token;
                        token=strtok(NULL,",\n");
                  }
                  if(compname(name,elm[LNAME])==1)
                  {      if(matched==0)printf("First Name Last Name  Birth      First Name Last Name  Marriage   Death\n");
                        printf("%-10s %-10s %10s %-10s %-10s %10s %10s\n",elm[FNAME],elm[LNAME],elm[BDATE],
                              elm[SFNAM],elm[SLNAM],elm[MDATE],elm[DDATE]);
                        if(msave)fprintf(mfile,"%-10s %-10s %10s %-10s %-10s %10s %10s\n",elm[FNAME],elm[LNAME],elm[BDATE],
                              elm[SFNAM],elm[SLNAM],elm[MDATE],elm[DDATE]);
                        matched=1;
                  }
            }
            if(matched==0)
            {      printf("No Matches Found.\n");
                  if(usave)fprintf(ufile,"%-10s",name);
            }
            printf("Compare again (y or n)?\n");
            gets(line);
      } while(toupper(line[0])=='Y');
      fclose(namefile);
      if(msave)fclose(mfile);
      if(usave)fclose(ufile);
}

int compname(char *nm1,char *nm2)
{   int i,l1,l2;

    l1=strlen(nm1);
    l2=strlen(nm2);
    for(i=0; i<l1; ++i)
    {   if(i<l2 && compchar(nm1[i],nm2[i]))continue;
        if(i+1<l2 && compchar(nm1[i],nm2[i+1]))continue;
        if(i+2<l2 && compchar(nm1[i],nm2[i+2]))continue;
        if(i-1<l2 && i>0 && compchar(nm1[i],nm2[i-1]))continue;
        if(i<l2 && i>0 && compchar(nm1[i-1],nm2[i]))continue;
        if(i+1<l1 && i<l2 && compchar(nm1[i+1],nm2[i]))continue;
        if(i+2<l1 && i<l2 && compchar(nm1[i+2],nm2[i]))continue;
        if(i+1<l1 && i+1<l2 && compchar(nm1[i+1],nm2[i+1]))continue;
        if(i+2<l1 && i+2<l2 && compchar(nm1[i+2],nm2[i+2]))continue;
        return(0);
    }
    return(1);
}

int compchar(char a,char b)
{      return(toupper(a)==toupper(b));
}
Avatar of korsila

ASKER

Adjusted points from 250 to 300
Avatar of korsila

ASKER

Dear Imladris,
as you said..
------------
The difference between smyth and Smyth has been resolved by using compchar which uses toupper on both characters to force them both to be uppercase, thus eliminating case differences as source of mismatches.
------------
1. it seemed still not working...
when i enter the input name "smyt"
the program only matched and print out only one record...
or even input file was "smyth" the program print out only one record of smyth...it should come up with 3 records..also it should match either "chakrit" or "chakkrit" but the program came up with "no match "message...however, if i entee nbame with the beginning with the capicatl letter like "Chakrit" , it came up with a good result...

could you please make sure u have fixed it with a samll letter as well..
 
--------------------------------------
Note also that spaces after comma's will affect the outcome. If you put three spaces in front of Smithe (e.g.:

                      John,   Smithe," ",Jane,"",""

                      it will still fail to match). This program assumes the data to be in fixed and correct form. Leading or trailing spaces are not accounted for.
----------------------------

2..but the print out of the first name(John) of Smythe when the input name is "Smyth" did come up to the screen..but it appears in the datafile somehow..


---------------------------------------
I have put the questions as to whether they wanted to save results in a file at the beginning, so that they only need to be answered once.

-------------------------------------
3. it 's very good...but whenever i am looking for a new match, the program will delete the old match and then save only a new match..similarly,saving in the  unmatch datafile...

I would like to keep the old records which matched or unmatched to the file name matched.dat and unmatched.dat respectively....so whenever new names are inputed to match , the program still save the old names which were matched and new names which just matched as well..similaly , saving in unmatched records as well...

could you make it????

-----------------------------

4. one more interesting requirement...
whenever the input names are not matched
f(matched==0)
{ printf("No Matches Found.\n");                       if(usave)fprintf(ufile,"%-10s",name);

"printf(would you like to update profile name in to the main datafile"
...yes or no...?

if yes...!
 please enter: first name:
  second name:
  date of birth:..
  etc..
after finish updating these details will be saved into names.dat..

if no...continute to compare/match..
 loop come back to match again...?

------------------------------

, I would like to save those names and new details of those peronal names (dtae of birth, first name, marriage records and so on)into the datafile "names.dat"...kidda updating procedure...program ask the user whether to update  names which are not matched into the datatfile or not (names.dat)..if yes the program show the details to enter..usch as :date of birth ......
first name:...?
marriage:....?
etc...

and then save these detail into names.dat...
---------------------------------------

hope you can be my hero again..
i have been appreciated so far...!!

many thanks....

Korsila..

p.s. I increse the point up to 300 now..so it will challenge you and cheer you up a bit..in the mean time don't work yourself to death...:) ..^_^

 
Avatar of korsila

ASKER

sorry..i have changed my datafile as below ..no space after comma.and the results just cmae up really good...

John,Smith,01/01/1950,Jane,Doe,01/01/1970,01/01/1995
Rick,Black,01/01/1951,Mary,Brown,01/01/1971,01/01/1996
John,Smyth,01/01/1950,Single, " ", " ", "" 
John,Smithe," ",Jane,"",""
Snae,Chakkrit,08/05/1972 ," ","  "
Snae,Chakrit, " ", "","",""
Gorsa,chakkrit," "," "," "," ",""
X,Glavin,01/05/1976,"","","",""
Zy,Glavyn,"","","","",""
Ian,McKay,27,01/1978,"","","",""
Ian,McCoy,"","","","",""
R,Michael,11,02,1967,Jira,Damp,"",""
Math,Mitchel,"","","","",""


so skip 1, 2, 3 from the previous problems above...it 's more or less working...

the things, I need from 3(see above) to be changed is to create more detail in dtafile when names are matched or are not matched...like foloowing below..

after names nmatched and names are saved into matched.dat

mathed.dat
---------------------------
1). header of entry should be shown like ..first nae, second name, date of bith... at the top in datafile..

2). the name which is entered to match should be appear here as well..
like group s"smyth" match...and then folowing the names whgich are matched including record...

3). ------------------------------- shouold be in datafile(matched.data) to separate another names which are matched and are not the same name s as the previous match...


and here is the example...of matched.dat after has been matched...

matched.dat
-----------------------------
first name, second name, date of birth..etc..--->request from 1)

name "Smyth" match---->request from 2)
--------------------------------------- -->(request from 3)

John,Smith,01/01/1950,Jane,Doe,01/01/1970,01/01/1995
John,Smyth,01/01/1950,Single, " ", " ", "" 
John,Smithe," ",Jane,"",""
-------------------------------------
name smyth macth--->again from 2
Snae,Chakkrit,08/05/1972 ," ","  "
Snae,Chakrit, " ", "","",""
Gorsa,chakkrit," "," "," "," ",""
-----------------------------------(from 3)

name Galvin match----------> from 2)
X,Glavin,01/05/1976,"","","",""
Zy,Glavyn,"","","","",""
-------------------------------------
name mkay match---> from 2
Ian,McKay,27,01/1978,"","","",""
Ian,McCoy,"","","","",""

---------------------------------
name Michel match---from 3)

R,Michael,11,02,1967,Jira,Damp,"",""
Math,Mitchel,"","","","",""

--------------------------


similarly to the unmatched.dat...the results should be exactly the same...like above...
------------------
requirement 4 still need to be implemented ....

a million  thank again..
korsila

ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The above code has the following additions:

header in matched.dat
show what name is being matched in matched.dat
separator line in matched.dat

equivalents for unmatched.dat

updating names.dat in the case of no match
Avatar of korsila

ASKER

Answer accepted
Avatar of korsila

ASKER

that was absoloutely spot on...!!!!
well done!!! heehh finally we got it done..

I wish i could give you all the points i have..^_^

i think you are my hero..next time if i got any requirement ..could you feel free to pop in again....

am touched and appreciated.. ...!!

a million thanks...

and best wish for your future

Korsila..
 
Avatar of korsila

ASKER

1. i just came up with the idea how to show
this program work on the internet..or kidda visualisation...
any suggestion?????

maybe here is a little example..

---------------------
Name to match:
---------------------

--------------------------------
click here to see names are matched
---------------------------------

somethinf like this
----
----
is represented a button when users have to click...to get the results...


REQUIREMENT 2 IS TO BE CONTINUED..
Avatar of korsila

ASKER


2. am interested in doing some graphic...

from the following codes:
void main(int argc,char *argv[])
{  
 char name1[150],name2[150],ans;
 
 do
 {
  printf("please enter name 1:\n");
  scanf("%s",name1);
  printf("please enter name 2:\n");
  scanf("%s",name2);  /* \n */
  if(compname(name1,name2)==1)
   printf("2 names are matched\n");
  else printf("2 names are not matched\n");
  printf("compare again (y or n)?\n");
  scanf("%s",&ans);
 } while(ans=='y' || ans=='Y');
}


int compname(char *nm1, char *nm2)
{
 int i, le1, le2;

 le1=strlen(nm1);
 le2=strlen(nm2);

 for(i=0; i<le1; ++i)
 {
   if(i<le2 && nm1[i]==nm2[i])continue;
   if(i+1<le2 && nm1[i]==nm2[i+1])continue;
   if(i+2<le2 && nm1[i]==nm2[i+2])continue;
   if(i-1<le2 && i>0 && nm1[i]==nm2[i-1])continue;
   if(i<le2 && i>0 && nm1[i-1]==nm2[i])continue;
   if(i+1<le1 && i<le2 && nm1[i+1]==nm2[i])continue;
   if(i+2<le1 && i<le2 && nm1[i+2]==nm2[i])continue;
   if(i+1<le1 && i+1<le2 && nm1[i+1]==nm2[i+1])continue;
   if(i+2<le1 && i+2<le2 && nm1[i+2]==nm2[i+2])continue;
   return(0);
 }
 return(1);
}


the program supposed to show how it compared...

igure1 tests for position of letters in matching alternate surname spellings
(see the first requirement figure.. above)

for example 2 name : GLAVIN and GLAWYN

test1
GLAVIN
|||
GLAWYN
|||
-----------------------
test2
GLAVIN
   |
GLAWYN
    |
-----------------------
test3
GLAVIN
   |
GLAWYN
     |
-----------------------
test4
GLAVIN
   |
GLAWYN
  |
-----------------------
test5
GLAVIN
  |
GLAWYN
   |
-----------------------
test6
GLAVIN
    |
GLAWYN
   |
-----------------------
test7
GLAVIN
     |
GLAWYN
   |
-----------------------
test8
GLAVIN
    |
GLAWYN
    |
-----------------------
test9
GLAVIN
     |
GLAWYN
     |
-----------------------


| is represented the comparation from test1 -test9.....see int compname()..
and also the figure from the first question (the top of this page)

...any idea???? to suggest???
can you make it...?

I will 100 points but if you think it's harder i will increase some later...


man thanks...

Korsila
















                                     
Getting this onto the Internet is not a task that can be accomplished in a matter of hours. There is a lot of hardware and software that has to be in place to facilitate that, and straightforward C is not good for the kind of graphic displays that are normally provided on the internet.

I don't understand requirement 2 either. It appears that the "graphic" is supposed to reflect the tests that are performed. The first three letters pass with test 1. But the next letter (V/W) passes with test 8, yet the graphic carries on to test 9? Is it a graphic? Or just characters coming up on the console (like printf supplies)? It would stream by too fast to read though?

You definitely need to open a new question, and work real hard at not letting it turn into a runon question this time.
Avatar of korsila

ASKER

.!! yeah it just characters coming up on the console (like printf supplies)? say it's a print out of the result to see how it works...cus finally both two names "GLAVIN and GLAWYN" and matched..so it printed out how it matched step by step...from test 1- test9...

you are getting to the point of my thought...

regards..

Korsila..

p.s. I will put another question on..
Avatar of korsila

ASKER

Dear  Imladris,

I need your help again...
I got another requirement for you which is smilar to the one you have been implemented...just changed a few things...and i don't think anyone could understand that apart from you..since you have been involved with my codes more or less...:)

I will put the require ment tpo you refering this  topic in this page "comparing name matching names algorithm "

many thanks,
and hope you are doing fine..

Korsila...