]> gitweb.factorcode.org Git - factor.git/commitdiff
did-you-mean: prototype of a spelling corrector word search
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Jan 2022 22:30:42 +0000 (14:30 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Jan 2022 22:30:42 +0000 (14:30 -0800)
extra/did-you-mean/authors.txt [new file with mode: 0644]
extra/did-you-mean/did-you-mean.factor [new file with mode: 0644]

diff --git a/extra/did-you-mean/authors.txt b/extra/did-you-mean/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/did-you-mean/did-you-mean.factor b/extra/did-you-mean/did-you-mean.factor
new file mode 100644 (file)
index 0000000..3008536
--- /dev/null
@@ -0,0 +1,12 @@
+! 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 ;
+
+IN: did-you-mean
+
+: did-you-mean ( name -- words )
+    dup all-words [ [ name>> ] histogram-by corrections ] keep
+    [ name>> swap member? ] with filter
+    <no-word-error> throw-restarts no-word-restarted ;