Click here to Skip to main content
15,894,343 members
Articles / Programming Languages / C++

Implement Phonetic ("Sounds-like") Name Searches with Double Metaphone Part I: Introduction & C++ Implementation

Rate me:
Please Sign up or sign in to vote.
4.91/5 (21 votes)
19 Mar 2007CPOL15 min read 149K   2.8K   60  
Introduces the Double Metaphone algorithm for phonetic comparison of proper names, and provides a practical C++ implementation for use in the reader's projects.
// DoubleMetaphoneShort.h : Declaration of the DoubleMetaphoneShort

#pragma once
#include "resource.h"       // main symbols


// IDoubleMetaphoneShort
[
	object,
	uuid("8DDA7DB4-1548-4E71-B9F7-EB6714A5CD07"),
	dual,	helpstring("IDoubleMetaphoneShort Interface"),
	pointer_default(unique)
]
__interface IDoubleMetaphoneShort : IDispatch
{
	HRESULT ComputeMetaphoneKeys([in] BSTR Word, [out] short* PrimaryKey, [out] short* AlternateKey);
	HRESULT CompareMetaphoneKeys([in] short PrimaryKey, [in] short AlternateKey1, [in] short PrimaryKey2, [in] short AlternateKey2, [out, retval] VARIANT_BOOL* Result);

	HRESULT ComputeMetaphoneKeysScr([in] BSTR Word, [out] VARIANT* PrimaryKey, [out] VARIANT* AlternateKey);
}; 



// DoubleMetaphoneShort

[
	coclass,
	threading("both"),
	vi_progid("MetaphoneCOM.DoubleMetaphoneShort"),
	progid("MetaphoneCOM.DoubleMetaphoneShort.1"),
	version(1.0),
	uuid("C762BBEB-9D86-4988-BB7E-3A9963249AB6"),
	helpstring("Adam J. Nelson's Double Metaphone Short Implementation")
]
class ATL_NO_VTABLE DoubleMetaphoneShort : 
	public IDoubleMetaphoneShort
{
public:
	DoubleMetaphoneShort()
	{
	}


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

public:
	STDMETHOD(ComputeMetaphoneKeys)(/*[in]*/ BSTR Word, /*[out]*/ short* PrimaryKey, /*[out]*/ short* AlternateKey);
	STDMETHOD(CompareMetaphoneKeys)(/*[in]*/ short PrimaryKey1, /*[in]*/ short AlternateKey1, /*[in]*/ short PrimaryKey2, /*[in]*/ short AlternateKey2, /*[out, retval]*/ VARIANT_BOOL* Result);

	STDMETHOD(ComputeMetaphoneKeysScr)(/*[in]*/ BSTR Word, /*[out]*/ VARIANT* PrimaryKey, /*[out]*/ VARIANT* AlternateKey);
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
My name is Adam Nelson. I've been a professional programmer since 1996, working on everything from database development, early first-generation web applications, modern n-tier distributed apps, high-performance wireless security tools, to my last job as a Senior Consultant at BearingPoint posted in Baghdad, Iraq training Iraqi developers in the wonders of C# and ASP.NET. I am currently an Engineering Director at Dell.

I have a wide range of skills and interests, including cryptography, image processing, computational linguistics, military history, 3D graphics, database optimization, and mathematics, to name a few.

Comments and Discussions