1 ! Copyright (C) 2022 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors arrays assocs continuations formatting kernel
5 math math.statistics parser sequences sorting spelling vocabs
10 : did-you-mean-restarts ( possibilities -- restarts )
12 [ [ [ vocabulary>> ] [ name>> ] bi "Use %s:%s" sprintf ] keep ]
15 : did-you-mean-restarts-with-defer ( name possibilities -- restarts )
16 did-you-mean-restarts "Defer word in current vocabulary"
19 : <did-you-mean> ( name possibilities -- error restarts )
20 [ drop \ no-word-error boa ]
21 [ did-you-mean-restarts-with-defer ] 2bi ;
23 : did-you-mean ( name -- word )
24 dup all-words [ [ name>> ] histogram-by corrections ] keep
25 [ name>> swap member? ] with filter
26 <did-you-mean> throw-restarts no-word-restarted ;