extensions.st
changeset 2199 a9d3b1aa9f03
parent 2150 bdd3b90b3dae
child 2237 3b041af2bf04
--- a/extensions.st	Mon Aug 10 15:37:02 2009 +0200
+++ b/extensions.st	Mon Aug 10 15:39:26 2009 +0200
@@ -1,6 +1,97 @@
 "{ Package: 'stx:libbasic2' }"
 !
 
+!CharacterArray methodsFor:'converting'!
+
+asKoelnerPhoneticCode
+    "return a koelner phonetic code.
+     The koelnerPhonetic code is for the german language what the soundex code is for english;
+     it returns simular strings for similar sounding words. 
+     There are some differences to soundex, though: 
+        its length is not limited to 4, but depends on the length of the original string;
+        it does not start with the first character of the input."
+
+    ^ PhoneticStringUtilities koelnerPhoneticCodeOf:self 
+
+    "
+     #(
+        'Müller'
+        'Miller'
+        'Mueller'
+        'Mühler'
+        'Mühlherr'
+        'Mülherr'
+        'Myler'
+        'Millar'
+        'Myller'
+        'Müllar'
+        'Müler'
+        'Muehler'
+        'Mülller'
+        'Müllerr'
+        'Muehlherr'
+        'Muellar'
+        'Mueler'
+        'Mülleer'
+        'Mueller'
+        'Nüller'
+        'Nyller'
+        'Niler'
+        'Czerny'
+        'Tscherny'
+        'Czernie'
+        'Tschernie'
+        'Schernie'
+        'Scherny'
+        'Scherno'
+        'Czerne'
+        'Zerny'
+        'Tzernie'
+        'Breschnew'
+     ) do:[:w |
+         Transcript show:w; show:'->'; showCR:(w asKoelnerPhoneticCode)
+     ].
+    "
+
+    "
+     'Breschnew' asKoelnerPhoneticCode -> '17863'
+     'Breschnew' asKoelnerPhoneticCode -> '17863'
+     'Breschneff' asKoelnerPhoneticCode -> '17863'
+     'Braeschneff' asKoelnerPhoneticCode -> '17863'
+     'Braessneff' asKoelnerPhoneticCode -> '17863'
+     'Pressneff' asKoelnerPhoneticCode -> '17863'
+     'Presznäph' asKoelnerPhoneticCode -> '17863'
+    "
+! !
+
+!CharacterArray methodsFor:'converting'!
+
+asSoundexCode
+    "return a soundex phonetic code or nil.
+     Soundex returns similar codes for similar sounding words, making it a useful
+     tool when searching for words where the correct spelling is unknown.
+     (read Knuth or search the web if you dont know what a soundex code is).
+     Caveat: 'similar sounding words' means: 'similar sounding in english'."
+
+    ^ PhoneticStringUtilities soundexCodeOf:self
+
+    "
+     'claus' asSoundexCode     
+     'clause' asSoundexCode
+     'close' asSoundexCode
+     'smalltalk' asSoundexCode
+     'smaltalk' asSoundexCode
+     'smaltak' asSoundexCode
+     'smaltok' asSoundexCode
+     'smoltok' asSoundexCode
+     'aa' asSoundexCode
+     'by' asSoundexCode
+     'bab' asSoundexCode
+     'bob' asSoundexCode
+     'bop' asSoundexCode
+    "
+! !
+
 !Object methodsFor:'dependents-interests'!
 
 addInterest:anInterest