[pk_soundex]

Description

Link: [pk_soundex]
Author: Pier Kuipers
Category: Database
Version: 8.x
License: Public Domain
Posted: Jan. 10, 2006
Updated: Jan. 12, 2011
More by this author...

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.

Parameters

none


Sample Usage

Usage:
[pk_soundex(<string>)]

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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

01/12/2011, Pier Kuipers

Good suggestion indeed :-) Tag has now been updated.
01/05/2011, Sidney San Martín

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).
Email:


Password:



Newest

Most Popular

Support tagSwap.net