1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: sequences grouping assocs kernel ascii ascii tr ;
8 "AEHIOUWYBFPVCGJKQSXZDTLMNR"
9 "00000000111122222222334556" ;
11 : remove-duplicates ( seq -- seq' )
12 #! Remove _consecutive_ duplicates (unlike prune which removes
14 [ 2 <clumps> [ = not ] assoc-filter values ] [ first ] bi prefix ;
16 : first>upper ( seq -- seq' ) 1 head >upper ;
17 : trim-first ( seq -- seq' ) dup first [ = ] curry trim-left ;
18 : remove-zeroes ( seq -- seq' ) CHAR: 0 swap remove ;
19 : remove-non-alpha ( seq -- seq' ) [ alpha? ] filter ;
20 : pad-4 ( first seq -- seq' ) "000" 3append 4 head ;
22 : soundex ( string -- soundex )
23 remove-non-alpha [ f ] [
27 [ "" ] [ trim-first ] if-empty
28 [ "" ] [ remove-duplicates ] if-empty