Skip to content
Browse files

Some work on the Norvig checker in Clojure.

  • Loading branch information...
0 parents commit b76c15b50a1fc4bbe3114bcdd4b5e3bcbb634c04 @smerrill committed Jul 30, 2012
Showing with 49 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +13 −0 README
  3. +3 −0 project.clj
  4. +19 −0 src/norvig_checker/core.clj
  5. +6 −0 test/norvig_checker/test/core.clj
8 .gitignore
@@ -0,0 +1,8 @@
+/pom.xml
+*jar
+/lib
+/classes
+/native
+/.lein-failures
+/checkouts
+/.lein-deps-sum
13 README
@@ -0,0 +1,13 @@
+# norvig-checker
+
+FIXME: write description
+
+## Usage
+
+FIXME: write
+
+## License
+
+Copyright (C) 2012 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
3 project.clj
@@ -0,0 +1,3 @@
+(defproject norvig-checker "1.0.0-SNAPSHOT"
+ :description "FIXME: write description"
+ :dependencies [[org.clojure/clojure "1.3.0"]])
19 src/norvig_checker/core.clj
@@ -0,0 +1,19 @@
+(ns norvig-checker.core)
+(use '[clojure.string :only (lower-case)])
+(defn words [x] (re-seq #"[a-z]+" (lower-case x)))
+(def NWORDS (frequencies (words (slurp "small.txt")))) ; @TODO: Move from slurp.
+;(words (slurp "big.txt"))
+(def alphabet "abcdefghijklmnopqrstuvwxyz")
+(defn correct [words] (filter #(contains? NWORDS %) (list words)))
+(defn edits1 [word]
+ (let [len (count word)]
+ (for [a (range len)]
+ (concat
+ (concat (take a word) (drop (inc a) word)) ; Deletions
+ (if (< a (dec len)) (concat (take a word) (list (get word (inc a))) (list (get word a)) (drop (inc (inc a)) word)) nil) ; Transposes (yuck)
+ (map #(concat (take a word) (list %) (drop (inc a) word)) alphabet) ; Replaces
+ (map #(concat (take a word) (list %) (drop a word)) alphabet) ; Inserts
+ )
+ )))
+
+(edits1 "hi")
6 test/norvig_checker/test/core.clj
@@ -0,0 +1,6 @@
+(ns norvig-checker.test.core
+ (:use [norvig-checker.core])
+ (:use [clojure.test]))
+
+(deftest replace-me ;; FIXME: write
+ (is false "No tests have been written."))

0 comments on commit b76c15b

Please sign in to comment.
Something went wrong with that request. Please try again.