Lasso Soft Inc. > Home

[pk_soundex]

Linkpk_soundex
AuthorPier Kuipers
CategoryDatabase
Version8.x
LicensePublic Domain
Posted10 Jan 2006
Updated12 Jan 2011
More by this author...

Description

Based on the NARA Soundex Guide (http://www.archives.gov/research_room/genealogy/census/soundex.html) The soundex is a coded surname (last name) index based on the way a surname sounds rather than the way it is spelled. Surnames that sound the same, but are spelled differently, like SMITH and SMYTH, have the same code and are filed together. The soundex coding system was developed so that you can find a surname even though it may have been recorded under various spellings. Every soundex code consists of a letter and three numbers, such as W-252. The letter is always the first letter of the surname. The numbers are assigned to the remaining letters of the surname according to the soundex guide. Zeroes are added at the end if necessary to produce a four-character code. Additional letters are disregarded.

 

Modified Jan 2011 at the suggestion of Sidney San Martín to include -copy reference.

Sample Usage

Usage:
[pk_soundex()]

Example:
[pk_soundex('Washington')] -> W252

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

	if(!(lasso_tagexists('pk_soundex')));
	
		define_tag('pk_soundex',
			-required='myString',
			-copy);
				
			if((#myString -> length) > 0);
			
				#myString -> uppercase;
				
				local('myStringArray' = ((#myString) -> split:''));
				local('mySoundexCode'=(#myStringArray -> get:1));
				local('fullSoundexCode'=(string));
						
				if(('Ëçǻ®') >> #mySoundexCode);
				
					#mySoundexCode = 'A';
				
				else(('') >> #mySoundexCode);
				
					#mySoundexCode = 'S';
				
				else(('éæè') >> #mySoundexCode);
				
					#mySoundexCode = 'E';
				
				else(('íêëì') >> #mySoundexCode);
				
					#mySoundexCode = 'I';
				
				else(('') >> #mySoundexCode);
				
					#mySoundexCode = 'N';
		
				else(('îïͯÎ') >> #mySoundexCode);
				
					#mySoundexCode = 'O';
		
				else(('ôòó') >> #mySoundexCode);
				
					#mySoundexCode = 'U';
		
				/if;
			
				local('thisSoundexCode'=(string));
				local('previousCharacter'=(string));
				local('previousSoundexCode'=(string));
				
				iterate(#myStringArray, local:'temp');
				
					if(loop_count != 1);
			
						#previousCharacter = (#myStringArray -> get((loop_count) - 1));
						
					/if;

					if(#fullSoundexCode -> length > 0);
						
						local('previousSoundexCode'=(#fullSoundexCode -> split('') -> get((#fullSoundexCode -> length))));
					
					else;
						
						local('previousSoundexCode'=(''));
					
					/if;
											
					if(((string_findregexp(#temp, -find='B|F|P|V')) -> size) > 0);
					
						#thisSoundexCode = '1';
						
					else(((string_findregexp(#temp, -find='C|G|J|K|Q|S|X|Z||§')) -> size) > 0);
					
						#thisSoundexCode = '2';
		
					else(((string_findregexp(#temp, -find='D|T')) -> size) > 0);
					
						#thisSoundexCode = '3';
		
					else(((string_findregexp(#temp, -find='L')) -> size) > 0);
					
						#thisSoundexCode = '4';
		
					else(((string_findregexp(#temp, -find='M|N|')) -> size) > 0);
					
						#thisSoundexCode = '5';
		
					else(((string_findregexp(#temp, -find='R')) -> size) > 0);
					
						#thisSoundexCode = '6';
		
					else(((string_findregexp(#temp, -find='B|F|P|V|C|G|J|K|Q|S|X|Z|D|T|L|M|N|R')) -> size) == 0);
					
						#thisSoundexCode = '';
					
					/if;
					
					if(#thisSoundexCode != '');
						#fullSoundexCode += #thisSoundexCode;
					else;
						#fullSoundexCode += 'Z';
					/if;
					
					if(loop_count != 1);
						if((#thisSoundexCode != #previousSoundexCode));
							if(#temp != #previousCharacter);
				
								#mySoundexCode += #thisSoundexCode;
							
							/if;
						/if;
					/if;
					
					if(#mySoundexCode -> length > 3);
					
						Loop_Abort;
						
					/if;
				
				/iterate;
				
				if(#mySoundexCode -> length < 4);
				
					local('x'=(4 - ((#mySoundexCode -> length))));
			
					Loop(#x);
					
						#mySoundexCode += '0';
					
					/Loop;
					
				/if;
				
				return(#mySoundexCode);
			
			else;
			
				return('0000');
			
			/if;

		/define_tag;
		
	/if;

Comments

12 Jan 2011, Pier Kuipers

Good suggestion indeed :-) Tag has now been updated.

05 Jan 2011, Sidney San Martin

You might want to add `-Copy` after the `-Required`. Currently, this tag modifies the passed-in string (i.e. if you pass a variable to [pk_soundex], the contents become uppercase).

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft