From: John Benediktsson Date: Wed, 26 Jan 2022 02:55:46 +0000 (-0800) Subject: did-you-mean: tweak the restarts X-Git-Tag: 0.99~1639 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=92f8f6446a9c70af2353e64d3e077e6ac8109208 did-you-mean: tweak the restarts --- diff --git a/extra/did-you-mean/did-you-mean.factor b/extra/did-you-mean/did-you-mean.factor index 300853630e..ec17d33e23 100644 --- a/extra/did-you-mean/did-you-mean.factor +++ b/extra/did-you-mean/did-you-mean.factor @@ -1,12 +1,26 @@ ! Copyright (C) 2022 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: accessors assocs continuations kernel math -math.statistics parser sequences spelling vocabs vocabs.parser ; +USING: accessors arrays assocs continuations formatting kernel +math math.statistics parser sequences sorting spelling vocabs +vocabs.parser ; IN: did-you-mean -: did-you-mean ( name -- words ) +: did-you-mean-restarts ( possibilities -- restarts ) + natural-sort + [ [ [ vocabulary>> ] [ name>> ] bi "Use %s:%s" sprintf ] keep ] + { } map>assoc ; + +: did-you-mean-restarts-with-defer ( name possibilities -- restarts ) + did-you-mean-restarts "Defer word in current vocabulary" + rot 2array suffix ; + +: ( name possibilities -- error restarts ) + [ drop \ no-word-error boa ] + [ did-you-mean-restarts-with-defer ] 2bi ; + +: did-you-mean ( name -- word ) dup all-words [ [ name>> ] histogram-by corrections ] keep [ name>> swap member? ] with filter - throw-restarts no-word-restarted ; + throw-restarts no-word-restarted ;