|
|
|
@ -12,22 +12,13 @@ file and a prose file, and returns a stream of words and possible
|
|
|
|
|
substitutions. The library is responsible for generating that list. |
|
|
|
|
-} |
|
|
|
|
{-# LANGUAGE OverloadedStrings #-} |
|
|
|
|
module Lib (Suggestion(..), spellcheck, suggestions, lDistance) where |
|
|
|
|
module Text.Spellcheck (Suggestion(..), spellcheck, suggestions, lDistance) where |
|
|
|
|
import qualified Data.Text as T |
|
|
|
|
import Data.List |
|
|
|
|
import Data.Array |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data Suggestion a = Suggestion Int a |
|
|
|
|
|
|
|
|
|
instance (Show a) => Show (Suggestion a) where |
|
|
|
|
show (Suggestion i a) = "Suggestion" ++ show a ++ ", distance " ++ show i |
|
|
|
|
|
|
|
|
|
instance (Eq a) => Eq (Suggestion a) where |
|
|
|
|
(Suggestion a b) == (Suggestion c d) = (a == c) && (b == d) |
|
|
|
|
|
|
|
|
|
instance (Ord a) => Ord (Suggestion a) where |
|
|
|
|
(Suggestion i _) <= (Suggestion j _) = i <= j |
|
|
|
|
data Suggestion a = Suggestion Int a deriving (Show, Ord, Eq) |
|
|
|
|
|
|
|
|
|
spellcheck :: (Ord a) => [[a]] -> [[a]] -> [([a], [Suggestion [a]])] |
|
|
|
|
spellcheck dict words = zip words $ map (suggestions dict) words |