Database Reference
In-Depth Information
6.
The second primary function gets the edits of the edits of a word, but only if
they're known in the training set:
(defn known-edits-2 [word]
(set (filter (partial contains? n-words)
(apply union
(map #(edits-1 %)
(edits-1 word))))))
7.
Now, we need another utility function that takes a sequence of words and returns
the set of those seen in the training corpus:
(defn known [words]
(set (filter (partial contains? n-words) words)))
8.
Finally, we can put it all together to create the correct function:
(defn correct [word]
(let [candidate-thunks [#(known (list word))
#(known (edits-1 word))
#(known-edits-2 word)
#(list word)]]
(->>
candidate-thunks
(map (fn [f] (f)))
(filter #(> (count %) 0))
first
(map (fn [w] [(get n-words w 1) w]))
(reduce (partial max-key first))
second)))
Let's see how it works:
user=> (correct "deete")
"delete"
user=> (correct "editr")
"editor"
user=> (correct "tranpsose")
"tranpsose"
user=> (correct "eidtor")
"editor"
 
Search WWH ::




Custom Search