spelling: minor cleanup.

clean-macosx-x86-64
John Benediktsson 2019-10-31 14:55:47 -07:00
parent e256a4ba18
commit 4c48f03fe1
1 changed files with 13 additions and 15 deletions

View File

@ -1,7 +1,9 @@
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: arrays ascii assocs combinators combinators.smart fry USING: arrays ascii assocs combinators combinators.smart fry
http.client io.encodings.ascii io.files io.files.temp kernel http.client io.encodings.ascii io.files io.files.temp kernel
literals locals math math.ranges math.statistics memoize locals math math.ranges math.statistics memoize sequences
sequences sequences.private sets sorting splitting strings urls ; sequences.private sorting splitting urls ;
IN: spelling IN: spelling
! http://norvig.com/spell-correct.html ! http://norvig.com/spell-correct.html
@ -12,23 +14,19 @@ CONSTANT: ALPHABET "abcdefghijklmnopqrstuvwxyz"
[ length <iota> ] keep '[ _ remove-nth ] map ; [ length <iota> ] keep '[ _ remove-nth ] map ;
: transposes ( word -- edits ) : transposes ( word -- edits )
[ length [1,b) ] keep '[ [ length [1,b) ] keep
dup 1 - _ clone [ exchange-unsafe ] keep '[ dup 1 - _ clone [ exchange-unsafe ] keep ] map ;
] map ;
: replace1 ( i word -- words )
[ ALPHABET ] 2dip bounds-check
'[ _ _ clone [ set-nth-unsafe ] keep ] { } map-as ;
: replaces ( word -- edits ) : replaces ( word -- edits )
[ length <iota> ] keep '[ [ length <iota> ] keep '[ _ replace1 ] map concat ;
ALPHABET [
swap _ clone [ set-nth-unsafe ] keep
] with { } map-as
] map concat ;
: inserts ( word -- edits ) : inserts ( word -- edits )
[ length [0,b] ] keep '[ [ length [0,b] ] keep
CHAR: ? over _ insert-nth ALPHABET swap [ '[ CHAR: ? over _ insert-nth replace1 ] map concat ;
swapd clone [ set-nth-unsafe ] keep
] curry with { } map-as
] map concat ;
: edits1 ( word -- edits ) : edits1 ( word -- edits )
[ [