summaryrefslogtreecommitdiff
path: root/spellcheck/mutate.scm
diff options
context:
space:
mode:
Diffstat (limited to 'spellcheck/mutate.scm')
-rw-r--r--spellcheck/mutate.scm43
1 files changed, 43 insertions, 0 deletions
diff --git a/spellcheck/mutate.scm b/spellcheck/mutate.scm
new file mode 100644
index 0000000..117d0b3
--- /dev/null
+++ b/spellcheck/mutate.scm
@@ -0,0 +1,43 @@
+(define-module (mutate)
+ #:use-module (srfi srfi-1)
+ #:export (deletes
+ transposes
+ replaces
+ inserts))
+
+
+;; see https://norvig.com/spell-correct.html
+;; this is a translation of that from python
+;; to guile
+(define (deletes word)
+ (define (deletes-helper word splits result)
+ (if (null? splits)
+ result
+ (let* ((split (car splits))
+ (tail (cdr split)))
+ (if (zero? (string-length tail))
+ (deletes-helper word (cdr splits) result)
+ (deletes-helper word (cdr splits)
+ (append result
+ (list (string-append (car split) (substring tail 1)))))))))
+ (deletes-helper word (splits word) '()))
+
+(define (transposes word)
+ #t)
+
+(define (replaces word)
+ #t)
+
+(define (inserts word)
+ #t)
+
+
+(define (splits word)
+ "Given WORD, returns a list of pairs of
+all possible splits:
+
+'six' ->
+(('' . 'six') ('s' . 'ix') ('si' . 'x') ('six' . ''))"
+ (map (lambda (s) (cons (substring word 0 s)
+ (substring word s)))
+ (iota (1+ (string-length word)))))