ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> squeak
squeak
Re: Finding and indexing 'similar' string
by Avi Bryant other posts by this author
Aug 26 2003 5:51PM messages near this date
Re: Finding and indexing 'similar' string | [Q] about Richard's GeeMail Example
On Tue, 26 Aug 2003, Julian Fitzell wrote:

>  Other than that, though, it works great: we used it for a sales
>  system and it allowed users to stop asking people to spell their names
>  over the phone.  I've tried typing in every convoluted spelling of my
>  name I can think of and it always finds me :)

And the code we used was (man, this is pretty old, these days I would use
streams...):

initialize

	SoundexMap _ Dictionary new.
	#('bpfv' 'cskgjqxz' 'dt' 'l' 'mn' 'r') doWithIndex:
            [:r :i | r do: [:c | SoundexMap at: c put: i asString first]].
	'aeiouyhw ' do: [:c | SoundexMap at: c put: nil].

soundex: aString

	|soundex i lastCode|
	soundex _ '0000' copy.
	aString isEmpty ifTrue: [^ soundex].
	soundex at: 1 put: (aString asUppercase at: 1).
	lastCode _ i _ 1.
	aString asLowercase allButFirst do:
		[:c | |code|
		(i < 4) ifTrue:
			[code _ SoundexMap at: c ifAbsent:[].
			 ((code = lastCode) or: [code isNil]) ifFalse:
                             [i := i + 1.
			     soundex at: i put: code].
			 lastCode _ code]].
	^ soundex
Thread:
Chris Muller
Jim Menard
Julian Fitzell
Avi Bryant

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved