2197
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
COPYRIGHT (c) 2009 by eXept Software AG
|
|
4 |
All Rights Reserved
|
|
5 |
|
|
6 |
This software is furnished under a license and may be used
|
|
7 |
only in accordance with the terms of that license and with the
|
|
8 |
inclusion of the above copyright notice. This software may not
|
|
9 |
be provided or otherwise made available to, or used by, any
|
|
10 |
other person. No title to or ownership of the software is
|
|
11 |
hereby transferred.
|
|
12 |
"
|
|
13 |
"{ Package: 'stx:libbasic2' }"
|
|
14 |
|
|
15 |
Object subclass:#PhoneticStringUtilities
|
|
16 |
instanceVariableNames:''
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Collections-Text-Support'
|
|
20 |
!
|
|
21 |
|
2208
|
22 |
Object subclass:#PhoneticStringComparator
|
|
23 |
instanceVariableNames:''
|
|
24 |
classVariableNames:''
|
|
25 |
poolDictionaries:''
|
|
26 |
privateIn:PhoneticStringUtilities
|
|
27 |
!
|
|
28 |
|
2211
|
29 |
PhoneticStringUtilities::PhoneticStringComparator subclass:#ExtendedSoundexStringComparator
|
|
30 |
instanceVariableNames:''
|
|
31 |
classVariableNames:'CharacterTranslationDict'
|
|
32 |
poolDictionaries:''
|
|
33 |
privateIn:PhoneticStringUtilities
|
|
34 |
!
|
|
35 |
|
2208
|
36 |
PhoneticStringUtilities::PhoneticStringComparator subclass:#KoelnerPhoneticCodeStringComparator
|
|
37 |
instanceVariableNames:''
|
|
38 |
classVariableNames:'CharacterTranslationDict'
|
|
39 |
poolDictionaries:''
|
|
40 |
privateIn:PhoneticStringUtilities
|
|
41 |
!
|
|
42 |
|
|
43 |
PhoneticStringUtilities::PhoneticStringComparator subclass:#SoundexStringComparator
|
|
44 |
instanceVariableNames:''
|
|
45 |
classVariableNames:'CharacterTranslationDict'
|
|
46 |
poolDictionaries:''
|
|
47 |
privateIn:PhoneticStringUtilities
|
|
48 |
!
|
|
49 |
|
|
50 |
PhoneticStringUtilities::SoundexStringComparator subclass:#MySQLSoundexStringComparator
|
|
51 |
instanceVariableNames:''
|
|
52 |
classVariableNames:''
|
|
53 |
poolDictionaries:''
|
|
54 |
privateIn:PhoneticStringUtilities
|
|
55 |
!
|
|
56 |
|
|
57 |
Object subclass:#NYSIISStringComparator
|
|
58 |
instanceVariableNames:''
|
|
59 |
classVariableNames:''
|
|
60 |
poolDictionaries:''
|
|
61 |
privateIn:PhoneticStringUtilities
|
|
62 |
!
|
|
63 |
|
2211
|
64 |
PhoneticStringUtilities::PhoneticStringComparator subclass:#PhonemStringComparator
|
|
65 |
instanceVariableNames:''
|
|
66 |
classVariableNames:'CharacterTranslationDict'
|
|
67 |
poolDictionaries:''
|
|
68 |
privateIn:PhoneticStringUtilities
|
|
69 |
!
|
|
70 |
|
2208
|
71 |
PhoneticStringUtilities::PhoneticStringComparator subclass:#DoubleMetaphoneStringComparator
|
|
72 |
instanceVariableNames:'inputKey primaryTranslation secondaryTranslation startIndex
|
|
73 |
currentIndex skipCount'
|
|
74 |
classVariableNames:''
|
|
75 |
poolDictionaries:''
|
|
76 |
privateIn:PhoneticStringUtilities
|
|
77 |
!
|
|
78 |
|
|
79 |
PhoneticStringUtilities::SoundexStringComparator subclass:#MiracodeStringComparator
|
|
80 |
instanceVariableNames:''
|
|
81 |
classVariableNames:''
|
|
82 |
poolDictionaries:''
|
|
83 |
privateIn:PhoneticStringUtilities
|
|
84 |
!
|
|
85 |
|
2197
|
86 |
!PhoneticStringUtilities class methodsFor:'documentation'!
|
|
87 |
|
|
88 |
copyright
|
|
89 |
"
|
|
90 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
91 |
COPYRIGHT (c) 2009 by eXept Software AG
|
|
92 |
All Rights Reserved
|
|
93 |
|
|
94 |
This software is furnished under a license and may be used
|
|
95 |
only in accordance with the terms of that license and with the
|
|
96 |
inclusion of the above copyright notice. This software may not
|
|
97 |
be provided or otherwise made available to, or used by, any
|
|
98 |
other person. No title to or ownership of the software is
|
|
99 |
hereby transferred.
|
|
100 |
"
|
|
101 |
!
|
|
102 |
|
|
103 |
documentation
|
|
104 |
"
|
2285
|
105 |
Utilities which are helpful to perform phonetic string searches or comparisons
|
|
106 |
|
2208
|
107 |
soundexCode
|
|
108 |
this algorithm was originally contained in the CharacterArray class;
|
|
109 |
|
|
110 |
nysiis
|
|
111 |
a modified soundex algorithm
|
|
112 |
|
2209
|
113 |
miracode
|
|
114 |
another modified soundex algorithm ('american soundex') used in the 1880 census.
|
|
115 |
|
|
116 |
mySQLSoundex
|
|
117 |
another modified soundex algorithm used in mySQL.
|
|
118 |
|
2208
|
119 |
koelner phoneticCode
|
|
120 |
provides a functionality similar to soundex, but much more tuned towards the German language
|
|
121 |
|
|
122 |
Double metaphone
|
|
123 |
works with most european languages.
|
2211
|
124 |
|
|
125 |
phonem
|
|
126 |
described in Georg Wilde and Carsten Meyer, 'Doppelgaenger gesucht - Ein Programm fuer kontextsensitive phonetische Textumwandlung'
|
|
127 |
from 'ct Magazin fuer Computer & Technik 25/1999'.
|
|
128 |
|
|
129 |
More info for german readers is found in:
|
|
130 |
http://www.uni-koeln.de/phil-fak/phonetik/Lehre/MA-Arbeiten/magister_wilz.pdf
|
|
131 |
"
|
|
132 |
!
|
|
133 |
|
|
134 |
sampleData
|
|
135 |
"
|
|
136 |
for the 50 most common german names, we get:
|
|
137 |
|
|
138 |
ext.
|
|
139 |
name soundex soundex metaphone phonet phonet2 phonix daitsch phonem koeln
|
|
140 |
|
|
141 |
müller M460 54600000 MLR MÜLA NILA M4000000 689000 MYLR 657
|
|
142 |
schmidt S253 25300000 SKMTT SHMIT ZNIT S5300000 463000 CMYD 8628
|
|
143 |
schneider S253 25360000 SKNTR SHNEIDA ZNEITA S5300000 463900 CNAYDR 8627
|
|
144 |
fischer F260 12600000 FSKR FISHA FIZA F8000000 749000 VYCR 387
|
|
145 |
weber W160 16000000 WBR WEBA FEBA $1000000 779000 VBR 317
|
|
146 |
meyer M600 56000000 MYR MEIA NEIA M0000000 619000 MAYR 67
|
|
147 |
wagner W256 25600000 WKNR WAKNA FAKNA $2500000 756900 VACNR 367
|
|
148 |
schulz S242 24200000 SKLS SHULS ZULZ S4800000 484000 CULC 85
|
|
149 |
becker B260 12600000 BKR BEKA BEKA B2000000 759000 BCR 147
|
|
150 |
hoffmann H155 15500000 HFMN HOFMAN UFNAN $7550000 576600 OVMAN 036
|
|
151 |
schäfer S216 21600000 SKFR SHEFA ZEFA S7000000 479000 CVR 837
|
2197
|
152 |
"
|
|
153 |
! !
|
|
154 |
|
|
155 |
!PhoneticStringUtilities class methodsFor:'phonetic codes'!
|
|
156 |
|
|
157 |
koelnerPhoneticCodeOf:aString
|
|
158 |
"return a koelner phonetic code.
|
|
159 |
The koelnerPhonetic code is for the german language what the soundex code is for english;
|
|
160 |
it returns simular strings for similar sounding words.
|
|
161 |
There are some differences to soundex, though:
|
|
162 |
its length is not limited to 4, but depends on the length of the original string;
|
2207
|
163 |
it does not start with the first character of the input.
|
|
164 |
This algorithm is described by Postel 1969"
|
2197
|
165 |
|
2209
|
166 |
^ (KoelnerPhoneticCodeStringComparator new phoneticStringsFor:aString) first
|
2197
|
167 |
|
|
168 |
"
|
|
169 |
#(
|
|
170 |
'Müller'
|
|
171 |
'Miller'
|
|
172 |
'Mueller'
|
|
173 |
'Mühler'
|
|
174 |
'Mühlherr'
|
|
175 |
'Mülherr'
|
|
176 |
'Myler'
|
|
177 |
'Millar'
|
|
178 |
'Myller'
|
|
179 |
'Müllar'
|
|
180 |
'Müler'
|
|
181 |
'Muehler'
|
|
182 |
'Mülller'
|
|
183 |
'Müllerr'
|
|
184 |
'Muehlherr'
|
|
185 |
'Muellar'
|
|
186 |
'Mueler'
|
|
187 |
'Mülleer'
|
|
188 |
'Mueller'
|
|
189 |
'Nüller'
|
|
190 |
'Nyller'
|
|
191 |
'Niler'
|
|
192 |
'Czerny'
|
|
193 |
'Tscherny'
|
|
194 |
'Czernie'
|
|
195 |
'Tschernie'
|
|
196 |
'Schernie'
|
|
197 |
'Scherny'
|
|
198 |
'Scherno'
|
|
199 |
'Czerne'
|
|
200 |
'Zerny'
|
|
201 |
'Tzernie'
|
|
202 |
'Breschnew'
|
|
203 |
) do:[:w |
|
|
204 |
Transcript show:w; show:'->'; showCR:(PhoneticStringUtilities koelnerPhoneticCodeOf:w)
|
|
205 |
].
|
|
206 |
"
|
|
207 |
|
|
208 |
"
|
2209
|
209 |
PhoneticStringUtilities koelnerPhoneticCodeOf:'Breschnew'. '17863'.
|
|
210 |
PhoneticStringUtilities koelnerPhoneticCodeOf:'Breschneff'. '17863'.
|
|
211 |
PhoneticStringUtilities koelnerPhoneticCodeOf:'Braeschneff'. '17863'.
|
|
212 |
PhoneticStringUtilities koelnerPhoneticCodeOf:'Braessneff'. '17863'.
|
|
213 |
PhoneticStringUtilities koelnerPhoneticCodeOf:'Pressneff'. '17863'.
|
|
214 |
PhoneticStringUtilities koelnerPhoneticCodeOf:'Presznäph'. '17863'.
|
|
215 |
PhoneticStringUtilities koelnerPhoneticCodeOf:'Preschnjiev'. '17863'.
|
|
216 |
"
|
|
217 |
!
|
|
218 |
|
|
219 |
mySQLSoundexCodeOf:aString
|
|
220 |
"return the mySQL soundex code. The mysql soundex coed is different from the miracode 'american' soundex
|
|
221 |
(no 4char limitation; different order of duplicate vowel vs. duplicate code elimination)"
|
|
222 |
|
|
223 |
^ (MySQLSoundexStringComparator new phoneticStringsFor:aString) first
|
|
224 |
|
|
225 |
"
|
|
226 |
#(
|
|
227 |
'Müller'
|
|
228 |
'Miller'
|
|
229 |
'Mueller'
|
|
230 |
'Mühler'
|
|
231 |
'Mühlherr'
|
|
232 |
'Mülherr'
|
|
233 |
'Myler'
|
|
234 |
'Millar'
|
|
235 |
'Myller'
|
|
236 |
'Müllar'
|
|
237 |
'Müler'
|
|
238 |
'Muehler'
|
|
239 |
'Mülller'
|
|
240 |
'Müllerr'
|
|
241 |
'Muehlherr'
|
|
242 |
'Muellar'
|
|
243 |
'Mueler'
|
|
244 |
'Mülleer'
|
|
245 |
'Mueller'
|
|
246 |
'Nüller'
|
|
247 |
'Nyller'
|
|
248 |
'Niler'
|
|
249 |
'Czerny'
|
|
250 |
'Tscherny'
|
|
251 |
'Czernie'
|
|
252 |
'Tschernie'
|
|
253 |
'Schernie'
|
|
254 |
'Scherny'
|
|
255 |
'Scherno'
|
|
256 |
'Czerne'
|
|
257 |
'Zerny'
|
|
258 |
'Tzernie'
|
|
259 |
'Breschnew'
|
|
260 |
) do:[:w |
|
|
261 |
Transcript show:w; show:'->'; showCR:(PhoneticStringUtilities mySQLSoundexCodeOf:w)
|
|
262 |
].
|
|
263 |
"
|
|
264 |
|
|
265 |
"
|
|
266 |
PhoneticStringUtilities mySQLSoundexCodeOf:'Breschnew'.
|
|
267 |
PhoneticStringUtilities mySQLSoundexCodeOf:'Breschneff'.
|
|
268 |
PhoneticStringUtilities mySQLSoundexCodeOf:'Braeschneff'.
|
|
269 |
PhoneticStringUtilities mySQLSoundexCodeOf:'Braessneff'.
|
|
270 |
PhoneticStringUtilities mySQLSoundexCodeOf:'Pressneff'.
|
|
271 |
PhoneticStringUtilities mySQLSoundexCodeOf:'Presznäph'.
|
|
272 |
PhoneticStringUtilities mySQLSoundexCodeOf:'Preschnjiev'.
|
2197
|
273 |
"
|
|
274 |
!
|
|
275 |
|
|
276 |
soundexCodeOf:aString
|
|
277 |
"return a soundex phonetic code or nil.
|
2207
|
278 |
Soundex (1918, 1922) returns similar codes for similar sounding words, making it a useful
|
2197
|
279 |
tool when searching for words where the correct spelling is unknown.
|
|
280 |
(read Knuth or search the web if you dont know what a soundex code is).
|
|
281 |
Caveat: 'similar sounding words' means: 'similar sounding in english'."
|
|
282 |
|
2210
|
283 |
^ (SoundexStringComparator new phoneticStringsFor:aString) first
|
2197
|
284 |
|
2210
|
285 |
"/ old code - now use code in private class...
|
|
286 |
"/ |inStream codeStream ch last lch codeLength codes code lastCode|
|
|
287 |
"/
|
|
288 |
"/ inStream := aString readStream.
|
|
289 |
"/ inStream skipSeparators.
|
|
290 |
"/ inStream atEnd ifTrue:[
|
|
291 |
"/ ^ nil
|
|
292 |
"/ ].
|
|
293 |
"/
|
|
294 |
"/ ch := inStream next.
|
|
295 |
"/ ch isLetter ifFalse:[
|
|
296 |
"/ ^ nil
|
|
297 |
"/ ].
|
|
298 |
"/ codeLength := 0.
|
|
299 |
"/
|
|
300 |
"/ codes := Dictionary new.
|
|
301 |
"/ codes atAll:'bpfv' put:$1.
|
|
302 |
"/ codes atAll:'cskgjqxz' put:$2.
|
|
303 |
"/ codes atAll:'dt' put:$3.
|
|
304 |
"/ codes atAll:'l' put:$4.
|
|
305 |
"/ codes atAll:'nm' put:$5.
|
|
306 |
"/ codes atAll:'r' put:$6.
|
|
307 |
"/
|
|
308 |
"/ codeStream := WriteStream on:(String new:4).
|
|
309 |
"/ codeStream nextPut:(ch asUppercase).
|
|
310 |
"/ last := ch asLowercase.
|
|
311 |
"/ lastCode := codes at:last ifAbsent:nil.
|
|
312 |
"/
|
|
313 |
"/ [inStream atEnd] whileFalse:[
|
|
314 |
"/ ch := inStream next.
|
|
315 |
"/ lch := ch asLowercase.
|
|
316 |
"/ lch = last ifFalse:[
|
|
317 |
"/ last := lch.
|
|
318 |
"/
|
|
319 |
"/ code := codes at:lch ifAbsent:nil.
|
|
320 |
"/ (code notNil and:[ code ~= lastCode]) ifTrue:[
|
|
321 |
"/ codeLength < 3 ifTrue:[
|
|
322 |
"/ codeStream nextPut:code.
|
|
323 |
"/ codeLength := codeLength + 1.
|
|
324 |
"/ codeLength > 3 ifTrue:[^ codeStream contents].
|
|
325 |
"/ ].
|
|
326 |
"/ ].
|
|
327 |
"/ lastCode := code.
|
|
328 |
"/ ]
|
|
329 |
"/ ].
|
|
330 |
"/ [ codeLength < 3 ] whileTrue:[
|
|
331 |
"/ codeStream nextPut:$0.
|
|
332 |
"/ codeLength := codeLength + 1.
|
|
333 |
"/ ].
|
|
334 |
"/
|
|
335 |
"/ ^ codeStream contents
|
2197
|
336 |
|
|
337 |
"
|
|
338 |
PhoneticStringUtilities soundexCodeOf:'claus'
|
|
339 |
PhoneticStringUtilities soundexCodeOf:'clause'
|
|
340 |
PhoneticStringUtilities soundexCodeOf:'close'
|
|
341 |
PhoneticStringUtilities soundexCodeOf:'smalltalk'
|
|
342 |
PhoneticStringUtilities soundexCodeOf:'smaltalk'
|
|
343 |
PhoneticStringUtilities soundexCodeOf:'smaltak'
|
|
344 |
PhoneticStringUtilities soundexCodeOf:'smaltok'
|
|
345 |
PhoneticStringUtilities soundexCodeOf:'smoltok'
|
|
346 |
PhoneticStringUtilities soundexCodeOf:'aa'
|
|
347 |
PhoneticStringUtilities soundexCodeOf:'by'
|
|
348 |
PhoneticStringUtilities soundexCodeOf:'bab'
|
|
349 |
PhoneticStringUtilities soundexCodeOf:'bob'
|
|
350 |
PhoneticStringUtilities soundexCodeOf:'bop'
|
|
351 |
"
|
|
352 |
! !
|
|
353 |
|
2208
|
354 |
!PhoneticStringUtilities::PhoneticStringComparator class methodsFor:'constant'!
|
|
355 |
|
|
356 |
defaultClass
|
|
357 |
^SoundexStringComparator
|
|
358 |
! !
|
|
359 |
|
|
360 |
!PhoneticStringUtilities::PhoneticStringComparator class methodsFor:'instance creation'!
|
|
361 |
|
|
362 |
new
|
|
363 |
^ self basicNew initialize.
|
|
364 |
! !
|
|
365 |
|
|
366 |
!PhoneticStringUtilities::PhoneticStringComparator methodsFor:'api'!
|
|
367 |
|
|
368 |
does:aString soundLike:anotherString
|
|
369 |
|translations1 translations2|
|
|
370 |
|
|
371 |
translations1 := self phoneticStringsFor:aString.
|
|
372 |
translations2 := self phoneticStringsFor:anotherString.
|
|
373 |
|
|
374 |
^ translations1 contains:[:t1 |
|
|
375 |
translations2 contains:[:t2 | t1 = t2]]
|
|
376 |
|
|
377 |
"
|
|
378 |
PhoneticStringUtilities::SoundexStringComparator new
|
|
379 |
does:'miller' soundLike:'miler'.
|
|
380 |
PhoneticStringUtilities::SoundexStringComparator new
|
|
381 |
does:'miller' soundLike:'milner'.
|
|
382 |
"
|
|
383 |
!
|
|
384 |
|
|
385 |
phoneticStringsFor: aString
|
|
386 |
"Should answer an array of alternate phonetic strings for the given input string."
|
|
387 |
self subclassResponsibility
|
|
388 |
|
|
389 |
"
|
|
390 |
(PhoneticStringUtilities::SoundexStringComparator new
|
|
391 |
phoneticStringsFor:'miller') first
|
|
392 |
'miller' asSoundexCode
|
|
393 |
"
|
|
394 |
! !
|
|
395 |
|
|
396 |
!PhoneticStringUtilities::PhoneticStringComparator methodsFor:'initialization'!
|
|
397 |
|
|
398 |
initialize
|
|
399 |
"Invoked when a new instance is created."
|
|
400 |
|
|
401 |
"/ please change as required (and remove this comment)
|
|
402 |
|
|
403 |
"/ super initialize. -- commented since inherited method does nothing
|
|
404 |
! !
|
|
405 |
|
2211
|
406 |
!PhoneticStringUtilities::ExtendedSoundexStringComparator class methodsFor:'documentation'!
|
|
407 |
|
|
408 |
documentation
|
|
409 |
"
|
|
410 |
There are many extended and enhanced soundex variants around;
|
|
411 |
here is one, called 'extended soundex'. It is destribed for example in
|
|
412 |
http://www.epidata.dk/documentation.php.
|
|
413 |
An author or origin is unknown.
|
|
414 |
|
|
415 |
The number of digits is increased to 5 or 8;
|
|
416 |
The first character is not used literally; instead it is encoded like the rest.
|
|
417 |
This might have a negative effect on names starting with a vovel, though.
|
|
418 |
|
|
419 |
Overall, it can be doubted if this is really an enhancement after all.
|
|
420 |
"
|
|
421 |
! !
|
|
422 |
|
|
423 |
!PhoneticStringUtilities::ExtendedSoundexStringComparator methodsFor:'api'!
|
|
424 |
|
|
425 |
phoneticStringsFor:aString
|
|
426 |
"generates both an extended soundex of length 5 and one of length 8"
|
|
427 |
|
|
428 |
|first second u t prevCode|
|
|
429 |
|
|
430 |
u := aString asUppercase.
|
|
431 |
first := second := ''.
|
|
432 |
u do:[:c |
|
|
433 |
t := self translate:c.
|
|
434 |
(t notNil and:[ t ~= '0' and:[ t ~= prevCode ]]) ifTrue:[
|
|
435 |
first := first , t.
|
|
436 |
second := second , t.
|
|
437 |
second size == 8 ifTrue:[
|
|
438 |
^ Array with:(first copyTo:5) with:second
|
|
439 |
].
|
|
440 |
].
|
|
441 |
prevCode := t
|
|
442 |
].
|
|
443 |
[ first size < 5 ] whileTrue:[
|
|
444 |
first := first , '0'.
|
|
445 |
second := second , '0'.
|
|
446 |
].
|
|
447 |
[ second size < 8 ] whileTrue:[
|
|
448 |
second := second , '0'
|
|
449 |
].
|
|
450 |
^ Array with:first with:second
|
|
451 |
|
|
452 |
"
|
|
453 |
self basicNew phoneticStringsFor:'müller' #('87900' '87900000')
|
|
454 |
self basicNew phoneticStringsFor:'miller' #('87900' '87900000')
|
|
455 |
self basicNew phoneticStringsFor:'muller' #('87900' '87900000')
|
|
456 |
self basicNew phoneticStringsFor:'muler' #('87900' '87900000')
|
|
457 |
self basicNew phoneticStringsFor:'schmidt' #('38600' '38600000')
|
|
458 |
self basicNew phoneticStringsFor:'schneider' #('38690' '38690000')
|
|
459 |
self basicNew phoneticStringsFor:'fischer' #('23900' '23900000')
|
|
460 |
self basicNew phoneticStringsFor:'weber' #('19000' '19000000')
|
|
461 |
self basicNew phoneticStringsFor:'meyer' #('89000' '89000000')
|
|
462 |
self basicNew phoneticStringsFor:'wagner' #('48900' '48900000')
|
|
463 |
self basicNew phoneticStringsFor:'schulz' #('37500' '37500000')
|
|
464 |
self basicNew phoneticStringsFor:'becker' #('13900' '13900000')
|
|
465 |
self basicNew phoneticStringsFor:'hoffmann' #('28800' '28800000')
|
|
466 |
self basicNew phoneticStringsFor:'schäfer' #('32900' '32900000')
|
|
467 |
"
|
|
468 |
! !
|
|
469 |
|
|
470 |
!PhoneticStringUtilities::ExtendedSoundexStringComparator methodsFor:'private'!
|
|
471 |
|
|
472 |
translate:aCharacter
|
|
473 |
"use simple if's for more speed when compiled"
|
|
474 |
|
|
475 |
"vowels serve as separators"
|
|
476 |
aCharacter == $A ifTrue:[^ '0' ].
|
|
477 |
aCharacter == $E ifTrue:[^ '0' ].
|
|
478 |
aCharacter == $I ifTrue:[^ '0' ].
|
|
479 |
aCharacter == $O ifTrue:[^ '0' ].
|
|
480 |
aCharacter == $U ifTrue:[^ '0' ].
|
|
481 |
aCharacter == $Y ifTrue:[^ '0' ].
|
|
482 |
|
|
483 |
aCharacter == $B ifTrue:[^ '1' ].
|
|
484 |
aCharacter == $P ifTrue:[^ '1' ].
|
|
485 |
|
|
486 |
aCharacter == $F ifTrue:[^ '2' ].
|
|
487 |
aCharacter == $V ifTrue:[^ '2' ].
|
|
488 |
|
|
489 |
aCharacter == $C ifTrue:[^ '3' ].
|
|
490 |
aCharacter == $S ifTrue:[^ '3' ].
|
|
491 |
aCharacter == $K ifTrue:[^ '3' ].
|
|
492 |
|
|
493 |
aCharacter == $G ifTrue:[^ '4' ].
|
|
494 |
aCharacter == $J ifTrue:[^ '4' ].
|
|
495 |
|
|
496 |
aCharacter == $Q ifTrue:[^ '5' ].
|
|
497 |
aCharacter == $X ifTrue:[^ '5' ].
|
|
498 |
aCharacter == $Z ifTrue:[^ '5' ].
|
|
499 |
|
|
500 |
aCharacter == $D ifTrue:[^ '6' ].
|
|
501 |
aCharacter == $G ifTrue:[^ '6' ].
|
|
502 |
aCharacter == $T ifTrue:[^ '6' ].
|
|
503 |
|
|
504 |
aCharacter == $L ifTrue:[^ '7' ].
|
|
505 |
|
|
506 |
aCharacter == $M ifTrue:[^ '8' ].
|
|
507 |
aCharacter == $N ifTrue:[^ '8' ].
|
|
508 |
|
|
509 |
aCharacter == $R ifTrue:[^ '9' ].
|
|
510 |
^ nil
|
|
511 |
! !
|
|
512 |
|
2208
|
513 |
!PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator class methodsFor:'documentation'!
|
|
514 |
|
|
515 |
documentation
|
|
516 |
"
|
|
517 |
The koelnerPhonetic code is for the german language what the soundex code is for english.
|
|
518 |
It returns simular strings for similar sounding words.
|
|
519 |
|
|
520 |
There are some differences to soundex, though:
|
|
521 |
its length is not limited to 4, but depends on the length of the original string;
|
|
522 |
it does not start with the first character of the input.
|
|
523 |
|
|
524 |
This algorithm was described by Postel 1969
|
|
525 |
"
|
|
526 |
! !
|
|
527 |
|
|
528 |
!PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator methodsFor:'api'!
|
|
529 |
|
|
530 |
phoneticStringsFor: aString
|
|
531 |
"return a koelner phonetic code.
|
|
532 |
The koelnerPhonetic code is for the german language what the soundex code is for english;
|
|
533 |
it returns simular strings for similar sounding words.
|
|
534 |
There are some differences to soundex, though:
|
|
535 |
its length is not limited to 4, but depends on the length of the original string;
|
|
536 |
it does not start with the first character of the input.
|
|
537 |
This algorithm is described by Postel 1969"
|
|
538 |
|
|
539 |
|in ret val rslt|
|
|
540 |
|
|
541 |
in := aString withoutSeparators asLowercase.
|
|
542 |
in := in copyReplaceString:'ph' withString:'f'.
|
|
543 |
in := in copyReplaceAll:$ü withAll:'u'.
|
|
544 |
in := in copyReplaceAll:$ä withAll:'a'.
|
|
545 |
in := in copyReplaceAll:$ö withAll:'o'.
|
|
546 |
in := in copyReplaceAll:$ß withAll:'ss'.
|
|
547 |
in := '#',in,'#'.
|
|
548 |
|
|
549 |
ret := ''.
|
|
550 |
1 to:in size-2 do:[:i |
|
|
551 |
|sub|
|
|
552 |
|
|
553 |
sub := in copyFrom:i to:i+2.
|
|
554 |
val := (i==1)
|
|
555 |
ifTrue:[ self convertFirst:sub ]
|
|
556 |
ifFalse:[ self convertRest:sub ].
|
|
557 |
ret := ret,val
|
|
558 |
].
|
|
559 |
|
|
560 |
ret := ret select:[:ch | ch ~= $-].
|
|
561 |
|
|
562 |
(ret startsWith:'0') ifTrue:[
|
|
563 |
ret := '0',(ret select:[:ch | ch ~= $0]).
|
|
564 |
] ifFalse:[
|
|
565 |
ret := ret select:[:ch | ch ~= $0].
|
|
566 |
].
|
|
567 |
|
|
568 |
rslt := String streamContents:[:s |
|
|
569 |
|prev|
|
|
570 |
|
|
571 |
ret do:[:ch |
|
|
572 |
ch ~= prev ifTrue:[
|
|
573 |
s nextPut:ch
|
|
574 |
].
|
|
575 |
prev := ch.
|
|
576 |
].
|
|
577 |
].
|
|
578 |
^ Array with:rslt.
|
|
579 |
|
|
580 |
"
|
|
581 |
#(
|
|
582 |
'Müller'
|
|
583 |
'Miller'
|
|
584 |
'Mueller'
|
|
585 |
'Mühler'
|
|
586 |
'Mühlherr'
|
|
587 |
'Mülherr'
|
|
588 |
'Myler'
|
|
589 |
'Millar'
|
|
590 |
'Myller'
|
|
591 |
'Müllar'
|
|
592 |
'Müler'
|
|
593 |
'Muehler'
|
|
594 |
'Mülller'
|
|
595 |
'Müllerr'
|
|
596 |
'Muehlherr'
|
|
597 |
'Muellar'
|
|
598 |
'Mueler'
|
|
599 |
'Mülleer'
|
|
600 |
'Mueller'
|
|
601 |
'Nüller'
|
|
602 |
'Nyller'
|
|
603 |
'Niler'
|
|
604 |
'Czerny'
|
|
605 |
'Tscherny'
|
|
606 |
'Czernie'
|
|
607 |
'Tschernie'
|
|
608 |
'Schernie'
|
|
609 |
'Scherny'
|
|
610 |
'Scherno'
|
|
611 |
'Czerne'
|
|
612 |
'Zerny'
|
|
613 |
'Tzernie'
|
|
614 |
'Breschnew'
|
|
615 |
) do:[:w |
|
|
616 |
Transcript show:w; show:'->'; showCR:(PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:w) first
|
|
617 |
].
|
|
618 |
"
|
|
619 |
|
|
620 |
"
|
|
621 |
PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:'Breschnew' -> '17863'
|
|
622 |
PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:'Breschneff' -> '17863'
|
|
623 |
PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:'Braeschneff' -> '17863'
|
|
624 |
PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:'Braessneff' -> '17863'
|
|
625 |
PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:'Pressneff' -> '17863'
|
|
626 |
PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:'Presznäph' -> '17863'
|
|
627 |
PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator new phoneticStringsFor:'Präschnäf' -> '17863'
|
|
628 |
"
|
2211
|
629 |
"
|
|
630 |
self basicNew phoneticStringsFor:'müller' #('657')
|
|
631 |
self basicNew phoneticStringsFor:'möller' #('657')
|
|
632 |
self basicNew phoneticStringsFor:'miller' #('657')
|
|
633 |
self basicNew phoneticStringsFor:'muller' #('657')
|
|
634 |
self basicNew phoneticStringsFor:'muler' #('657')
|
|
635 |
self basicNew phoneticStringsFor:'schmidt' #('862')
|
|
636 |
self basicNew phoneticStringsFor:'schneider' #('8627')
|
|
637 |
self basicNew phoneticStringsFor:'fischer' #('387')
|
|
638 |
self basicNew phoneticStringsFor:'weber' #('317')
|
|
639 |
self basicNew phoneticStringsFor:'meyer' #('67')
|
|
640 |
self basicNew phoneticStringsFor:'wagner' #('3467')
|
|
641 |
self basicNew phoneticStringsFor:'schulz' #('858')
|
|
642 |
self basicNew phoneticStringsFor:'becker' #('147')
|
|
643 |
self basicNew phoneticStringsFor:'hoffmann' #('036')
|
|
644 |
self basicNew phoneticStringsFor:'schäfer' #('837')
|
|
645 |
"
|
2208
|
646 |
! !
|
|
647 |
|
|
648 |
!PhoneticStringUtilities::KoelnerPhoneticCodeStringComparator methodsFor:'private'!
|
|
649 |
|
|
650 |
convertFirst:chars
|
|
651 |
#(
|
|
652 |
('#a#' '0')
|
|
653 |
('#e#' '0')
|
|
654 |
('#i#' '0')
|
|
655 |
('#j#' '0')
|
|
656 |
('#y#' '0')
|
|
657 |
('#o#' '0')
|
|
658 |
('#u#' '0')
|
|
659 |
|
|
660 |
('#ca' '4')
|
|
661 |
('#ch' '4')
|
|
662 |
('#ck' '4')
|
|
663 |
('#cl' '4')
|
|
664 |
('#co' '4')
|
|
665 |
('#cq' '4')
|
|
666 |
('#cr' '4')
|
|
667 |
('#cu' '4')
|
|
668 |
('#cx' '4')
|
|
669 |
|
|
670 |
('#c#' '8')
|
|
671 |
) do:[:pair |
|
|
672 |
(pair first match:chars) ifTrue:[
|
|
673 |
^ pair second
|
|
674 |
]
|
|
675 |
].
|
|
676 |
|
|
677 |
^ self convertRest:chars
|
|
678 |
!
|
|
679 |
|
|
680 |
convertRest:chars
|
|
681 |
#(
|
|
682 |
('#ds' '8')
|
|
683 |
('#dc' '8')
|
|
684 |
('#dz' '8')
|
|
685 |
('#ts' '8')
|
|
686 |
('#tc' '8')
|
|
687 |
('#tz' '8')
|
|
688 |
('#d#' '2')
|
|
689 |
('#t#' '2')
|
|
690 |
('cx#' '8')
|
|
691 |
('kx#' '8')
|
|
692 |
('qx#' '8')
|
|
693 |
('#x#' '48')
|
|
694 |
('sc#' '8')
|
|
695 |
('sz#' '8')
|
|
696 |
('#ca' '4')
|
|
697 |
('#co' '4')
|
|
698 |
('#cu' '4')
|
|
699 |
('#ch' '4')
|
|
700 |
('#ck' '4')
|
|
701 |
('#cx' '4')
|
|
702 |
('#cq' '4')
|
|
703 |
('#c#' '8')
|
|
704 |
('#a#' '0')
|
|
705 |
('#e#' '0')
|
|
706 |
('#i#' '0')
|
|
707 |
('#j#' '0')
|
|
708 |
('#y#' '0')
|
|
709 |
('#o#' '0')
|
|
710 |
('#u#' '0')
|
|
711 |
('#h#' '-')
|
|
712 |
('#l#' '5')
|
|
713 |
('#r#' '7')
|
|
714 |
('#m#' '6')
|
|
715 |
('#n#' '6')
|
|
716 |
('#s#' '8')
|
|
717 |
('#z#' '8')
|
|
718 |
('#b#' '1')
|
|
719 |
('#p#' '1')
|
|
720 |
('#f#' '3')
|
|
721 |
('#v#' '3')
|
|
722 |
('#w#' '3')
|
|
723 |
('#g#' '4')
|
|
724 |
('#k#' '4')
|
|
725 |
('#q#' '4')
|
|
726 |
('###' '?')
|
|
727 |
) do:[:pair |
|
|
728 |
(pair first match:chars) ifTrue:[
|
|
729 |
^ pair second
|
|
730 |
]
|
|
731 |
].
|
|
732 |
|
|
733 |
self error:'cannot happen'
|
|
734 |
! !
|
|
735 |
|
|
736 |
!PhoneticStringUtilities::SoundexStringComparator class methodsFor:'documentation'!
|
|
737 |
|
|
738 |
documentation
|
|
739 |
"
|
|
740 |
WARNING: this is the so called 'simplified soundex' algorithm;
|
|
741 |
there are more variants like miracode (american soundex) or mysqlSoundex around.
|
|
742 |
Be sure to use the correct algorithm, if the generated strings must be compatible
|
|
743 |
(otherwise, the differences are probably too small to be noticed as effect)
|
|
744 |
|
|
745 |
The following was copied from http://www.civilsolutions.com.au/publications/dedup.htm
|
|
746 |
|
|
747 |
SOUNDEX is a phonetic coding algorithm that ignores many of the unreliable
|
|
748 |
components of names, but by doing so reports more matches.
|
|
749 |
|
|
750 |
There are some variations around in the literature;
|
|
751 |
the following is called 'simplified soundex', and the rules for coding a name are:
|
|
752 |
|
|
753 |
1. The first letter of the name is used in its un-coded form to serve as the prefix
|
|
754 |
character of the code. (The rest of the code is numerical).
|
|
755 |
|
|
756 |
2. Thereafter, W and H are ignored entirely.
|
|
757 |
|
|
758 |
3. A, E, I, 0, U, Y are not assigned a code number, but do serve as 'separators' (see Step 5).
|
|
759 |
|
|
760 |
4. Other letters of the name are converted to a numerical equivalent:
|
|
761 |
B, P, F, V 1
|
|
762 |
C, G, J, K, Q, S, X, Z 2
|
|
763 |
D, T 3
|
|
764 |
L 4
|
|
765 |
M, N 5
|
|
766 |
R 6
|
|
767 |
|
|
768 |
5. There are two exceptions:
|
|
769 |
1. Letters that follow prefix letters which would, if coded, have the same
|
|
770 |
numerical code, are ignored in all cases unless a ''separator'' (see Step 3) precedes them.
|
|
771 |
|
|
772 |
2. The second letter of any pair of consonants having the same code number is likewise ignored,
|
|
773 |
i.e. unless there is a ''separator'' between them in the name.
|
|
774 |
|
|
775 |
6. The final SOUNDEX code consists of the prefix letter plus three numerical characters.
|
|
776 |
Longer codes are truncated to this length, and shorter codes are extended to it by adding zeros.
|
|
777 |
|
|
778 |
Notice, that in another variant, w and h are treated slightly differently.
|
|
779 |
This is only of relevance, if you need to reconstruct original soundex codes of other programs
|
|
780 |
or for the original 1880 us census data.
|
|
781 |
|
|
782 |
"
|
|
783 |
! !
|
|
784 |
|
|
785 |
!PhoneticStringUtilities::SoundexStringComparator methodsFor:'api'!
|
|
786 |
|
|
787 |
phoneticStringsFor:aString
|
|
788 |
|u p t prevCode|
|
|
789 |
|
|
790 |
u := aString asUppercase.
|
|
791 |
p := u first asString.
|
|
792 |
prevCode := self translate:u first.
|
|
793 |
u from:2 to:u size do:[:c |
|
|
794 |
t := self translate:c.
|
|
795 |
(t notNil and:[ t ~= '0' and:[ t ~= prevCode ]]) ifTrue:[
|
|
796 |
p := p , t.
|
|
797 |
p size == 4 ifTrue:[^ Array with:p ].
|
|
798 |
].
|
|
799 |
prevCode := t
|
|
800 |
].
|
|
801 |
[ p size < 4 ] whileTrue:[
|
|
802 |
p := p , '0'
|
|
803 |
].
|
|
804 |
^ Array with:(p copyFrom:1 to:4)
|
|
805 |
! !
|
|
806 |
|
|
807 |
!PhoneticStringUtilities::SoundexStringComparator methodsFor:'private'!
|
|
808 |
|
|
809 |
translate:aCharacter
|
|
810 |
"use simple if's for more speed when compiled"
|
|
811 |
|
|
812 |
"vowels serve as separators"
|
|
813 |
aCharacter == $A ifTrue:[^ '0' ].
|
|
814 |
aCharacter == $E ifTrue:[^ '0' ].
|
|
815 |
aCharacter == $I ifTrue:[^ '0' ].
|
|
816 |
aCharacter == $O ifTrue:[^ '0' ].
|
|
817 |
aCharacter == $U ifTrue:[^ '0' ].
|
|
818 |
aCharacter == $Y ifTrue:[^ '0' ].
|
|
819 |
|
|
820 |
aCharacter == $B ifTrue:[^ '1' ].
|
|
821 |
aCharacter == $P ifTrue:[^ '1' ].
|
|
822 |
aCharacter == $F ifTrue:[^ '1' ].
|
|
823 |
aCharacter == $V ifTrue:[^ '1' ].
|
|
824 |
|
|
825 |
aCharacter == $C ifTrue:[^ '2' ].
|
|
826 |
aCharacter == $S ifTrue:[^ '2' ].
|
|
827 |
aCharacter == $K ifTrue:[^ '2' ].
|
|
828 |
aCharacter == $G ifTrue:[^ '2' ].
|
|
829 |
aCharacter == $J ifTrue:[^ '2' ].
|
|
830 |
aCharacter == $Q ifTrue:[^ '2' ].
|
|
831 |
aCharacter == $X ifTrue:[^ '2' ].
|
|
832 |
aCharacter == $Z ifTrue:[^ '2' ].
|
|
833 |
|
|
834 |
aCharacter == $D ifTrue:[^ '3' ].
|
|
835 |
aCharacter == $T ifTrue:[^ '3' ].
|
|
836 |
|
|
837 |
aCharacter == $L ifTrue:[^ '4' ].
|
|
838 |
|
|
839 |
aCharacter == $M ifTrue:[^ '5' ].
|
|
840 |
aCharacter == $N ifTrue:[^ '5' ].
|
|
841 |
|
|
842 |
aCharacter == $R ifTrue:[^ '6' ].
|
|
843 |
^ nil
|
|
844 |
! !
|
|
845 |
|
|
846 |
!PhoneticStringUtilities::MySQLSoundexStringComparator class methodsFor:'documentation'!
|
|
847 |
|
|
848 |
documentation
|
|
849 |
"
|
|
850 |
MySQL soundex is like american Soundex (i.e. miracode) without the 4 character limitation,
|
|
851 |
and also removing vokals first, then removing duplicate codes
|
|
852 |
(whereas the soundex code does this in reverse order).
|
|
853 |
|
|
854 |
These variations are important, if you need the ame soundex codes to be generated.
|
|
855 |
"
|
|
856 |
! !
|
|
857 |
|
|
858 |
!PhoneticStringUtilities::MySQLSoundexStringComparator methodsFor:'api'!
|
|
859 |
|
|
860 |
phoneticStringsFor:aString
|
|
861 |
|u p t prevCode|
|
|
862 |
|
|
863 |
u := aString asUppercase.
|
|
864 |
p := u first asString.
|
|
865 |
prevCode := self translate:u first.
|
|
866 |
u from:2 to:u size do:[:c |
|
|
867 |
t := self translate:c.
|
|
868 |
(t notNil and:[ t ~= '0' and:[ t ~= prevCode ]]) ifTrue:[
|
|
869 |
p := p , t.
|
|
870 |
].
|
|
871 |
(t ~= '0' and:[ c ~= $W and:[c ~= $H]]) ifTrue:[
|
|
872 |
prevCode := t.
|
|
873 |
].
|
|
874 |
].
|
|
875 |
[ p size < 4 ] whileTrue:[
|
|
876 |
p := p , '0'
|
|
877 |
].
|
|
878 |
^ Array with:p
|
|
879 |
! !
|
|
880 |
|
|
881 |
!PhoneticStringUtilities::NYSIISStringComparator class methodsFor:'documentation'!
|
|
882 |
|
|
883 |
documentation
|
|
884 |
"
|
|
885 |
NYSIIS Algorithm:
|
|
886 |
|
|
887 |
1.
|
|
888 |
remove all ''S'' and ''Z'' chars from the end of the surname
|
|
889 |
|
|
890 |
2.
|
|
891 |
transcode initial strings
|
|
892 |
MAC => MC
|
|
893 |
PF => F
|
|
894 |
|
|
895 |
3.
|
|
896 |
Transcode trailing strings as follows,
|
|
897 |
|
|
898 |
IX => IC
|
|
899 |
EX => EC
|
|
900 |
YE,EE,IE => Y
|
|
901 |
NT,ND => D
|
|
902 |
|
|
903 |
4.
|
|
904 |
transcode ''EV'' to ''EF'' if not at start of name
|
|
905 |
|
|
906 |
5.
|
|
907 |
use first character of name as first character of key
|
|
908 |
|
|
909 |
6.
|
|
910 |
remove any ''W'' that follows a vowel
|
|
911 |
|
|
912 |
7.
|
|
913 |
replace all vowels with ''A''
|
|
914 |
|
|
915 |
8.
|
|
916 |
transcode ''GHT'' to ''GT''
|
|
917 |
|
|
918 |
9.
|
|
919 |
transcode ''DG'' to ''G''
|
|
920 |
|
|
921 |
10.
|
|
922 |
transcode ''PH'' to ''F''
|
|
923 |
|
|
924 |
11.
|
|
925 |
if not first character, eliminate all ''H'' preceded or followed by a vowel
|
|
926 |
|
|
927 |
12.
|
|
928 |
change ''KN'' to ''N'', else ''K'' to ''C''
|
|
929 |
|
|
930 |
13.
|
|
931 |
if not first character, change ''M'' to ''N''
|
|
932 |
|
|
933 |
14.
|
|
934 |
if not first character, change ''Q'' to ''G''
|
|
935 |
|
|
936 |
15.
|
|
937 |
transcode ''SH'' to ''S''
|
|
938 |
|
|
939 |
16.
|
|
940 |
transcode ''SCH'' to ''S''
|
|
941 |
|
|
942 |
17.
|
|
943 |
transcode ''YW'' to ''Y''
|
|
944 |
|
|
945 |
18.
|
|
946 |
if not first or last character, change ''Y'' to ''A''
|
|
947 |
|
|
948 |
19.
|
|
949 |
transcode ''WR'' to ''R''
|
|
950 |
|
|
951 |
20.
|
|
952 |
if not first character, change ''Z'' to ''S''
|
|
953 |
|
|
954 |
21.
|
|
955 |
transcode terminal ''AY'' to ''Y''
|
|
956 |
|
|
957 |
22.
|
|
958 |
remove traling vowels
|
|
959 |
|
|
960 |
23.
|
|
961 |
collapse all strings of repeated characters
|
|
962 |
|
|
963 |
24.
|
|
964 |
if first char of original surname was a vowel, append it to the code
|
|
965 |
"
|
|
966 |
! !
|
|
967 |
|
|
968 |
!PhoneticStringUtilities::NYSIISStringComparator methodsFor:'api'!
|
|
969 |
|
|
970 |
phoneticStringsFor:aString
|
|
971 |
|k|
|
|
972 |
|
|
973 |
k := self rule1:(aString asUppercase).
|
|
974 |
k := self rule2:k.
|
|
975 |
k := self rule3:k.
|
|
976 |
k := self rule4:k.
|
|
977 |
k := self rule5:k.
|
|
978 |
k := self rule6:k.
|
|
979 |
k := self rule7:k.
|
|
980 |
k := self rule8:k.
|
|
981 |
k := self rule9:k.
|
|
982 |
k := self rule10:k.
|
|
983 |
k := self rule11:k.
|
|
984 |
k := self rule12:k.
|
|
985 |
k := self rule13:k.
|
|
986 |
k := self rule14:k.
|
|
987 |
k := self rule15:k.
|
|
988 |
k := self rule16:k.
|
|
989 |
k := self rule17:k.
|
|
990 |
k := self rule18:k.
|
|
991 |
k := self rule19:k.
|
|
992 |
k := self rule20:k.
|
|
993 |
k := self rule21:k.
|
|
994 |
k := self rule22:k.
|
|
995 |
k := self rule23:k.
|
|
996 |
k := self rule24:k originalKey:aString.
|
|
997 |
^ Array with:k
|
|
998 |
|
|
999 |
"
|
|
1000 |
self new phoneticStringsFor:'hello'
|
|
1001 |
"
|
|
1002 |
! !
|
|
1003 |
|
|
1004 |
!PhoneticStringUtilities::NYSIISStringComparator methodsFor:'private'!
|
|
1005 |
|
|
1006 |
rule10:key
|
|
1007 |
"10. transcode 'PH' to 'F' "
|
|
1008 |
|
|
1009 |
^ self
|
|
1010 |
transcodeAll:'PH'
|
|
1011 |
of:key
|
|
1012 |
to:'F'
|
|
1013 |
startingAt:1
|
|
1014 |
!
|
|
1015 |
|
|
1016 |
rule11:key
|
|
1017 |
|k c|
|
|
1018 |
|
|
1019 |
"11. if not first character, eliminate all 'H' preceded or followed by a vowel "
|
|
1020 |
k := key copy.
|
|
1021 |
c := SortedCollection sortBlock:[:a :b | b < a ].
|
|
1022 |
2 to:key size do:[:i |
|
|
1023 |
(key at:i) = $H ifTrue:[
|
|
1024 |
((key at:i - 1) isVowel
|
|
1025 |
or:[ (i < key size) and:[ (key at:i + 1) isVowel ] ]) ifTrue:[ c add:i ]
|
|
1026 |
]
|
|
1027 |
].
|
|
1028 |
c do:[:n |
|
|
1029 |
k := (k copyFrom:1 to:n - 1) , (k copyFrom:n + 1 to:k size)
|
|
1030 |
].
|
|
1031 |
^ k
|
|
1032 |
!
|
|
1033 |
|
|
1034 |
rule12:key
|
|
1035 |
|k|
|
|
1036 |
|
|
1037 |
"12. change 'KN' to 'N', else 'K' to 'C' "
|
|
1038 |
k := self
|
|
1039 |
transcodeAll:'KN'
|
|
1040 |
of:key
|
|
1041 |
to:'K'
|
|
1042 |
startingAt:1.
|
|
1043 |
k := self
|
|
1044 |
transcodeAll:'K'
|
|
1045 |
of:k
|
|
1046 |
to:'C'
|
|
1047 |
startingAt:1.
|
|
1048 |
^ k
|
|
1049 |
!
|
|
1050 |
|
|
1051 |
rule13:key
|
|
1052 |
"13. if not first character, change 'M' to 'N' "
|
|
1053 |
|
|
1054 |
^ self
|
|
1055 |
transcodeAll:'M'
|
|
1056 |
of:key
|
|
1057 |
to:'N'
|
|
1058 |
startingAt:2
|
|
1059 |
!
|
|
1060 |
|
|
1061 |
rule14:key
|
|
1062 |
"14. if not first character, change 'Q' to 'G' "
|
|
1063 |
|
|
1064 |
^ self
|
|
1065 |
transcodeAll:'Q'
|
|
1066 |
of:key
|
|
1067 |
to:'G'
|
|
1068 |
startingAt:2
|
|
1069 |
!
|
|
1070 |
|
|
1071 |
rule15:key
|
|
1072 |
"15. transcode 'SH' to 'S' "
|
|
1073 |
|
|
1074 |
^ self
|
|
1075 |
transcodeAll:'SH'
|
|
1076 |
of:key
|
|
1077 |
to:'S'
|
|
1078 |
startingAt:1
|
|
1079 |
!
|
|
1080 |
|
|
1081 |
rule16:key
|
|
1082 |
"16. transcode 'SCH' to 'S' "
|
|
1083 |
|
|
1084 |
^ self
|
|
1085 |
transcodeAll:'SCH'
|
|
1086 |
of:key
|
|
1087 |
to:'S'
|
|
1088 |
startingAt:1
|
|
1089 |
!
|
|
1090 |
|
|
1091 |
rule17:key
|
|
1092 |
"17. transcode 'YW' to 'Y' "
|
|
1093 |
|
|
1094 |
^ self
|
|
1095 |
transcodeAll:'YW'
|
|
1096 |
of:key
|
|
1097 |
to:'Y'
|
|
1098 |
startingAt:1
|
|
1099 |
!
|
|
1100 |
|
|
1101 |
rule18:key
|
|
1102 |
|k|
|
|
1103 |
|
|
1104 |
"18. if not first or last character, change 'Y' to 'A' "
|
|
1105 |
k := self
|
|
1106 |
transcodeAll:'Y'
|
|
1107 |
of:key
|
|
1108 |
to:'A'
|
|
1109 |
startingAt:2.
|
|
1110 |
key last = $Y ifTrue:[
|
|
1111 |
k at:k size put:$Y
|
|
1112 |
].
|
|
1113 |
^ k
|
|
1114 |
!
|
|
1115 |
|
|
1116 |
rule19:key
|
|
1117 |
"19. transcode 'WR' to 'R' "
|
|
1118 |
|
|
1119 |
^ self
|
|
1120 |
transcodeAll:'WR'
|
|
1121 |
of:key
|
|
1122 |
to:'R'
|
|
1123 |
startingAt:1
|
|
1124 |
!
|
|
1125 |
|
|
1126 |
rule1:key
|
|
1127 |
|k|
|
|
1128 |
|
|
1129 |
k := key copy.
|
|
1130 |
"1. Remove all 'S' and 'Z' chars from the end of the name"
|
|
1131 |
[
|
|
1132 |
#( 'S' 'Z' ) includes:k last
|
|
1133 |
] whileTrue:[ k := k copyFrom:1 to:(k size - 1) ].
|
|
1134 |
^ k
|
|
1135 |
!
|
|
1136 |
|
|
1137 |
rule20:key
|
|
1138 |
"20. if not first character, change 'Z' to 'S' "
|
|
1139 |
|
|
1140 |
^ self
|
|
1141 |
transcodeAll:'Z'
|
|
1142 |
of:key
|
|
1143 |
to:'S'
|
|
1144 |
startingAt:2
|
|
1145 |
!
|
|
1146 |
|
|
1147 |
rule21:key
|
|
1148 |
"21. transcode terminal 'AY' to 'Y' "
|
|
1149 |
|
|
1150 |
^ self
|
|
1151 |
transcodeAll:'AY'
|
|
1152 |
of:key
|
|
1153 |
to:'Y'
|
|
1154 |
startingAt:key size - 1
|
|
1155 |
!
|
|
1156 |
|
|
1157 |
rule22:key
|
|
1158 |
|k|
|
|
1159 |
|
|
1160 |
"22. remove trailing vowels "
|
|
1161 |
k := key copy.
|
|
1162 |
[ k last isVowel ] whileTrue:[
|
|
1163 |
k := k copyFrom:1 to:k size - 1
|
|
1164 |
].
|
|
1165 |
^ k
|
|
1166 |
!
|
|
1167 |
|
|
1168 |
rule23:key
|
|
1169 |
|k c|
|
|
1170 |
|
|
1171 |
"23. collapse all strings of repeated characters "
|
|
1172 |
k := key copy.
|
|
1173 |
c := SortedCollection sortBlock:[:a :b | b < a ].
|
|
1174 |
k size to:2 do:[:i |
|
|
1175 |
(k at:i) = (k at:i - 1) ifTrue:[
|
|
1176 |
c add:i
|
|
1177 |
]
|
|
1178 |
].
|
|
1179 |
c do:[:n |
|
|
1180 |
k := (k copyFrom:1 to:n - 1) , (k copyFrom:n + 1 to:k size)
|
|
1181 |
].
|
|
1182 |
^ k
|
|
1183 |
!
|
|
1184 |
|
|
1185 |
rule24:key originalKey:originalKey
|
|
1186 |
|k|
|
|
1187 |
|
|
1188 |
"24. if first char of original surname was a vowel, append it to the code"
|
|
1189 |
k := key copy.
|
|
1190 |
originalKey first isVowel ifTrue:[
|
|
1191 |
k := k , originalKey first asString asUppercase
|
|
1192 |
].
|
|
1193 |
^ k
|
|
1194 |
!
|
|
1195 |
|
|
1196 |
rule2:key
|
|
1197 |
|k|
|
|
1198 |
|
|
1199 |
k := key copy.
|
|
1200 |
"2. Transcode initial strings: MAC => MC PF => F"
|
|
1201 |
(k copyFrom:1 to:3) = 'MAC' ifTrue:[
|
|
1202 |
k := 'MC' , (k copyFrom:4 to:k size)
|
|
1203 |
].
|
|
1204 |
(k copyFrom:1 to:2) = 'PF' ifTrue:[
|
|
1205 |
k := 'F' , (k copyFrom:3 to:k size)
|
|
1206 |
].
|
|
1207 |
^ k
|
|
1208 |
!
|
|
1209 |
|
|
1210 |
rule3:key
|
|
1211 |
|k|
|
|
1212 |
|
|
1213 |
"3. Transcode trailing strings as follows:
|
|
1214 |
IX => IC
|
|
1215 |
EX => EC
|
|
1216 |
YE, EE, IE => Y
|
|
1217 |
NT, ND => D"
|
|
1218 |
k := key copy.
|
|
1219 |
k := self
|
|
1220 |
transcodeTrailing:#( 'IX' )
|
|
1221 |
of:k
|
|
1222 |
to:'IC'.
|
|
1223 |
k := self
|
|
1224 |
transcodeTrailing:#( 'EX' )
|
|
1225 |
of:k
|
|
1226 |
to:'EC'.
|
|
1227 |
k := self
|
|
1228 |
transcodeTrailing:#( 'YE' 'EE' 'IE' )
|
|
1229 |
of:k
|
|
1230 |
to:'Y'.
|
|
1231 |
k := self
|
|
1232 |
transcodeTrailing:#( 'NT' 'ND' )
|
|
1233 |
of:k
|
|
1234 |
to:'D'.
|
|
1235 |
^ k
|
|
1236 |
!
|
|
1237 |
|
|
1238 |
rule4:key
|
|
1239 |
"4. Transcode 'EV' to 'EF' if not at start of name"
|
|
1240 |
|
|
1241 |
^ self
|
|
1242 |
transcodeAll:'EV'
|
|
1243 |
of:key
|
|
1244 |
to:'EF'
|
|
1245 |
startingAt:2
|
|
1246 |
!
|
|
1247 |
|
|
1248 |
rule5:key
|
|
1249 |
"5. Use first character of name as first character of key. Ignored because we're doing an in-place conversion"
|
|
1250 |
|
|
1251 |
^ key
|
|
1252 |
!
|
|
1253 |
|
|
1254 |
rule6:key
|
|
1255 |
|k i|
|
|
1256 |
|
|
1257 |
"6. Remove any 'W' that follows a vowel"
|
|
1258 |
k := key copy.
|
|
1259 |
i := 2.
|
|
1260 |
[
|
|
1261 |
(i := k indexOf:$W startingAt:i) > 0
|
|
1262 |
] whileTrue:[
|
|
1263 |
(k at:i - 1) isVowel ifTrue:[
|
|
1264 |
k := (k copyFrom:1 to:i - 1) , (k copyFrom:i + 1 to:k size).
|
|
1265 |
i := i - 1
|
|
1266 |
]
|
|
1267 |
].
|
|
1268 |
^ k
|
|
1269 |
!
|
|
1270 |
|
|
1271 |
rule7:key
|
|
1272 |
|k|
|
|
1273 |
|
|
1274 |
"7. replace all vowels with 'A' "
|
|
1275 |
k := key copy.
|
|
1276 |
1 to:key size do:[:i |
|
|
1277 |
(key at:i) isVowel ifTrue:[
|
|
1278 |
k at:i put:$A
|
|
1279 |
]
|
|
1280 |
].
|
|
1281 |
^ k
|
|
1282 |
!
|
|
1283 |
|
|
1284 |
rule8:key
|
|
1285 |
"8. transcode 'GHT' to 'GT' "
|
|
1286 |
|
|
1287 |
^ self
|
|
1288 |
transcodeAll:'GHT'
|
|
1289 |
of:key
|
|
1290 |
to:'GT'
|
|
1291 |
startingAt:1
|
|
1292 |
!
|
|
1293 |
|
|
1294 |
rule9:key
|
|
1295 |
"9. transcode 'DG' to 'G' "
|
|
1296 |
|
|
1297 |
^ self
|
|
1298 |
transcodeAll:'DG'
|
|
1299 |
of:key
|
|
1300 |
to:'G'
|
|
1301 |
startingAt:1
|
|
1302 |
!
|
|
1303 |
|
|
1304 |
transcodeAll:aString of:key to:replacementString startingAt:start
|
|
1305 |
|k i|
|
|
1306 |
|
|
1307 |
k := key copy.
|
|
1308 |
[
|
|
1309 |
(i := k indexOfSubCollection:aString startingAt:start) > 0
|
|
1310 |
] whileTrue:[
|
|
1311 |
k := (k copyFrom:1 to:i - 1) , replacementString
|
|
1312 |
, (k copyFrom:i + aString size to:k size)
|
|
1313 |
].
|
|
1314 |
^ k
|
|
1315 |
!
|
|
1316 |
|
|
1317 |
transcodeTrailing:anArrayOfStrings of:key to:replacementString
|
|
1318 |
|answer|
|
|
1319 |
|
|
1320 |
answer := key copy.
|
|
1321 |
anArrayOfStrings do:[:aString |
|
|
1322 |
answer := self
|
|
1323 |
transcodeAll:aString
|
|
1324 |
of:answer
|
|
1325 |
to:replacementString
|
|
1326 |
startingAt:(answer size - aString size) + 1
|
|
1327 |
].
|
|
1328 |
^ answer
|
|
1329 |
! !
|
|
1330 |
|
2211
|
1331 |
!PhoneticStringUtilities::PhonemStringComparator class methodsFor:'documentation'!
|
|
1332 |
|
|
1333 |
documentation
|
|
1334 |
"
|
|
1335 |
Implementation of the PHONEM algorithm, as described in
|
|
1336 |
'Georg Wilde and Carsten Meyer, Doppelgaenger gesucht -
|
|
1337 |
Ein Programm fuer kontextsensitive phonetische Textumwandlung
|
|
1338 |
ct Magazin fuer Computer & Technik 25/1998'
|
|
1339 |
"
|
|
1340 |
! !
|
|
1341 |
|
|
1342 |
!PhoneticStringUtilities::PhonemStringComparator methodsFor:'api'!
|
|
1343 |
|
|
1344 |
phoneticStringsFor:aString
|
|
1345 |
|s idx t t2|
|
|
1346 |
|
|
1347 |
s := aString asUppercase.
|
|
1348 |
|
|
1349 |
idx := 1.
|
|
1350 |
[idx < (s size-1)] whileTrue:[
|
|
1351 |
t2 := nil.
|
|
1352 |
t := s copyFrom:idx to:idx+1.
|
|
1353 |
t = 'SC' ifTrue:[ t2 := 'C' ]
|
|
1354 |
ifFalse:[ t = 'SZ' ifTrue:[ t2 := 'C' ]
|
|
1355 |
ifFalse:[ t = 'CZ' ifTrue:[ t2 := 'C' ]
|
|
1356 |
ifFalse:[ t = 'TZ' ifTrue:[ t2 := 'C' ]
|
|
1357 |
ifFalse:[ t = 'TS' ifTrue:[ t2 := 'C' ]
|
|
1358 |
ifFalse:[ t = 'KS' ifTrue:[ t2 := 'X' ]
|
|
1359 |
ifFalse:[ t = 'PF' ifTrue:[ t2 := 'V' ]
|
|
1360 |
ifFalse:[ t = 'QU' ifTrue:[ t2 := 'KW' ]
|
|
1361 |
ifFalse:[ t = 'PH' ifTrue:[ t2 := 'V' ]
|
|
1362 |
ifFalse:[ t = 'UE' ifTrue:[ t2 := 'Y' ]
|
|
1363 |
ifFalse:[ t = 'AE' ifTrue:[ t2 := 'E' ]
|
|
1364 |
ifFalse:[ t = 'OE' ifTrue:[ t2 := 'Ö' ]
|
|
1365 |
ifFalse:[ t = 'EI' ifTrue:[ t2 := 'AY' ]
|
|
1366 |
ifFalse:[ t = 'EY' ifTrue:[ t2 := 'AY' ]
|
|
1367 |
ifFalse:[ t = 'EU' ifTrue:[ t2 := 'OY' ]
|
|
1368 |
ifFalse:[ t = 'AU' ifTrue:[ t2 := 'A§' ]
|
|
1369 |
ifFalse:[ t = 'OU' ifTrue:[ t2 := '§ ' ]]]]]]]]]]]]]]]]].
|
|
1370 |
t2 notNil ifTrue:[
|
|
1371 |
s := (s copyTo:idx-1),t2,(s copyFrom:idx+2)
|
|
1372 |
] ifFalse:[
|
|
1373 |
idx := idx + 1.
|
|
1374 |
].
|
|
1375 |
].
|
|
1376 |
|
|
1377 |
"/ single character substitutions via tr
|
|
1378 |
s := s copyTransliterating:'ÖÄZKGQÜIJFWPT§' to:'YECCCCYYYVVDDUA'.
|
|
1379 |
s := s copyTransliterating:'ABCDLMNORSUVWXY' to:'' complement:true squashDuplicates:false.
|
|
1380 |
s := s copyTransliterating:'ABCDLMNORSUVWXY' to:'ABCDLMNORSUVWXY' complement:false squashDuplicates:true.
|
|
1381 |
^ Array with:s
|
|
1382 |
|
|
1383 |
"
|
|
1384 |
self basicNew phoneticStringsFor:'müller' #('MYLR')
|
|
1385 |
self basicNew phoneticStringsFor:'möller' #('MYLR')
|
|
1386 |
self basicNew phoneticStringsFor:'miller' #('MYLR')
|
|
1387 |
self basicNew phoneticStringsFor:'muller' #('MULR')
|
|
1388 |
self basicNew phoneticStringsFor:'muler' #('MULR')
|
|
1389 |
self basicNew phoneticStringsFor:'schmidt' #('CMYD')
|
|
1390 |
self basicNew phoneticStringsFor:'schneider' #('CNAYDR')
|
|
1391 |
self basicNew phoneticStringsFor:'fischer' #('VYCR')
|
|
1392 |
self basicNew phoneticStringsFor:'weber' #('VBR')
|
|
1393 |
self basicNew phoneticStringsFor:'meyer' #('MAYR')
|
|
1394 |
self basicNew phoneticStringsFor:'wagner' #('VACNR')
|
|
1395 |
self basicNew phoneticStringsFor:'schulz' #('CULC')
|
|
1396 |
self basicNew phoneticStringsFor:'becker' #('BCR')
|
|
1397 |
self basicNew phoneticStringsFor:'hoffmann' #('OVMAN')
|
|
1398 |
self basicNew phoneticStringsFor:'schäfer' #('CVR')
|
|
1399 |
"
|
|
1400 |
! !
|
|
1401 |
|
2208
|
1402 |
!PhoneticStringUtilities::DoubleMetaphoneStringComparator class methodsFor:'LICENSE'!
|
|
1403 |
|
2209
|
1404 |
copyright
|
|
1405 |
"
|
|
1406 |
Copyright (c) 2002-2004 Robert Jarvis
|
2208
|
1407 |
|
2209
|
1408 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
1409 |
files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use,
|
|
1410 |
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
|
|
1411 |
the Software is furnished to do so, subject to the following conditions:
|
|
1412 |
|
|
1413 |
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
1414 |
portions of the Software.
|
2208
|
1415 |
|
2209
|
1416 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
1417 |
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
1418 |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
1419 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
1420 |
USE OR OTHER DEALINGS IN THE SOFTWARE.'
|
|
1421 |
"
|
|
1422 |
! !
|
2208
|
1423 |
|
2213
|
1424 |
!PhoneticStringUtilities::DoubleMetaphoneStringComparator class methodsFor:'classification'!
|
|
1425 |
|
|
1426 |
isSlavoGermanic:aString
|
|
1427 |
^ #('w' 'k' 'cz' 'witz') contains:[:sub | aString includesString:sub]
|
|
1428 |
|
|
1429 |
"
|
|
1430 |
self isSlavoGermanic:'walter'
|
|
1431 |
"
|
|
1432 |
! !
|
|
1433 |
|
2209
|
1434 |
!PhoneticStringUtilities::DoubleMetaphoneStringComparator class methodsFor:'documentation'!
|
2208
|
1435 |
|
2209
|
1436 |
documentaion
|
|
1437 |
"
|
|
1438 |
The Double Metaphone algorithm:
|
|
1439 |
see internet
|
|
1440 |
"
|
2208
|
1441 |
! !
|
|
1442 |
|
|
1443 |
!PhoneticStringUtilities::DoubleMetaphoneStringComparator methodsFor:'accessing'!
|
|
1444 |
|
|
1445 |
currentIndex
|
|
1446 |
^currentIndex
|
|
1447 |
!
|
|
1448 |
|
|
1449 |
currentIndex: anInteger
|
|
1450 |
currentIndex := anInteger
|
|
1451 |
!
|
|
1452 |
|
|
1453 |
inputKey
|
|
1454 |
^inputKey
|
|
1455 |
!
|
|
1456 |
|
|
1457 |
inputKey: aString
|
|
1458 |
inputKey := aString asUppercase
|
|
1459 |
!
|
|
1460 |
|
|
1461 |
primaryTranslation
|
|
1462 |
^primaryTranslation
|
|
1463 |
!
|
|
1464 |
|
|
1465 |
primaryTranslation: anObject
|
|
1466 |
primaryTranslation := anObject
|
|
1467 |
!
|
|
1468 |
|
|
1469 |
secondaryTranslation
|
|
1470 |
^secondaryTranslation
|
|
1471 |
!
|
|
1472 |
|
|
1473 |
secondaryTranslation: anObject
|
|
1474 |
secondaryTranslation := anObject
|
|
1475 |
!
|
|
1476 |
|
|
1477 |
skipCount
|
|
1478 |
^skipCount
|
|
1479 |
!
|
|
1480 |
|
|
1481 |
skipCount: anInteger
|
|
1482 |
skipCount := anInteger
|
|
1483 |
!
|
|
1484 |
|
|
1485 |
startIndex
|
|
1486 |
^startIndex
|
|
1487 |
!
|
|
1488 |
|
|
1489 |
startIndex: anObject
|
|
1490 |
startIndex := anObject
|
|
1491 |
! !
|
|
1492 |
|
|
1493 |
!PhoneticStringUtilities::DoubleMetaphoneStringComparator methodsFor:'api'!
|
|
1494 |
|
|
1495 |
phoneticStringsFor: aString
|
|
1496 |
"Private - Answers an array of alternate phonetic strings for the given input string."
|
|
1497 |
|
|
1498 |
self inputKey: aString.
|
|
1499 |
self performInitialProcessing.
|
|
1500 |
self processRemainingCharacters.
|
|
1501 |
|
2209
|
1502 |
^ Array with: primaryTranslation with: secondaryTranslation
|
2208
|
1503 |
! !
|
|
1504 |
|
|
1505 |
!PhoneticStringUtilities::DoubleMetaphoneStringComparator methodsFor:'initialization'!
|
|
1506 |
|
|
1507 |
initialize
|
|
1508 |
super initialize.
|
|
1509 |
|
|
1510 |
self
|
|
1511 |
startIndex: 1;
|
|
1512 |
primaryTranslation: '';
|
|
1513 |
secondaryTranslation: '';
|
|
1514 |
skipCount: 0;
|
|
1515 |
currentIndex: 1
|
|
1516 |
! !
|
|
1517 |
|
|
1518 |
!PhoneticStringUtilities::DoubleMetaphoneStringComparator methodsFor:'private'!
|
|
1519 |
|
|
1520 |
addPrimaryTranslation: aString
|
|
1521 |
self primaryTranslation: self primaryTranslation, aString
|
|
1522 |
!
|
|
1523 |
|
|
1524 |
addSecondaryTranslation: aString
|
|
1525 |
self secondaryTranslation: self secondaryTranslation, aString
|
|
1526 |
!
|
|
1527 |
|
|
1528 |
decrementSkipCount
|
|
1529 |
self skipCount: self skipCount - 1
|
|
1530 |
!
|
|
1531 |
|
|
1532 |
incrementSkipCount
|
|
1533 |
self incrementSkipCount: 1
|
|
1534 |
!
|
|
1535 |
|
|
1536 |
incrementSkipCount: anInteger
|
|
1537 |
self skipCount: self skipCount + anInteger
|
|
1538 |
!
|
|
1539 |
|
|
1540 |
incrementStartIndex
|
|
1541 |
self startIndex: self startIndex + 1
|
|
1542 |
!
|
|
1543 |
|
|
1544 |
isSlavoGermanic: aString
|
|
1545 |
^((aString includesAnyOf: 'WK') or:
|
|
1546 |
[ (aString indexOfSubCollection: 'CZ' startingAt: 1) >= 1 ]) or:
|
|
1547 |
[ (aString indexOfSubCollection: 'WITZ' startingAt: 1) >= 1 ]
|
|
1548 |
!
|
|
1549 |
|
|
1550 |
keyAt: anInteger
|
|
1551 |
(anInteger >=1 and: [ anInteger <= self inputKey size ])
|
|
1552 |
ifTrue: [ ^self inputKey at: anInteger ]
|
|
1553 |
ifFalse: [ ^$ ]
|
|
1554 |
!
|
|
1555 |
|
|
1556 |
keyLeftString: lengthInteger
|
|
1557 |
^self keyMidString: lengthInteger from: 1
|
|
1558 |
!
|
|
1559 |
|
|
1560 |
keyMidString: lengthInteger from: fromInteger
|
|
1561 |
| result from len additionalSpaces |
|
|
1562 |
|
|
1563 |
result := ''.
|
|
1564 |
from := fromInteger.
|
|
1565 |
len := lengthInteger.
|
|
1566 |
|
|
1567 |
"Prepend spaces if caller is requesting characters from before the start of the string"
|
|
1568 |
|
|
1569 |
[ from < 1 ] whileTrue:
|
|
1570 |
[ result := result, ' '.
|
|
1571 |
from := from + 1.
|
|
1572 |
len := len - 1 ].
|
|
1573 |
|
|
1574 |
from + len - 1 > self inputKey size
|
|
1575 |
ifTrue:
|
|
1576 |
[ additionalSpaces := from + len - 1 - self inputKey size.
|
|
1577 |
len := self inputKey size - from + 1 ]
|
|
1578 |
ifFalse: [ additionalSpaces := 0 ].
|
|
1579 |
|
|
1580 |
result := result, (self inputKey copyFrom: from to: (from+len-1 min: self inputKey size)).
|
|
1581 |
|
|
1582 |
[ additionalSpaces > 0 ] whileTrue:
|
|
1583 |
[ result := result, ' '.
|
|
1584 |
additionalSpaces := additionalSpaces - 1 ].
|
|
1585 |
|
|
1586 |
^result
|
|
1587 |
!
|
|
1588 |
|
|
1589 |
keyRightString: lengthInteger
|
|
1590 |
^self keyMidString: lengthInteger from: self inputKey size - lengthInteger + 1
|
|
1591 |
!
|
|
1592 |
|
|
1593 |
performInitialProcessing
|
|
1594 |
(#('GN' 'KN' 'PN' 'WR' 'PS') includes: (self inputKey copyFrom: 1 to: 2))
|
|
1595 |
ifTrue: [ self incrementStartIndex ].
|
|
1596 |
|
|
1597 |
(self keyAt: 1) = $X
|
|
1598 |
ifTrue:
|
|
1599 |
[ self
|
|
1600 |
addPrimaryTranslation: 'S';
|
|
1601 |
addSecondaryTranslation: 'S'.
|
|
1602 |
self incrementStartIndex ].
|
|
1603 |
|
|
1604 |
(self keyAt: 1) isVowel
|
|
1605 |
ifTrue:
|
|
1606 |
[ self
|
|
1607 |
addPrimaryTranslation: 'A';
|
|
1608 |
addSecondaryTranslation: 'A'.
|
|
1609 |
self incrementStartIndex ]
|
|
1610 |
!
|
|
1611 |
|
|
1612 |
processB
|
2213
|
1613 |
self
|
|
1614 |
addPrimaryTranslation: 'P';
|
|
1615 |
addSecondaryTranslation: 'P'.
|
|
1616 |
(self keyAt: (currentIndex + 1)) = $B
|
|
1617 |
ifTrue: [ self incrementSkipCount ].
|
2208
|
1618 |
!
|
|
1619 |
|
|
1620 |
processC
|
2213
|
1621 |
"i"
|
|
1622 |
((((currentIndex >= 3
|
|
1623 |
and: [ (self keyAt: currentIndex-2) isVowel not ])
|
|
1624 |
and: [ (self keyMidString: 3 from: currentIndex-1) = 'ACH' ])
|
|
1625 |
and: [ (self keyAt: currentIndex+2) ~= $I ])
|
|
1626 |
and: [ ((self keyAt: currentIndex+2) ~= $E)
|
|
1627 |
or: [ (self keyMidString: 6 from: currentIndex-2) ~= 'BACHER'
|
|
1628 |
and: [ (self keyMidString: 6 from: currentIndex-2) ~= 'MACHER' ] ] ])
|
|
1629 |
ifTrue:
|
|
1630 |
[ self addPrimaryTranslation: 'K'.
|
|
1631 |
self addSecondaryTranslation: 'K'.
|
|
1632 |
self incrementSkipCount: 2.
|
|
1633 |
^self ].
|
|
1634 |
|
|
1635 |
"ii"
|
|
1636 |
(self inputKey beginsWith: 'CAESAR')
|
|
1637 |
ifTrue:
|
|
1638 |
[ self addPrimaryTranslation: 'S'.
|
|
1639 |
self addSecondaryTranslation: 'S'.
|
|
1640 |
self incrementSkipCount: 1.
|
|
1641 |
^self ].
|
|
1642 |
|
|
1643 |
"iii"
|
|
1644 |
(self keyMidString: 4 from: currentIndex) = 'CHIA'
|
|
1645 |
ifTrue:
|
|
1646 |
[ self addPrimaryTranslation: 'K'.
|
|
1647 |
self addSecondaryTranslation: 'K'.
|
|
1648 |
self incrementSkipCount: 1.
|
|
1649 |
^self ].
|
|
1650 |
|
|
1651 |
"iv"
|
|
1652 |
(self keyMidString: 2 from: currentIndex) = 'CH'
|
|
1653 |
ifTrue:
|
|
1654 |
[ (currentIndex > 1 "a"
|
|
1655 |
and: [ (self keyMidString: 4 from: currentIndex) = 'CHAE' ])
|
|
1656 |
ifTrue: [ self
|
|
1657 |
addPrimaryTranslation: 'K';
|
|
1658 |
addSecondaryTranslation: 'X';
|
|
1659 |
incrementSkipCount: 1.
|
|
1660 |
^self ].
|
|
1661 |
|
|
1662 |
(currentIndex = 1 "b"
|
|
1663 |
and: [ (self inputKey size > 5 and: [(self inputKey copyFrom: 1 to: 6) = 'CHARAC'
|
|
1664 |
or: [ (self inputKey copyFrom: 1 to: 6) = 'CHARIS' ]] )
|
|
1665 |
or: [self inputKey size > 4 and: [ ((((self inputKey copyFrom: 1 to: 4) = 'CHOR'
|
|
1666 |
or: [ (self inputKey copyFrom: 1 to: 4) = 'CHYM' ])
|
|
1667 |
or: [ (self inputKey copyFrom: 1 to: 4) = 'CHIA' ])
|
|
1668 |
or: [ (self inputKey copyFrom: 1 to: 4) = 'CHEM' ])
|
|
1669 |
and: [ (self inputKey copyFrom: 1 to: 4) ~= 'CHORE' ] ] ] ])
|
|
1670 |
ifTrue: [ self
|
|
1671 |
addPrimaryTranslation: 'K';
|
|
1672 |
addSecondaryTranslation: 'K';
|
|
1673 |
incrementSkipCount: 1.
|
|
1674 |
^self ].
|
|
1675 |
|
|
1676 |
(((((#('VAN ' 'VON ') includes: (self inputKey copyFrom: 1 to: 4)) "c"
|
|
1677 |
or: [ (self inputKey copyFrom: 1 to: 3) = 'SCH' ])
|
|
1678 |
or: [ #('ORCHES' 'ARCHIT' 'ORCHID')
|
|
1679 |
includes: (self keyMidString: 6 from: currentIndex-2) ])
|
|
1680 |
or: [ #($T $S) includes: (self keyAt: currentIndex+2) ])
|
|
1681 |
or: [ ((currentIndex = 1)
|
|
1682 |
or: [ #($A $O $U $E) includes: (self keyAt: currentIndex-1) ])
|
|
1683 |
and: [ #($L $R $N $M $B $H $F $V $W $ ) includes: (self keyAt: currentIndex+2) ] ] )
|
|
1684 |
ifTrue:
|
|
1685 |
[ self
|
|
1686 |
addPrimaryTranslation: 'K';
|
|
1687 |
addSecondaryTranslation: 'K';
|
|
1688 |
incrementSkipCount: 1.
|
|
1689 |
^self ]
|
|
1690 |
ifFalse:
|
|
1691 |
[ currentIndex > 1
|
|
1692 |
ifTrue:
|
|
1693 |
[ (self inputKey copyFrom: 1 to: 2) = 'MC'
|
|
1694 |
ifTrue:
|
|
1695 |
[ self
|
|
1696 |
addPrimaryTranslation: 'K';
|
|
1697 |
addSecondaryTranslation: 'K' ]
|
|
1698 |
ifFalse:
|
|
1699 |
[ self
|
|
1700 |
addPrimaryTranslation: 'X';
|
|
1701 |
addSecondaryTranslation: 'K' ] ]
|
|
1702 |
ifFalse:
|
|
1703 |
[ self
|
|
1704 |
addPrimaryTranslation: 'X';
|
|
1705 |
addSecondaryTranslation: 'X' ].
|
|
1706 |
self incrementSkipCount: 1.
|
|
1707 |
^self ] ].
|
|
1708 |
|
|
1709 |
"v"
|
|
1710 |
(self keyAt: currentIndex+1) = $Z
|
|
1711 |
ifTrue:
|
|
1712 |
[ self
|
|
1713 |
addPrimaryTranslation: 'S';
|
|
1714 |
addSecondaryTranslation: 'X';
|
|
1715 |
incrementSkipCount: 1.
|
|
1716 |
^self ].
|
|
1717 |
|
|
1718 |
"vi"
|
|
1719 |
(self keyMidString: 3 from: currentIndex+1) = 'CIA'
|
|
1720 |
ifTrue:
|
|
1721 |
[ self
|
|
1722 |
addPrimaryTranslation: 'X';
|
|
1723 |
addSecondaryTranslation: 'X';
|
|
1724 |
incrementSkipCount: 2.
|
|
1725 |
^self ].
|
|
1726 |
|
|
1727 |
"vii"
|
|
1728 |
((self keyAt: currentIndex+1) = $C
|
|
1729 |
and: [ ((currentIndex = 2)
|
|
1730 |
and: [ (self keyAt: 1) = $M ]) not ])
|
|
1731 |
ifTrue:
|
|
1732 |
[ ((#($I $E $H) includes: (self keyAt: currentIndex+2))
|
|
1733 |
and: [ (self keyMidString: 2 from: currentIndex+2) ~= 'HU' ])
|
|
1734 |
ifTrue:
|
|
1735 |
[ ((currentIndex = 2 and: [ (self keyAt: 1) = $A ])
|
|
1736 |
or: [ #('UCCEE' 'UCCES') includes: (self keyMidString: 5 from: currentIndex-1)])
|
|
1737 |
ifTrue:
|
|
1738 |
[self
|
|
1739 |
addPrimaryTranslation: 'KS';
|
|
1740 |
addSecondaryTranslation: 'KS';
|
|
1741 |
incrementSkipCount: 2.
|
|
1742 |
^self ]
|
|
1743 |
ifFalse:
|
|
1744 |
[self
|
|
1745 |
addPrimaryTranslation: 'X';
|
|
1746 |
addSecondaryTranslation: 'X';
|
|
1747 |
incrementSkipCount: 2.
|
|
1748 |
^self ] ]
|
|
1749 |
ifFalse:
|
|
1750 |
[ self
|
|
1751 |
addPrimaryTranslation: 'K';
|
|
1752 |
addSecondaryTranslation: 'K';
|
|
1753 |
incrementSkipCount: 2.
|
|
1754 |
^self ] ].
|
|
1755 |
|
|
1756 |
"viii"
|
|
1757 |
(#($K $G $Q) includes: (self keyAt: currentIndex+1))
|
|
1758 |
ifTrue:
|
|
1759 |
[ self
|
|
1760 |
addPrimaryTranslation: 'K';
|
|
1761 |
addSecondaryTranslation: 'K';
|
|
1762 |
incrementSkipCount: 1.
|
|
1763 |
^self ].
|
|
1764 |
|
|
1765 |
"ix"
|
|
1766 |
(#($I $E $Y) includes: (self keyAt: currentIndex+1))
|
|
1767 |
ifTrue:
|
|
1768 |
[ (#('CIO' 'CIE' 'CIA') includes: (self keyMidString: 3 from: currentIndex))
|
|
1769 |
ifTrue:
|
|
1770 |
[self
|
|
1771 |
addPrimaryTranslation: 'S';
|
|
1772 |
addSecondaryTranslation: 'X' ]
|
|
1773 |
ifFalse:
|
|
1774 |
[self
|
|
1775 |
addPrimaryTranslation: 'S';
|
|
1776 |
addSecondaryTranslation: 'S'].
|
|
1777 |
self incrementSkipCount: 1.
|
|
1778 |
^self ].
|
|
1779 |
|
|
1780 |
"x"
|
|
1781 |
self
|
|
1782 |
addPrimaryTranslation: 'K';
|
|
1783 |
addSecondaryTranslation: 'K'.
|
|
1784 |
|
|
1785 |
"xi"
|
|
1786 |
(#(' C' ' Q' ' G') includes: (self keyMidString: 2 from: currentIndex+1))
|
|
1787 |
ifTrue:
|
|
1788 |
[ self incrementSkipCount: 2 ]
|
|
1789 |
ifFalse:
|
|
1790 |
[ ((#($C $K $Q) includes: (self keyAt: currentIndex+1))
|
|
1791 |
and: [ (#('CE' 'CI') includes: (self keyMidString: 2 from: currentIndex+1)) not ])
|
|
1792 |
ifTrue: [ self incrementSkipCount: 1] ]
|
2208
|
1793 |
!
|
|
1794 |
|
|
1795 |
processCedille
|
|
1796 |
self
|
|
1797 |
addPrimaryTranslation: 'S';
|
|
1798 |
addSecondaryTranslation: 'S'
|
|
1799 |
!
|
|
1800 |
|
|
1801 |
processD
|
2213
|
1802 |
"i"
|
|
1803 |
(self keyAt: currentIndex+1) = $G
|
|
1804 |
ifTrue:
|
|
1805 |
[ (#($I $E $Y) includes: (self keyAt: currentIndex+2))
|
|
1806 |
ifTrue:
|
|
1807 |
[ self
|
|
1808 |
addPrimaryTranslation: 'J';
|
|
1809 |
addSecondaryTranslation: 'J';
|
|
1810 |
incrementSkipCount: 2.
|
|
1811 |
^self ]
|
|
1812 |
ifFalse:
|
|
1813 |
[ self
|
|
1814 |
addPrimaryTranslation: 'TK';
|
|
1815 |
addSecondaryTranslation: 'TK';
|
|
1816 |
incrementSkipCount: 1.
|
|
1817 |
^self ] ].
|
|
1818 |
|
|
1819 |
"ii"
|
|
1820 |
(#($T $D) includes: (self keyAt: currentIndex+1))
|
|
1821 |
ifTrue:
|
|
1822 |
[ self
|
|
1823 |
addPrimaryTranslation: 'T';
|
|
1824 |
addSecondaryTranslation: 'T';
|
|
1825 |
incrementSkipCount: 1.
|
|
1826 |
^self ].
|
|
1827 |
|
|
1828 |
"iii"
|
|
1829 |
self
|
|
1830 |
addPrimaryTranslation: 'T';
|
|
1831 |
addSecondaryTranslation: 'T'
|
2208
|
1832 |
!
|
|
1833 |
|
|
1834 |
processF
|
|
1835 |
self
|
|
1836 |
addPrimaryTranslation: 'F';
|
|
1837 |
addSecondaryTranslation: 'F'.
|
|
1838 |
(self keyAt: self currentIndex+1) = $F
|
|
1839 |
ifTrue: [ self incrementSkipCount: 1 ]
|
|
1840 |
!
|
|
1841 |
|
|
1842 |
processG
|
|
1843 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
1844 |
case 'G':
|
|
1845 |
if(GetAt(current + 1) == 'H')
|
|
1846 |
{"
|
|
1847 |
| word |
|
2213
|
1848 |
(self keyAt: currentIndex + 1) = $H
|
2208
|
1849 |
ifTrue: [
|
|
1850 |
"if((current > 0) AND !!IsVowel(current - 1))"
|
|
1851 |
|
2213
|
1852 |
(currentIndex > 1 and: [(self keyAt: currentIndex - 1) isVowel not])
|
2208
|
1853 |
ifTrue: [
|
|
1854 |
" {
|
|
1855 |
MetaphAdd(K);
|
|
1856 |
current += 2;
|
|
1857 |
break;
|
|
1858 |
}"
|
|
1859 |
|
|
1860 |
self addPrimaryTranslation: 'K';
|
|
1861 |
addSecondaryTranslation: 'K'.
|
|
1862 |
^self incrementSkipCount: 1
|
|
1863 |
].
|
|
1864 |
|
|
1865 |
"if(current < 3)
|
|
1866 |
{"
|
|
1867 |
|
|
1868 |
currentIndex < 4
|
|
1869 |
ifTrue: [
|
|
1870 |
|
|
1871 |
" //'ghislane', ghiradelli
|
|
1872 |
if(current == 0)
|
|
1873 |
{ "
|
|
1874 |
currentIndex = 1
|
|
1875 |
ifTrue: [
|
|
1876 |
"if(GetAt(current + 2) == 'I')"
|
|
1877 |
|
2213
|
1878 |
(self keyAt: currentIndex + 2) = $I
|
2208
|
1879 |
ifTrue: [
|
|
1880 |
"MetaphAdd(J);"
|
|
1881 |
self addPrimaryTranslation: 'J';
|
|
1882 |
addSecondaryTranslation: 'J'.
|
|
1883 |
] ifFalse: [
|
|
1884 |
"MetaphAdd(K);"
|
|
1885 |
self addPrimaryTranslation: 'K';
|
|
1886 |
addSecondaryTranslation: 'K'.
|
|
1887 |
].
|
|
1888 |
" current += 2;
|
|
1889 |
break;"
|
|
1890 |
^self incrementSkipCount: 1
|
|
1891 |
]
|
|
1892 |
].
|
|
1893 |
|
|
1894 |
" //Parker's rule (with some further refinements) - e.g., 'hugh'
|
|
1895 |
if(((current > 1) AND StringAt((current - 2), 1, B, H, D, ) )
|
|
1896 |
//e.g., 'bough'
|
|
1897 |
OR ((current > 2) AND StringAt((current - 3), 1, B, H, D, ) )
|
|
1898 |
//e.g., 'broughton'
|
|
1899 |
OR ((current > 3) AND StringAt((current - 4), 1, B, H, ) ) )
|
|
1900 |
"
|
2213
|
1901 |
(((currentIndex > 2 and: [#($B $H $D) includes: (self keyAt: currentIndex - 2)])
|
|
1902 |
or: [currentIndex > 3 and: [#($B $H $D) includes: (self keyAt: currentIndex - 3)]])
|
|
1903 |
or: [currentIndex > 4 and: [#($B $H) includes: (self keyAt: currentIndex - 4)]])
|
2208
|
1904 |
ifTrue: [
|
|
1905 |
"current += 2;
|
|
1906 |
break;"
|
|
1907 |
^self incrementSkipCount: 1
|
|
1908 |
] ifFalse: [
|
|
1909 |
" //e.g., 'laugh', 'McLaughlin', 'cough', 'gough', 'rough', 'tough'
|
|
1910 |
if((current > 2)
|
|
1911 |
AND (GetAt(current - 1) == 'U')
|
|
1912 |
AND StringAt((current - 3), 1, C, G, L, R, T, ) )"
|
|
1913 |
(currentIndex > 3 and: [
|
2213
|
1914 |
((self keyAt: currentIndex - 1) = $U) and: [
|
|
1915 |
#($C $G $L $R $T) includes: (self keyAt: currentIndex - 3)
|
2208
|
1916 |
]
|
|
1917 |
]) ifTrue: [
|
|
1918 |
"MetaphAdd(F);"
|
|
1919 |
self addPrimaryTranslation: 'F';
|
|
1920 |
addSecondaryTranslation: 'F'.
|
|
1921 |
] ifFalse: [
|
|
1922 |
" if((current > 0) AND GetAt(current - 1) !!= 'I')
|
|
1923 |
MetaphAdd(K);"
|
2213
|
1924 |
(currentIndex > 1 and: [(self keyAt: currentIndex - 1) ~= $I])
|
2208
|
1925 |
ifTrue: [
|
|
1926 |
self addPrimaryTranslation: 'K';
|
|
1927 |
addSecondaryTranslation: 'K'.
|
|
1928 |
].
|
|
1929 |
].
|
|
1930 |
^self incrementSkipCount: 1
|
|
1931 |
].
|
|
1932 |
].
|
|
1933 |
"if(GetAt(current + 1) == 'N')"
|
2213
|
1934 |
(self keyAt: currentIndex + 1) = $N
|
2208
|
1935 |
ifTrue: [
|
|
1936 |
"if((current == 1) AND IsVowel(0) AND !!SlavoGermanic())"
|
|
1937 |
(currentIndex = 2 and: [(self inputKey at: 1) isVowel and: [(self isSlavoGermanic: self inputKey) not]])
|
|
1938 |
ifTrue: [
|
|
1939 |
"MetaphAdd(KN, N);"
|
|
1940 |
self addPrimaryTranslation: 'KN';
|
|
1941 |
addSecondaryTranslation: 'N'.
|
|
1942 |
] ifFalse: [
|
|
1943 |
" //not e.g. 'cagney'
|
|
1944 |
if(!!StringAt((current + 2), 2, EY, )
|
|
1945 |
AND (GetAt(current + 1) !!= 'Y')
|
|
1946 |
AND !!SlavoGermanic())"
|
2213
|
1947 |
((self inputKey size >= (currentIndex + 2)) and: [
|
|
1948 |
(self inputKey copyFrom: currentIndex + 2 to: (currentIndex + 4 min: self inputKey size)) ~= 'EY' and: [
|
|
1949 |
(self keyAt: currentIndex + 1) ~= $Y and: [
|
2208
|
1950 |
(self isSlavoGermanic: self inputKey) not
|
|
1951 |
]
|
|
1952 |
]
|
|
1953 |
]) ifTrue: [
|
|
1954 |
self addPrimaryTranslation: 'N';
|
|
1955 |
addSecondaryTranslation: 'KN'.
|
|
1956 |
] ifFalse: [
|
|
1957 |
self addPrimaryTranslation: 'KN';
|
|
1958 |
addSecondaryTranslation: 'KN'.
|
|
1959 |
].
|
|
1960 |
].
|
|
1961 |
^self incrementSkipCount: 1
|
|
1962 |
].
|
|
1963 |
" //'tagliaro'
|
|
1964 |
if(StringAt((current + 1), 2, LI, ) AND !!SlavoGermanic())"
|
2213
|
1965 |
((self inputKey size >= (currentIndex + 3)) and: [
|
|
1966 |
(self inputKey copyFrom: currentIndex + 1 to: currentIndex + 2) = 'LI' and: [
|
2208
|
1967 |
(self isSlavoGermanic: self inputKey) not]])
|
|
1968 |
ifTrue: [
|
|
1969 |
self addPrimaryTranslation: 'KL';
|
|
1970 |
addSecondaryTranslation: 'L'.
|
|
1971 |
^self incrementSkipCount: 1.
|
|
1972 |
].
|
|
1973 |
" //-ges-,-gep-,-gel-, -gie- at beginning
|
|
1974 |
if((current == 0)
|
|
1975 |
AND ((GetAt(current + 1) == 'Y')
|
|
1976 |
OR StringAt((current + 1), 2, ES, EP, EB, EL, EY, IB, IL, IN, IE, EI, ER, )) )"
|
2213
|
1977 |
(currentIndex = 1 and: [
|
|
1978 |
((self keyAt: currentIndex + 1) = $Y) or: [
|
2208
|
1979 |
(#('ES' 'EP' 'EB' 'EL' 'EY' 'IB' 'IL' 'IN' 'IE' 'EI' 'ER') includes:
|
2213
|
1980 |
(self inputKey copyFrom: currentIndex + 1 to: currentIndex + 2))
|
2208
|
1981 |
]]) ifTrue: [
|
|
1982 |
self addPrimaryTranslation: 'K';
|
|
1983 |
addSecondaryTranslation: 'J'.
|
|
1984 |
^self incrementSkipCount: 1.
|
|
1985 |
].
|
|
1986 |
" // -ger-, -gy-
|
|
1987 |
if((StringAt((current + 1), 2, ER, ) OR (GetAt(current + 1) == 'Y'))
|
|
1988 |
AND !!StringAt(0, 6, DANGER, RANGER, MANGER, )
|
|
1989 |
AND !!StringAt((current - 1), 1, E, I, )
|
|
1990 |
AND !!StringAt((current - 1), 3, RGY, OGY, ) )
|
|
1991 |
"
|
2213
|
1992 |
(((self inputKey copyFrom: currentIndex + 1 to: (currentIndex + 3 min: self inputKey size)) = 'ER' or: [
|
|
1993 |
((self keyAt: currentIndex + 1) = $Y)])
|
2208
|
1994 |
and: [((#('DANGER' 'RANGER' 'MANGER') includes: (word := self inputKey copyFrom: 1 to: (6 min: self inputKey size))) not)
|
2213
|
1995 |
and: [(self keyAt: currentIndex - 1) ~= $E
|
|
1996 |
and: [(#('RGY' 'OGY') includes: (self inputKey copyFrom: currentIndex - 1 to: currentIndex + 1)) not]]])
|
2208
|
1997 |
ifTrue: [
|
|
1998 |
self addPrimaryTranslation: 'K';
|
|
1999 |
addSecondaryTranslation: 'J'.
|
|
2000 |
^self incrementSkipCount: 1.
|
|
2001 |
].
|
|
2002 |
|
|
2003 |
" // italian e.g, 'biaggi'
|
|
2004 |
if(StringAt((current + 1), 1, E, I, Y, ) OR StringAt((current - 1), 4, AGGI, OGGI, ))
|
|
2005 |
"
|
2213
|
2006 |
((#($E $I $Y) includes: (self keyAt: (currentIndex + 1))) or: [(#('AGGI' 'OGGI') includes: (self inputKey copyFrom: currentIndex - 1 to: (currentIndex + 2 min: self inputKey size)))])
|
2208
|
2007 |
ifTrue: [
|
|
2008 |
" //obvious germanic
|
|
2009 |
if((StringAt(0, 4, VAN , VON , ) OR StringAt(0, 3, SCH, ))
|
|
2010 |
OR StringAt((current + 1), 2, ET, )) MetaphAdd(K);"
|
|
2011 |
word := (self inputKey copyFrom: 1 to: 4).
|
|
2012 |
((#('VAN ' 'VON ') includes: word) or: [(word copyFrom: 1 to: 3) = 'SCH' or: [(word copyFrom: 1 to: 2) = 'ET']])
|
|
2013 |
ifTrue: [
|
|
2014 |
self addPrimaryTranslation: 'K';
|
|
2015 |
addSecondaryTranslation: 'K'.
|
|
2016 |
] ifFalse: [
|
|
2017 |
" //always soft if french ending
|
|
2018 |
if(StringAt((current + 1), 4, IER , ))
|
|
2019 |
MetaphAdd(J);
|
|
2020 |
else
|
|
2021 |
MetaphAdd(J, K);
|
|
2022 |
current += 2;
|
|
2023 |
break;"
|
2213
|
2024 |
(((self inputKey copyFrom: currentIndex + 1 to: (currentIndex + 5 min: self inputKey size)), ' ') copyFrom: 1 to: 4) = 'IER '
|
2208
|
2025 |
ifTrue: [
|
|
2026 |
self addPrimaryTranslation: 'J';
|
|
2027 |
addSecondaryTranslation: 'J'.
|
|
2028 |
] ifFalse: [
|
|
2029 |
self addPrimaryTranslation: 'J';
|
|
2030 |
addSecondaryTranslation: 'K'.
|
|
2031 |
].
|
|
2032 |
|
|
2033 |
].
|
|
2034 |
^self incrementSkipCount: 1.
|
|
2035 |
].
|
|
2036 |
|
|
2037 |
" if(GetAt(current + 1) == 'G')
|
|
2038 |
current += 2;
|
|
2039 |
else
|
|
2040 |
current += 1;
|
|
2041 |
MetaphAdd(K);
|
|
2042 |
break;"
|
|
2043 |
|
2213
|
2044 |
(self keyAt: (currentIndex + 1)) = $G
|
2208
|
2045 |
ifTrue: [
|
|
2046 |
self incrementSkipCount: 1.
|
|
2047 |
].
|
|
2048 |
self addPrimaryTranslation: 'K';
|
|
2049 |
addSecondaryTranslation: 'K'.
|
|
2050 |
!
|
|
2051 |
|
|
2052 |
processH
|
2213
|
2053 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2054 |
case 'H':
|
2208
|
2055 |
//only keep if first & before vowel or btw. 2 vowels
|
|
2056 |
if(((current == 0) OR IsVowel(current - 1))
|
|
2057 |
AND IsVowel(current + 1))
|
|
2058 |
{
|
|
2059 |
MetaphAdd(H);
|
|
2060 |
current += 2;
|
|
2061 |
}else//also takes care of 'HH'
|
|
2062 |
current += 1;
|
|
2063 |
break;
|
|
2064 |
"
|
|
2065 |
|
2213
|
2066 |
(((currentIndex = 1)
|
|
2067 |
or: [ (self keyAt: currentIndex - 1) isVowel])
|
|
2068 |
and: [(self keyAt: currentIndex + 1) isVowel])
|
|
2069 |
ifTrue: [
|
|
2070 |
self addPrimaryTranslation: 'H';
|
|
2071 |
addSecondaryTranslation: 'H'.
|
|
2072 |
^self incrementSkipCount: 1.
|
|
2073 |
]
|
2208
|
2074 |
!
|
|
2075 |
|
|
2076 |
processJ
|
2213
|
2077 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2078 |
case 'J':
|
2208
|
2079 |
//obvious spanish, 'jose', 'san jacinto'
|
|
2080 |
if(StringAt(current, 4, JOSE, ) OR StringAt(0, 4, SAN , ) )
|
|
2081 |
{
|
|
2082 |
if(((current == 0) AND (GetAt(current + 4) == ' ')) OR StringAt(0, 4, SAN , ) )
|
|
2083 |
MetaphAdd(H);
|
|
2084 |
else
|
|
2085 |
{
|
|
2086 |
MetaphAdd(J, H);
|
|
2087 |
}
|
|
2088 |
current +=1;
|
|
2089 |
break;
|
|
2090 |
}
|
|
2091 |
|
|
2092 |
if((current == 0) AND !!StringAt(current, 4, JOSE, ))
|
|
2093 |
MetaphAdd(J, A);//Yankelovich/Jankelowicz
|
|
2094 |
else
|
|
2095 |
//spanish pron. of e.g. 'bajador'
|
|
2096 |
if(IsVowel(current - 1)
|
|
2097 |
AND !!SlavoGermanic()
|
|
2098 |
AND ((GetAt(current + 1) == 'A') OR (GetAt(current + 1) == 'O')))
|
|
2099 |
MetaphAdd(J, H);
|
|
2100 |
else
|
|
2101 |
if(current == last)
|
|
2102 |
MetaphAdd(J, );
|
|
2103 |
else
|
|
2104 |
if(!!StringAt((current + 1), 1, L, T, K, S, N, M, B, Z, )
|
|
2105 |
AND !!StringAt((current - 1), 1, S, K, L, ))
|
|
2106 |
MetaphAdd(J);
|
|
2107 |
|
|
2108 |
if(GetAt(current + 1) == 'J')//it could happen!!
|
|
2109 |
current += 2;
|
|
2110 |
else
|
|
2111 |
current += 1;
|
|
2112 |
break;
|
|
2113 |
"
|
2213
|
2114 |
| currentWord firstWord nextLetter |
|
|
2115 |
currentWord := self inputKey copyFrom: currentIndex to: (currentIndex + 3 min: self inputKey size).
|
|
2116 |
firstWord := self inputKey copyFrom: 1 to: (4 min: self inputKey size).
|
|
2117 |
nextLetter := self keyAt: currentIndex + 1.
|
|
2118 |
(currentWord = 'JOSE' or: [firstWord = 'SAN '])
|
|
2119 |
ifTrue: [
|
|
2120 |
((currentIndex = 1 and: [self inputKey size = 4 or: [self inputKey size >= 5 and: [self keyAt: currentIndex + 4 = $ ]]])
|
|
2121 |
or: [firstWord = 'SAN '])
|
|
2122 |
ifTrue: [
|
|
2123 |
self addPrimaryTranslation: 'H';
|
|
2124 |
addSecondaryTranslation: 'H'.
|
|
2125 |
] ifFalse: [
|
|
2126 |
self addPrimaryTranslation: 'J';
|
|
2127 |
addSecondaryTranslation: 'H'.
|
|
2128 |
].
|
|
2129 |
^self.
|
|
2130 |
].
|
|
2131 |
(currentIndex = 1 and: [firstWord ~= 'JOSE'])
|
|
2132 |
ifTrue: [
|
|
2133 |
self addPrimaryTranslation: 'J';
|
|
2134 |
addSecondaryTranslation: 'A'.
|
|
2135 |
] ifFalse: [
|
|
2136 |
((currentIndex > 1 and: [(self keyAt: currentIndex -1) isVowel])
|
|
2137 |
and: [(self isSlavoGermanic: self inputKey) not and: [nextLetter = $A or: [nextLetter = $O]]])
|
|
2138 |
ifTrue: [
|
|
2139 |
self addPrimaryTranslation: 'J';
|
|
2140 |
addSecondaryTranslation: 'H'.
|
|
2141 |
] ifFalse: [
|
|
2142 |
currentIndex = self inputKey size
|
|
2143 |
ifTrue: [
|
|
2144 |
self addPrimaryTranslation: 'J';
|
|
2145 |
addSecondaryTranslation: ' '.
|
|
2146 |
] ifFalse: [
|
|
2147 |
((#($L $T $K $S $N $M $B $Z) includes: nextLetter) not and: [(#($S $K $L) includes: (self keyAt: currentIndex - 1)) not])
|
|
2148 |
ifTrue: [
|
|
2149 |
self addPrimaryTranslation: 'J';
|
|
2150 |
addSecondaryTranslation: 'J'.
|
|
2151 |
].
|
|
2152 |
].
|
|
2153 |
].
|
|
2154 |
].
|
|
2155 |
nextLetter = $J
|
|
2156 |
ifTrue: [
|
|
2157 |
self incrementSkipCount: 1.
|
|
2158 |
].
|
2208
|
2159 |
!
|
|
2160 |
|
|
2161 |
processK
|
2213
|
2162 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2163 |
case 'K':
|
2208
|
2164 |
if(GetAt(current + 1) == 'K')
|
|
2165 |
current += 2;
|
|
2166 |
else
|
|
2167 |
current += 1;
|
|
2168 |
MetaphAdd(K);
|
|
2169 |
break;
|
2213
|
2170 |
"
|
|
2171 |
|
|
2172 |
(self keyAt: currentIndex + 1) = $K
|
|
2173 |
ifTrue: [
|
|
2174 |
self incrementSkipCount: 1
|
|
2175 |
].
|
|
2176 |
self addPrimaryTranslation: 'K';
|
|
2177 |
addSecondaryTranslation: 'K'.
|
2208
|
2178 |
!
|
|
2179 |
|
|
2180 |
processL
|
|
2181 |
|
|
2182 |
"case 'L':
|
|
2183 |
if(GetAt(current + 1) == 'L')
|
|
2184 |
{
|
|
2185 |
//spanish e.g. 'cabrillo', 'gallegos'
|
|
2186 |
if(((current == (length - 3))
|
|
2187 |
AND StringAt((current - 1), 4, ILLO, ILLA, ALLE, ))
|
|
2188 |
OR ((StringAt((last - 1), 2, AS, OS, ) OR StringAt(last, 1, A, O, ))
|
|
2189 |
AND StringAt((current - 1), 4, ALLE, )) )
|
|
2190 |
{
|
|
2191 |
MetaphAdd(L, );
|
|
2192 |
current += 2;
|
|
2193 |
break;
|
|
2194 |
}
|
|
2195 |
current += 2;
|
|
2196 |
}else
|
|
2197 |
current += 1;
|
|
2198 |
MetaphAdd(L);
|
|
2199 |
break;
|
|
2200 |
"
|
2213
|
2201 |
| currentWord |
|
|
2202 |
(self keyAt: currentIndex + 1) = $L
|
|
2203 |
ifTrue: [
|
|
2204 |
(((currentIndex = (self inputKey size - 2))
|
|
2205 |
and: [(currentIndex > 1 and: [#('ILLO' 'ILLA' 'ALLE') includes: (currentWord := self inputKey copyFrom: currentIndex - 1 to: (currentIndex + 2 min: self inputKey size))])])
|
|
2206 |
or: [((#('AS' 'OS') includes: (self inputKey copyFrom: self inputKey size - 1 to: self inputKey size)) or: [#($A $O) includes: (self keyAt: self inputKey size)]) and: [currentWord = 'ALLE']
|
|
2207 |
])
|
|
2208 |
ifTrue: [
|
|
2209 |
self addPrimaryTranslation: 'L';
|
|
2210 |
addSecondaryTranslation: ' '.
|
|
2211 |
^self incrementSkipCount: 1.
|
|
2212 |
].
|
|
2213 |
self incrementSkipCount: 1.
|
|
2214 |
].
|
|
2215 |
self addPrimaryTranslation: 'L';
|
|
2216 |
addSecondaryTranslation: 'L'.
|
2208
|
2217 |
!
|
|
2218 |
|
|
2219 |
processM
|
|
2220 |
|
|
2221 |
"case 'M':
|
|
2222 |
if((StringAt((current - 1), 3, UMB, )
|
|
2223 |
AND (((current + 1) == last) OR StringAt((current + 2), 2, ER, )))
|
|
2224 |
//'dumb','thumb'
|
|
2225 |
OR (GetAt(current + 1) == 'M') )
|
|
2226 |
current += 2;
|
|
2227 |
else
|
|
2228 |
current += 1;
|
|
2229 |
MetaphAdd(M);
|
|
2230 |
break;
|
|
2231 |
"
|
2213
|
2232 |
(((currentIndex > 1 and: [(self inputKey copyFrom: currentIndex - 1 to: (currentIndex +1 min: self inputKey size)) = 'UMB'])
|
|
2233 |
and: [currentIndex + 1 = self inputKey size or: [(self inputKey copyFrom: (currentIndex + 2 min: self inputKey size) to: (currentIndex + 4 min: self inputKey size)) = 'ER']])
|
|
2234 |
or: [(self keyAt: currentIndex + 1) = $M])
|
|
2235 |
ifTrue: [
|
|
2236 |
self incrementSkipCount: 1.
|
|
2237 |
].
|
|
2238 |
self addPrimaryTranslation: 'M';
|
|
2239 |
addSecondaryTranslation: 'M'.
|
2208
|
2240 |
!
|
|
2241 |
|
|
2242 |
processN
|
2213
|
2243 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2244 |
case 'N':
|
2208
|
2245 |
if(GetAt(current + 1) == 'N')
|
|
2246 |
current += 2;
|
|
2247 |
else
|
|
2248 |
current += 1;
|
|
2249 |
MetaphAdd(N);
|
|
2250 |
break;
|
|
2251 |
|
2213
|
2252 |
"
|
|
2253 |
|
|
2254 |
(self keyAt: currentIndex + 1) = $N
|
|
2255 |
ifTrue: [
|
|
2256 |
self incrementSkipCount: 1
|
|
2257 |
].
|
|
2258 |
self addPrimaryTranslation: 'N';
|
|
2259 |
addSecondaryTranslation: 'N'.
|
2208
|
2260 |
!
|
|
2261 |
|
|
2262 |
processNtilde
|
|
2263 |
"case 'Ñ':
|
|
2264 |
current += 1;
|
|
2265 |
MetaphAdd(N);
|
|
2266 |
break;
|
|
2267 |
"
|
|
2268 |
self addPrimaryTranslation: 'N';
|
|
2269 |
addSecondaryTranslation: 'N'.
|
|
2270 |
!
|
|
2271 |
|
|
2272 |
processP
|
2213
|
2273 |
"case 'P':
|
2208
|
2274 |
if(GetAt(current + 1) == 'H')
|
|
2275 |
{
|
|
2276 |
MetaphAdd(F);
|
|
2277 |
current += 2;
|
|
2278 |
break;
|
|
2279 |
}
|
|
2280 |
|
|
2281 |
//also account for campbell, raspberry
|
|
2282 |
if(StringAt((current + 1), 1, P, B, ))
|
|
2283 |
current += 2;
|
|
2284 |
else
|
|
2285 |
current += 1;
|
|
2286 |
MetaphAdd(P);
|
|
2287 |
break;
|
|
2288 |
"
|
2213
|
2289 |
| nextLetter |
|
|
2290 |
(nextLetter := self keyAt: currentIndex + 1) = $H
|
|
2291 |
ifTrue: [
|
|
2292 |
self addPrimaryTranslation: 'F';
|
|
2293 |
addSecondaryTranslation: 'F'.
|
|
2294 |
^self incrementSkipCount: 1.
|
|
2295 |
].
|
|
2296 |
(#($P $B) includes: nextLetter)
|
|
2297 |
ifTrue: [
|
|
2298 |
self incrementSkipCount: 1.
|
|
2299 |
] ifFalse: [
|
|
2300 |
self addPrimaryTranslation: 'P';
|
|
2301 |
addSecondaryTranslation: 'P'.
|
|
2302 |
].
|
2208
|
2303 |
!
|
|
2304 |
|
|
2305 |
processQ
|
2213
|
2306 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2307 |
case 'Q':
|
2208
|
2308 |
if(GetAt(current + 1) == 'Q')
|
|
2309 |
current += 2;
|
|
2310 |
else
|
|
2311 |
current += 1;
|
|
2312 |
MetaphAdd(K);
|
|
2313 |
break;
|
|
2314 |
|
2213
|
2315 |
"
|
|
2316 |
|
|
2317 |
(self keyAt: currentIndex + 1) = $Q
|
|
2318 |
ifTrue: [
|
|
2319 |
self incrementSkipCount: 1
|
|
2320 |
].
|
|
2321 |
self addPrimaryTranslation: 'K';
|
|
2322 |
addSecondaryTranslation: 'K'.
|
2208
|
2323 |
!
|
|
2324 |
|
|
2325 |
processR
|
2213
|
2326 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2327 |
case 'R':
|
2208
|
2328 |
//french e.g. 'rogier', but exclude 'hochmeier'
|
|
2329 |
if((current == last)
|
|
2330 |
AND !!SlavoGermanic()
|
|
2331 |
AND StringAt((current - 2), 2, IE, )
|
|
2332 |
AND !!StringAt((current - 4), 2, ME, MA, ))
|
|
2333 |
MetaphAdd(, R);
|
|
2334 |
else
|
|
2335 |
MetaphAdd(R);
|
|
2336 |
|
|
2337 |
if(GetAt(current + 1) == 'R')
|
|
2338 |
current += 2;
|
|
2339 |
else
|
|
2340 |
current += 1;
|
|
2341 |
break;
|
2213
|
2342 |
"
|
|
2343 |
(currentIndex = self inputKey size and: [
|
|
2344 |
(self isSlavoGermanic: self inputKey) not and: [
|
|
2345 |
(self inputKey copyFrom: ((currentIndex - 2) max: 1) to: ((currentIndex - 1) max: 1)) = 'IE' and: [
|
|
2346 |
(#('ME' 'MA') includes: (self inputKey copyFrom: ((currentIndex - 4) max: 1) to: ((currentIndex - 3) max: 1))) not
|
|
2347 |
]
|
|
2348 |
]
|
|
2349 |
])
|
|
2350 |
ifTrue: [
|
|
2351 |
self addPrimaryTranslation: '';
|
|
2352 |
addSecondaryTranslation: 'R'.
|
|
2353 |
] ifFalse: [
|
|
2354 |
self addPrimaryTranslation: 'R';
|
|
2355 |
addSecondaryTranslation: 'R'.
|
|
2356 |
].
|
|
2357 |
(self keyAt: currentIndex + 1) = $R
|
|
2358 |
ifTrue: [
|
|
2359 |
self incrementSkipCount: 1
|
|
2360 |
].
|
2208
|
2361 |
!
|
|
2362 |
|
|
2363 |
processRemainingCharacters
|
|
2364 |
self startIndex to: self inputKey size do:[ :i |
|
|
2365 |
| c methodSelector |
|
|
2366 |
|
|
2367 |
self skipCount = 0 ifTrue:[
|
|
2368 |
((self primaryTranslation size > 4) and: [ self secondaryTranslation size > 4 ])
|
|
2369 |
ifTrue: [ ^self ].
|
|
2370 |
|
|
2371 |
self currentIndex: i.
|
|
2372 |
c := self keyAt: i.
|
|
2373 |
|
|
2374 |
(c isVowel not and: [c ~= $Y]) ifTrue:[
|
|
2375 |
c = $Ç ifTrue: [
|
|
2376 |
methodSelector := #processCedille
|
|
2377 |
] ifFalse: [ c = $Ñ ifTrue: [
|
|
2378 |
methodSelector := #processNtilde
|
|
2379 |
] ifFalse: [
|
|
2380 |
methodSelector := ('process', c asString) asSymbol
|
|
2381 |
]].
|
|
2382 |
self perform: methodSelector
|
|
2383 |
]
|
|
2384 |
] ifFalse: [
|
|
2385 |
self decrementSkipCount
|
|
2386 |
]
|
|
2387 |
]
|
|
2388 |
!
|
|
2389 |
|
|
2390 |
processS
|
2213
|
2391 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2392 |
case 'S':
|
2208
|
2393 |
//special cases 'island', 'isle', 'carlisle', 'carlysle'
|
|
2394 |
if(StringAt((current - 1), 3, ISL, YSL, ))
|
|
2395 |
{
|
|
2396 |
current += 1;
|
|
2397 |
break;
|
|
2398 |
}
|
|
2399 |
|
|
2400 |
//special case 'sugar-'
|
|
2401 |
if((current == 0) AND StringAt(current, 5, SUGAR, ))
|
|
2402 |
{
|
|
2403 |
MetaphAdd(X, S);
|
|
2404 |
current += 1;
|
|
2405 |
break;
|
|
2406 |
}
|
|
2407 |
|
|
2408 |
if(StringAt(current, 2, SH, ))
|
|
2409 |
{
|
|
2410 |
//germanic
|
|
2411 |
if(StringAt((current + 1), 4, HEIM, HOEK, HOLM, HOLZ, ))
|
|
2412 |
MetaphAdd(S);
|
|
2413 |
else
|
|
2414 |
MetaphAdd(X);
|
|
2415 |
current += 2;
|
|
2416 |
break;
|
|
2417 |
}
|
|
2418 |
|
|
2419 |
//italian & armenian
|
|
2420 |
if(StringAt(current, 3, SIO, SIA, ) OR StringAt(current, 4, SIAN, ))
|
|
2421 |
{
|
|
2422 |
if(!!SlavoGermanic())
|
|
2423 |
MetaphAdd(S, X);
|
|
2424 |
else
|
|
2425 |
MetaphAdd(S);
|
|
2426 |
current += 3;
|
|
2427 |
break;
|
|
2428 |
}
|
|
2429 |
|
|
2430 |
//german & anglicisations, e.g. 'smith' match 'schmidt', 'snider' match 'schneider'
|
|
2431 |
//also, -sz- in slavic language altho in hungarian it is pronounced 's'
|
|
2432 |
if(((current == 0)
|
|
2433 |
AND StringAt((current + 1), 1, M, N, L, W, ))
|
|
2434 |
OR StringAt((current + 1), 1, Z, ))
|
|
2435 |
{
|
|
2436 |
MetaphAdd(S, X);
|
|
2437 |
if(StringAt((current + 1), 1, Z, ))
|
|
2438 |
current += 2;
|
|
2439 |
else
|
|
2440 |
current += 1;
|
|
2441 |
break;
|
|
2442 |
}
|
|
2443 |
|
|
2444 |
if(StringAt(current, 2, SC, ))
|
|
2445 |
{
|
|
2446 |
//Schlesinger's rule
|
|
2447 |
if(GetAt(current + 2) == 'H')
|
|
2448 |
//dutch origin, e.g. 'school', 'schooner'
|
|
2449 |
if(StringAt((current + 3), 2, OO, ER, EN, UY, ED, EM, ))
|
|
2450 |
{
|
|
2451 |
//'schermerhorn', 'schenker'
|
|
2452 |
if(StringAt((current + 3), 2, ER, EN, ))
|
|
2453 |
{
|
|
2454 |
MetaphAdd(X, SK);
|
|
2455 |
}else
|
|
2456 |
MetaphAdd(SK);
|
|
2457 |
current += 3;
|
|
2458 |
break;
|
|
2459 |
}else{
|
|
2460 |
if((current == 0) AND !!IsVowel(3) AND (GetAt(3) !!= 'W'))
|
|
2461 |
MetaphAdd(X, S);
|
|
2462 |
else
|
|
2463 |
MetaphAdd(X);
|
|
2464 |
current += 3;
|
|
2465 |
break;
|
|
2466 |
}
|
|
2467 |
|
|
2468 |
if(StringAt((current + 2), 1, I, E, Y, ))
|
|
2469 |
{
|
|
2470 |
MetaphAdd(S);
|
|
2471 |
current += 3;
|
|
2472 |
break;
|
|
2473 |
}
|
|
2474 |
//else
|
|
2475 |
MetaphAdd(SK);
|
|
2476 |
current += 3;
|
|
2477 |
break;
|
|
2478 |
}
|
|
2479 |
|
|
2480 |
//french e.g. 'resnais', 'artois'
|
|
2481 |
if((current == last) AND StringAt((current - 2), 2, AI, OI, ))
|
|
2482 |
MetaphAdd(, S);
|
|
2483 |
else
|
|
2484 |
MetaphAdd(S);
|
|
2485 |
|
|
2486 |
if(StringAt((current + 1), 1, S, Z, ))
|
|
2487 |
current += 2;
|
|
2488 |
else
|
|
2489 |
current += 1;
|
|
2490 |
break;
|
|
2491 |
"
|
|
2492 |
|
2213
|
2493 |
| nextChar char2 chars char |
|
|
2494 |
(#('ISL' 'YSL') includes: (self inputKey copyFrom: (currentIndex - 1 max: 1) to: (currentIndex + 1 min: self inputKey size)))
|
|
2495 |
ifTrue: [
|
|
2496 |
^self
|
|
2497 |
].
|
|
2498 |
(currentIndex = 1 and: [(self inputKey copyFrom: 1 to: (5 min: self inputKey size)) = 'SUGAR'])
|
|
2499 |
ifTrue: [
|
|
2500 |
self addPrimaryTranslation: 'X';
|
|
2501 |
addSecondaryTranslation: 'S'.
|
|
2502 |
^self.
|
|
2503 |
].
|
|
2504 |
(self inputKey copyFrom: currentIndex to: ((currentIndex + 1) min: self inputKey size)) = 'SH'
|
|
2505 |
ifTrue: [
|
|
2506 |
(#('HEIM' 'HOEK' 'HOLM' 'HOLZ') includes: (self inputKey copyFrom: (currentIndex + 1 min: self inputKey size) to: ((currentIndex + 5) min: self inputKey size)))
|
|
2507 |
ifTrue: [
|
|
2508 |
self addPrimaryTranslation: 'S';
|
|
2509 |
addSecondaryTranslation: 'S'.
|
|
2510 |
] ifFalse: [
|
|
2511 |
self addPrimaryTranslation: 'X';
|
|
2512 |
addSecondaryTranslation: 'X'.
|
|
2513 |
].
|
|
2514 |
^self incrementSkipCount: 1
|
|
2515 |
].
|
|
2516 |
((#('SIO' 'SIA') includes: (self inputKey copyFrom: currentIndex to: (currentIndex + 2 min: self inputKey size)))
|
|
2517 |
or: [(self inputKey copyFrom: currentIndex to: (currentIndex + 3 min: self inputKey size)) = 'SIAN'])
|
|
2518 |
ifTrue: [
|
|
2519 |
(self isSlavoGermanic: self inputKey) not
|
|
2520 |
ifTrue: [
|
|
2521 |
self addPrimaryTranslation: 'S';
|
|
2522 |
addSecondaryTranslation: 'X'.
|
|
2523 |
] ifFalse: [
|
|
2524 |
self addPrimaryTranslation: 'S';
|
|
2525 |
addSecondaryTranslation: 'S'.
|
|
2526 |
].
|
|
2527 |
^self incrementSkipCount: 2
|
|
2528 |
].
|
|
2529 |
((currentIndex = 1 and: [#($M $N $L $W) includes: (self keyAt: currentIndex + 1)])
|
|
2530 |
or: [(nextChar := self keyAt: currentIndex + 1) = $Z])
|
|
2531 |
ifTrue: [
|
|
2532 |
self addPrimaryTranslation: 'S';
|
|
2533 |
addSecondaryTranslation: 'X'.
|
|
2534 |
nextChar = $Z
|
|
2535 |
ifTrue: [
|
|
2536 |
^self incrementSkipCount: 1.
|
|
2537 |
].
|
|
2538 |
^self.
|
|
2539 |
].
|
|
2540 |
((self inputKey copyFrom: currentIndex to: ((currentIndex + 1) min: self inputKey size)) = 'SC')
|
|
2541 |
ifTrue: [
|
|
2542 |
(char2 := self keyAt: currentIndex + 2) = $H
|
|
2543 |
ifTrue: [
|
|
2544 |
(#('OO' 'ER' 'EN' 'UY' 'ED' 'EM') includes: (chars := self inputKey copyFrom: ((currentIndex + 3) min: self inputKey size) to: ((currentIndex + 4) min: self inputKey size)))
|
|
2545 |
ifTrue: [
|
|
2546 |
(#('ER' 'EN') includes: chars)
|
|
2547 |
ifTrue: [
|
|
2548 |
self addPrimaryTranslation: 'X';
|
|
2549 |
addSecondaryTranslation: 'SK'.
|
|
2550 |
] ifFalse: [
|
|
2551 |
self addPrimaryTranslation: 'SK';
|
|
2552 |
addSecondaryTranslation: 'SK'.
|
|
2553 |
].
|
|
2554 |
^self incrementSkipCount: 2.
|
|
2555 |
] ifFalse: [
|
|
2556 |
((currentIndex = 1 and: [(char := self inputKey at: 4 ifAbsent: [$b]) isVowel not]) and: [char ~= $W])
|
|
2557 |
ifTrue: [
|
|
2558 |
self addPrimaryTranslation: 'X';
|
|
2559 |
addSecondaryTranslation: 'S'.
|
|
2560 |
] ifFalse: [
|
|
2561 |
self addPrimaryTranslation: 'X';
|
|
2562 |
addSecondaryTranslation: 'X'.
|
|
2563 |
].
|
|
2564 |
^self incrementSkipCount: 2.
|
|
2565 |
].
|
|
2566 |
] ifFalse: [
|
|
2567 |
(#($I $E $Y) includes: char2)
|
|
2568 |
ifTrue: [
|
|
2569 |
self addPrimaryTranslation: 'S';
|
|
2570 |
addSecondaryTranslation: 'S'.
|
|
2571 |
^self incrementSkipCount: 2.
|
|
2572 |
] ifFalse: [
|
|
2573 |
self addPrimaryTranslation: 'SK';
|
|
2574 |
addSecondaryTranslation: 'SK'.
|
|
2575 |
^self incrementSkipCount: 2.
|
|
2576 |
]
|
|
2577 |
].
|
|
2578 |
].
|
|
2579 |
(currentIndex = self inputKey size and: [(#('AI' 'OI') includes: (self inputKey copyFrom: ((currentIndex - 2) max: 1) to: ((currentIndex - 1) max: 1)))])
|
|
2580 |
ifTrue: [
|
|
2581 |
self addPrimaryTranslation: '';
|
|
2582 |
addSecondaryTranslation: 'S'.
|
|
2583 |
] ifFalse: [
|
|
2584 |
self addPrimaryTranslation: 'S';
|
|
2585 |
addSecondaryTranslation: 'S'.
|
|
2586 |
].
|
|
2587 |
(#($S $Z) includes: (self keyAt: currentIndex + 1))
|
|
2588 |
ifTrue: [
|
|
2589 |
^self incrementSkipCount: 1.
|
|
2590 |
].
|
2208
|
2591 |
!
|
|
2592 |
|
|
2593 |
processT
|
2213
|
2594 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2595 |
case 'T':
|
2208
|
2596 |
if(StringAt(current, 4, TION, ))
|
|
2597 |
{
|
|
2598 |
MetaphAdd(X);
|
|
2599 |
current += 3;
|
|
2600 |
break;
|
|
2601 |
}
|
|
2602 |
|
|
2603 |
if(StringAt(current, 3, TIA, TCH, ))
|
|
2604 |
{
|
|
2605 |
MetaphAdd(X);
|
|
2606 |
current += 3;
|
|
2607 |
break;
|
|
2608 |
}
|
|
2609 |
|
|
2610 |
if(StringAt(current, 2, TH, )
|
|
2611 |
OR StringAt(current, 3, TTH, ))
|
|
2612 |
{
|
|
2613 |
//special case 'thomas', 'thames' or germanic
|
|
2614 |
if(StringAt((current + 2), 2, OM, AM, )
|
|
2615 |
OR StringAt(0, 4, VAN , VON , )
|
|
2616 |
OR StringAt(0, 3, SCH, ))
|
|
2617 |
{
|
|
2618 |
MetaphAdd(T);
|
|
2619 |
}else{
|
|
2620 |
MetaphAdd(0, T);
|
|
2621 |
}
|
|
2622 |
current += 2;
|
|
2623 |
break;
|
|
2624 |
}
|
|
2625 |
|
|
2626 |
if(StringAt((current + 1), 1, T, D, ))
|
|
2627 |
current += 2;
|
|
2628 |
else
|
|
2629 |
current += 1;
|
|
2630 |
MetaphAdd(T);
|
|
2631 |
break;
|
|
2632 |
"
|
2213
|
2633 |
((self inputKey copyFrom: currentIndex to: ((currentIndex + 3) min: self inputKey size)) = 'TION')
|
|
2634 |
ifTrue: [
|
|
2635 |
self addPrimaryTranslation: 'X';
|
|
2636 |
addSecondaryTranslation: 'X'.
|
|
2637 |
^self incrementSkipCount: 2.
|
|
2638 |
].
|
|
2639 |
(#('TIA' 'TCH') includes: (self inputKey copyFrom: currentIndex to: ((currentIndex + 2) min: self inputKey size)))
|
|
2640 |
ifTrue: [
|
|
2641 |
self addPrimaryTranslation: 'X';
|
|
2642 |
addSecondaryTranslation: 'X'.
|
|
2643 |
^self incrementSkipCount: 2.
|
|
2644 |
].
|
|
2645 |
(((self inputKey copyFrom: currentIndex to: ((currentIndex + 1) min: self inputKey size)) = 'TH') or: [
|
|
2646 |
((self inputKey copyFrom: currentIndex to: ((currentIndex + 2) min: self inputKey size)) = 'TTH')
|
|
2647 |
])
|
|
2648 |
ifTrue: [
|
|
2649 |
((#('OM' 'AM') includes: (self inputKey copyFrom: currentIndex + 2 to: ((currentIndex + 3) min: self inputKey size)))
|
|
2650 |
or: [(#('VAN ' 'VON ') includes: (self inputKey copyFrom: 1 to: (4 min: self inputKey size)))
|
|
2651 |
or: [(self inputKey copyFrom: 1 to: (3 min: self inputKey size)) = 'SCH']
|
|
2652 |
])
|
|
2653 |
ifTrue: [
|
|
2654 |
self addPrimaryTranslation: 'T';
|
|
2655 |
addSecondaryTranslation: 'T'.
|
|
2656 |
] ifFalse: [
|
|
2657 |
self addPrimaryTranslation: '0';
|
|
2658 |
addSecondaryTranslation: 'T'.
|
|
2659 |
].
|
|
2660 |
^self incrementSkipCount: 1.
|
|
2661 |
].
|
|
2662 |
(#($T $D) includes: (self keyAt: currentIndex + 1))
|
|
2663 |
ifTrue: [
|
|
2664 |
self incrementSkipCount: 1.
|
|
2665 |
].
|
|
2666 |
self addPrimaryTranslation: 'T';
|
|
2667 |
addSecondaryTranslation: 'T'.
|
2208
|
2668 |
!
|
|
2669 |
|
|
2670 |
processV
|
2213
|
2671 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2672 |
case 'V':
|
2208
|
2673 |
if(GetAt(current + 1) == 'V')
|
|
2674 |
current += 2;
|
|
2675 |
else
|
|
2676 |
current += 1;
|
|
2677 |
MetaphAdd(F);
|
|
2678 |
break;
|
|
2679 |
|
|
2680 |
|
2213
|
2681 |
"
|
|
2682 |
|
|
2683 |
(self keyAt: currentIndex + 1) = $V
|
|
2684 |
ifTrue: [
|
|
2685 |
self incrementSkipCount: 1
|
|
2686 |
].
|
|
2687 |
self addPrimaryTranslation: 'F';
|
|
2688 |
addSecondaryTranslation: 'F'.
|
2208
|
2689 |
!
|
|
2690 |
|
|
2691 |
processW
|
2213
|
2692 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2693 |
case 'W':
|
2208
|
2694 |
//can also be in middle of word
|
|
2695 |
if(StringAt(current, 2, WR, ))
|
|
2696 |
{
|
|
2697 |
MetaphAdd(R);
|
|
2698 |
current += 2;
|
|
2699 |
break;
|
|
2700 |
}
|
|
2701 |
|
|
2702 |
if((current == 0)
|
|
2703 |
AND (IsVowel(current + 1) OR StringAt(current, 2, WH, )))
|
|
2704 |
{
|
|
2705 |
//Wasserman should match Vasserman
|
|
2706 |
if(IsVowel(current + 1))
|
|
2707 |
MetaphAdd(A, F);
|
|
2708 |
else
|
|
2709 |
//need Uomo to match Womo
|
|
2710 |
MetaphAdd(A);
|
|
2711 |
}
|
|
2712 |
|
|
2713 |
//Arnow should match Arnoff
|
|
2714 |
if(((current == last) AND IsVowel(current - 1))
|
|
2715 |
OR StringAt((current - 1), 5, EWSKI, EWSKY, OWSKI, OWSKY, )
|
|
2716 |
OR StringAt(0, 3, SCH, ))
|
2213
|
2717 |
{
|
2208
|
2718 |
MetaphAdd(, F);
|
|
2719 |
current +=1;
|
|
2720 |
break;
|
|
2721 |
}
|
|
2722 |
|
|
2723 |
//polish e.g. 'filipowicz'
|
|
2724 |
if(StringAt(current, 4, WICZ, WITZ, ))
|
|
2725 |
{
|
|
2726 |
MetaphAdd(TS, FX);
|
|
2727 |
current +=4;
|
|
2728 |
break;
|
|
2729 |
}
|
|
2730 |
|
|
2731 |
//else skip it
|
|
2732 |
current +=1;
|
|
2733 |
break;
|
|
2734 |
"
|
2213
|
2735 |
| word nextLetter |
|
|
2736 |
((word := self inputKey copyFrom: currentIndex to: (currentIndex + 1 min: self inputKey size)) = 'WR')
|
|
2737 |
ifTrue: [
|
|
2738 |
self addPrimaryTranslation: 'R';
|
|
2739 |
addSecondaryTranslation: 'R'.
|
|
2740 |
^self incrementSkipCount: 1
|
|
2741 |
].
|
|
2742 |
((currentIndex = 1 and: [(nextLetter := self keyAt: currentIndex + 1) isVowel]) or: [
|
|
2743 |
word = 'WH'
|
|
2744 |
])
|
|
2745 |
ifTrue: [
|
|
2746 |
nextLetter isVowel
|
|
2747 |
ifTrue: [
|
|
2748 |
self addPrimaryTranslation: 'A';
|
|
2749 |
addSecondaryTranslation: 'F'.
|
|
2750 |
] ifFalse: [
|
|
2751 |
self addPrimaryTranslation: 'A';
|
|
2752 |
addSecondaryTranslation: 'A'.
|
|
2753 |
]
|
|
2754 |
].
|
|
2755 |
((((currentIndex = self inputKey size) and: [(self keyAt: currentIndex - 1) isVowel])
|
|
2756 |
or: [#('EWSKI' 'EWSKY' 'OWSKI' 'OWSKY') includes: (self inputKey copyFrom: ((currentIndex - 1) max: 1) to: (currentIndex + 3 min: self inputKey size))])
|
|
2757 |
or: [(self inputKey copyFrom: 1 to: 3) = 'SCH'])
|
|
2758 |
ifTrue: [
|
|
2759 |
self addPrimaryTranslation: '';
|
|
2760 |
addSecondaryTranslation: 'F'.
|
|
2761 |
^self.
|
|
2762 |
].
|
|
2763 |
(#('WICZ' 'WITZ') includes: (self inputKey copyFrom: currentIndex to: (currentIndex + 4 min: self inputKey size)))
|
|
2764 |
ifTrue: [
|
|
2765 |
self addPrimaryTranslation: 'TS';
|
|
2766 |
addSecondaryTranslation: 'FX'.
|
|
2767 |
^self incrementSkipCount: 3
|
|
2768 |
].
|
2208
|
2769 |
!
|
|
2770 |
|
|
2771 |
processX
|
2213
|
2772 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2773 |
case 'X':
|
2208
|
2774 |
//french e.g. breaux
|
|
2775 |
if(!!((current == last)
|
|
2776 |
AND (StringAt((current - 3), 3, IAU, EAU, )
|
|
2777 |
OR StringAt((current - 2), 2, AU, OU, ))) )
|
|
2778 |
MetaphAdd(KS);
|
|
2779 |
|
|
2780 |
if(StringAt((current + 1), 1, C, X, ))
|
|
2781 |
current += 2;
|
|
2782 |
else
|
|
2783 |
current += 1;
|
|
2784 |
break;
|
|
2785 |
"
|
|
2786 |
|
|
2787 |
|
2213
|
2788 |
((currentIndex = self inputKey size) and: [(#('IAU' 'EAU') includes: (self inputKey copyFrom: ((currentIndex - 3) min: 1) to: currentIndex)) or: [(#('AU' 'OU') includes: (self inputKey copyFrom: ((currentIndex - 2) min: 1) to: currentIndex))]]) not
|
|
2789 |
ifTrue: [
|
|
2790 |
self addPrimaryTranslation: 'KS';
|
|
2791 |
addSecondaryTranslation: 'KS'.
|
|
2792 |
].
|
|
2793 |
(#($C $X) includes: (self keyAt: currentIndex + 1))
|
|
2794 |
ifTrue: [
|
|
2795 |
^self incrementSkipCount: 1
|
|
2796 |
]
|
2208
|
2797 |
!
|
|
2798 |
|
|
2799 |
processZ
|
2213
|
2800 |
"http://aspell.sourceforge.net/metaphone/dmetaph.cpp
|
|
2801 |
case 'Z':
|
2208
|
2802 |
//chinese pinyin e.g. 'zhao'
|
|
2803 |
if(GetAt(current + 1) == 'H')
|
|
2804 |
{
|
|
2805 |
MetaphAdd(J);
|
|
2806 |
current += 2;
|
|
2807 |
break;
|
|
2808 |
}else
|
|
2809 |
if(StringAt((current + 1), 2, ZO, ZI, ZA, )
|
|
2810 |
OR (SlavoGermanic() AND ((current > 0) AND GetAt(current - 1) !!= 'T')))
|
|
2811 |
{
|
|
2812 |
MetaphAdd(S, TS);
|
|
2813 |
}
|
|
2814 |
else
|
|
2815 |
MetaphAdd(S);
|
|
2816 |
|
|
2817 |
if(GetAt(current + 1) == 'Z')
|
|
2818 |
current += 2;
|
|
2819 |
else
|
|
2820 |
current += 1;
|
|
2821 |
break;
|
|
2822 |
"
|
|
2823 |
|
2213
|
2824 |
(self keyAt: currentIndex + 1) = $H
|
|
2825 |
ifTrue: [
|
|
2826 |
self addPrimaryTranslation: 'J';
|
|
2827 |
addSecondaryTranslation: 'J'.
|
|
2828 |
^self incrementSkipCount: 1
|
|
2829 |
] ifFalse: [
|
|
2830 |
((#('ZO' 'ZI' 'ZA') includes: (self inputKey copyFrom: ((currentIndex + 1) min: self inputKey size) to: ((currentIndex + 2) min: self inputKey size))) or: [
|
|
2831 |
(self isSlavoGermanic: self inputKey) and: [(currentIndex > 1 and: [(self keyAt: currentIndex - 1) ~= 'T'])]
|
|
2832 |
])
|
|
2833 |
ifTrue: [
|
|
2834 |
self addPrimaryTranslation: 'S';
|
|
2835 |
addSecondaryTranslation: 'TS'.
|
|
2836 |
] ifFalse: [
|
|
2837 |
self addPrimaryTranslation: 'S';
|
|
2838 |
addSecondaryTranslation: 'S'.
|
|
2839 |
].
|
|
2840 |
(self keyAt: currentIndex + 1) = $Z
|
|
2841 |
ifTrue: [
|
|
2842 |
^self incrementSkipCount: 1
|
|
2843 |
].
|
|
2844 |
]
|
2208
|
2845 |
! !
|
|
2846 |
|
|
2847 |
!PhoneticStringUtilities::MiracodeStringComparator class methodsFor:'documentation'!
|
|
2848 |
|
|
2849 |
documentation
|
|
2850 |
"
|
|
2851 |
Miracode (also called American Soundex) is like Soundex with the addition that h and w are
|
|
2852 |
discarded if they separate consonants.
|
|
2853 |
|
|
2854 |
These variants may be specifically important because they were used in U.S. National Archives.
|
|
2855 |
Most archive data were encoded with Miracode, but there are some entries encoded with
|
|
2856 |
Simplified Soundex.
|
|
2857 |
|
|
2858 |
The HW-rule was documented as a standard in 1910, but actually data of 1880, 1900 and 1910
|
|
2859 |
censuses were encoded with mixed methods.
|
|
2860 |
"
|
|
2861 |
! !
|
|
2862 |
|
|
2863 |
!PhoneticStringUtilities::MiracodeStringComparator methodsFor:'api'!
|
|
2864 |
|
|
2865 |
phoneticStringsFor:aString
|
|
2866 |
|u p t prevCode|
|
|
2867 |
|
|
2868 |
u := aString asUppercase.
|
|
2869 |
p := u first asString.
|
|
2870 |
prevCode := self translate:u first.
|
|
2871 |
u from:2 to:u size do:[:c |
|
|
2872 |
t := self translate:c.
|
|
2873 |
(t notNil
|
|
2874 |
and:[ t ~= '0'
|
|
2875 |
and:[ t ~= prevCode ]]) ifTrue:[
|
|
2876 |
p := p , t.
|
|
2877 |
p size == 4 ifTrue:[^ Array with:p ].
|
|
2878 |
].
|
|
2879 |
(c ~= $W and:[c ~= $H]) ifTrue:[
|
|
2880 |
prevCode := t.
|
|
2881 |
].
|
|
2882 |
].
|
|
2883 |
[ p size < 4 ] whileTrue:[
|
|
2884 |
p := p , '0'
|
|
2885 |
].
|
|
2886 |
^ Array with:(p copyFrom:1 to:4)
|
|
2887 |
! !
|
|
2888 |
|
2197
|
2889 |
!PhoneticStringUtilities class methodsFor:'documentation'!
|
|
2890 |
|
|
2891 |
version
|
2285
|
2892 |
^ '$Header: /cvs/stx/stx/libbasic2/PhoneticStringUtilities.st,v 1.9 2009-10-01 08:46:37 cg Exp $'
|
|
2893 |
!
|
|
2894 |
|
|
2895 |
version_CVS
|
|
2896 |
^ '$Header: /cvs/stx/stx/libbasic2/PhoneticStringUtilities.st,v 1.9 2009-10-01 08:46:37 cg Exp $'
|
2197
|
2897 |
! !
|