FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
June 01, 2000
The Double Metaphone Search Algorithm

(Page 1 of 2)
Lawrence Phillips
June 2000/The Double Metaphone Search Algorithm/Figure 1

Figure 1: The part of the Double Metaphone algorithm that processes the letter 'C'

case 'C':
   if((current > 1  )//various germanic
      AND !IsVowel(current - 2) 
      AND StringAt((current - 1), 3, "ACH", "") 
      AND ((GetAt(current + 2) != 'I') 
           AND ((GetAt(current + 2) != 'E') 
      OR StringAt((current - 2), 6, "BACHER", "MACHER", "")) )) {
         MetaphAdd("K"); current +=2; break;
   }
   //special case 'caesar'
   if((current == 0) AND StringAt(current, 6, "CAESAR", "")) {  
      MetaphAdd("S"); current +=2; break;
   }
   if(StringAt(current, 4, "CHIA", "")) {  //italian 'chianti'
      MetaphAdd("K"); current +=2; break;
   }
   if(StringAt(current, 2, "CH", "")) {    
      //find 'michael'
      if((current > 0) AND StringAt(current, 4, "CHAE", "")) {  
         MetaphAdd("K", "X"); current +=2; break;
      }
      if((current == 0)  //greek roots e.g. 'chemistry', 'chorus'
         AND (StringAt((current + 1), 5, "HARAC", "HARIS", "") 
         OR StringAt((current + 1), 3, "HOR", 
                     "HYM", "HIA", "HEM", ""))
         AND !StringAt(0, 5, "CHORE", "")) {

         MetaphAdd("K"); current +=2; break;
      }
      //germanic, greek, or otherwise 'ch' for 'kh' sound
      if((StringAt(0, 4, "VAN ", "VON ", "") 
         OR StringAt(0, 3, "SCH", "")) 

         // 'architect but not 'arch', 'orchestra', 'orchid'
         OR StringAt((current - 2), 6, "ORCHES", "ARCHIT", 
                     "ORCHID")
         OR StringAt((current + 2), 1, "T", "S", "")
         OR ((StringAt((current - 1), 1, "A", "O", "U", "E", "") 
             OR (current == 0))

         //e.g., 'wachtler', 'wechsler', but not 'tichner'
         AND StringAt((current + 2), 1, "L", "R", "N", "M", "B", 
                      "H", "F", "V", "W", " ", ""))) {  
         MetaphAdd("K");
      } else {    
         if(current > 0) {
            if(StringAt(0, 2, "MC", ""))  //e.g., "McHugh"
               MetaphAdd("K"); 
            else MetaphAdd("X", "K");
         }
            else  MetaphAdd("X");
      }
         current +=2; break;
   }
   //e.g, 'czerny'
   if(StringAt(current, 2, "CZ", "") 
      AND !StringAt((current - 2), 4, "WICZ", "")) { 
         MetaphAdd("S", "X"); current += 2; break;
   }
   //e.g., 'focaccia'
   if(StringAt((current + 1), 3, "CIA", "")) {  
      MetaphAdd("X"); current += 3; break;
   }
   //double 'C', but not if e.g. 'McClellan'
   if(StringAt(current, 2, "CC", "") AND !((current == 1) 
      AND (GetAt(0) == 'M')))  
      //'bellocchio' but not 'bacchus'
      if(StringAt((current + 2), 1, "I", "E", "H") 
         AND !StringAt((current + 2), 2, "HU", "")) {  
            
         //'accident', 'accede' 'succeed'
         if(((current == 1) AND (GetAt(current - 1) == 'A')) 
            OR StringAt((current - 1), 5, "UCCEE", "UCCES", ""))
                
            MetaphAdd("KS");
         else  //'bacci', 'bertucci', other italian
            MetaphAdd("X");
            
         current += 3; break;
      } else {//Pierce's rule
         MetaphAdd("K"); current += 2; break;
      }
   if(StringAt(current, 2, "CK", "CG", "CQ", "")) {
      MetaphAdd("K"); current += 2; break;
   }
   if(StringAt(current, 2, "CI", "CE", "CY", "")) {
      //italian vs. english
      if(StringAt(current, 3, "CIO", "CIE", "CIA", ""))  
         MetaphAdd("S", "X");
      else
         MetaphAdd("S");
      current += 2; break;
   }  //else
   MetaphAdd("K");

   //name sent in 'mac caffrey', 'mac gregor
   if(StringAt((current + 1), 2, " C", " Q", " G", ""))  
      current += 3;
   else
      if(StringAt((current + 1), 1, "C", "K", "Q", "") 
         AND !StringAt((current + 1), 2, "CE", "CI", ""))

         current += 2; else current += 1;
   break;

1 | 2 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.
DR. DOBB'S CAREER CENTER
Looking for a new job? open | close
Search jobs on Dr. Dobb's TechCareers
Function:

Keyword(s):

State:  
  • Post Your Resume
  • Employers Area
  • News & Features
  • Blogs & Forums
  • Career Resources

    Browse By:
    Location | Employer | City
  • Most Recent Posts:



    MICROSITES
    FEATURED TOPIC

    ADDITIONAL TOPICS

    INFO-LINK



     




    Techweb
    Informationweek Business Technology Network
    InformationweekInformationweek 500Informationweek 500 ConferenceInformationweek AnalyticsInformationweek Events
    Informationweek MagazineGlobal CIOIWK Government ITbMightyByte and SwitchDark Reading
    Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingPlug Into The CloudDr. DobbsContentinople
    space
    TechWeb Events Network
    InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0Mobile Business ExpoNoJitter
    Black HatGTECEnergy CampCloud ConnectGov 2.0 ExpoGov 2.0 Summit
    space
    Light Reading Communications Network
    Light ReadingLight Reading AsiaUnstrungCable Digital NewsInternet EvolutionPyramid Research
    Heavy ReadingLight Reading LiveLight Reading InsiderEthrnet ExpoTelco TVTower Technology Summit
    space
    Financial Technology Network
    Advanced TradingBank Systems and TechnologyInsurance and TechnologyWall Street and TechnologyAccelerating WallstreetBST SummitBuyside Trading SummitIT Summit
    space
    Microsoft Technology Network
    MSDNTechNetTotal IT ProTotal Dev ProNET Total Dev Pro CommunitySQL Total Dev Pro Community
    space