Bumped up to 0.1

main
Sam Hatfield 2020-08-18 21:15:06 -05:00
parent 310b8b8dae
commit 0187b87158
Signed by: sehqlr
GPG Key ID: 6B1E0EDE1530CA2B
6 changed files with 26 additions and 9 deletions

View File

@ -1 +1,3 @@
# Changes

View File

@ -1,3 +1,15 @@
{-|
Module : Text.Spellcheck
Description : Spell, my attempt at a simple spellchecker
Copyright : (c) Sam Hatfield, 2020
License : GPL-3
Maintainer : hey@samhatfield.me
Stability : experimental
Portability: POSIX
This is the executable for Spell. It takes the string representation
of the spelling suggestions and outputs them to stdout.
-}
{-# LANGUAGE OverloadedStrings #-}
import Text.Spellcheck
import qualified Data.Text as T
@ -6,6 +18,7 @@ import Options.Applicative
import Data.Semigroup ((<>))
-- |Parses commandline options and loads that into a configuration option
configuration :: Parser Configuration
configuration = Configuration
<$> strOption
@ -20,6 +33,7 @@ configuration = Configuration
<> value 3
<> metavar "INT" )
-- |Combines the 'runChecker' with the optparse configuration
main :: IO ()
main = runChecker =<< execParser opts
where
@ -28,6 +42,7 @@ main = runChecker =<< execParser opts
<> progDesc "Print spelling suggestions from a stream of text. Either pipe the input to spell or enter text and press CTRL-D"
<> header "spell - a simple spellchecker" )
-- |Takes 'Configuration' and feeds it into the 'spellchecker' function
runChecker :: Configuration -> IO ()
runChecker config = do
dictionary <- readFile (dictionaryPath config)

View File

@ -4,7 +4,7 @@
}:
mkDerivation {
pname = "spell";
version = "0.0.0.0";
version = "0.1.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;

View File

@ -1,6 +1,6 @@
spec-version: 0.30.0
name: spell
version: 0.0.0.0
version: 0.1.0.0
license: BSD3
author: sehqlr
maintainer: sehqlr

View File

@ -1,7 +1,7 @@
{-|
Module : Text.Spellcheck
Description : Spell, my attempt at a simple spellchecker
Copyright : (c) sehqlr, 2020
Copyright : (c) Sam Hatfield, 2020
License : GPL-3
Maintainer : hey@samhatfield.me
Stability : experimental
@ -31,11 +31,11 @@ data Suggestion a = Suggestion Int a deriving (Show, Ord, Eq)
-- |This is this module's entry function. It takes a 'Configuration',
-- a dictionary, and some words, runs 'spellcheckEntries' on those words,
-- and concats all the stringified 'Entries' to form the terminal UI.
-- and concats all the stringified entries to form the terminal UI.
spellchecker :: (Show a, Ord a) => Configuration-> [[a]] -> [[a]] -> String
spellchecker (Configuration path max) dict wrds = concat $ map stringifyEntry $ spellcheckEntries max dict wrds
-- |Convert a 'Suggestion' to a String representation, to pass to the 'Main' module
-- |Convert a 'Suggestion' to a String representation, to pass to the executable
stringifyEntry :: Show a => ([a], [Suggestion [a]]) -> String
stringifyEntry (wrd, sugs) =
concat [ "No entry for "

View File

@ -14,26 +14,26 @@ import Data.Text as T hiding (head, last, length, null)
import Data.List
-- |A word is a string between 1 and 100 characters
genWord :: Gen String
genWord =
Gen.list (Range.linear 1 100) Gen.alpha
genSuggestion :: Gen (Suggestion String)
genSuggestion =
Suggestion <$> Gen.integral (Range.constantFrom 1 0 100) <*> genWord
-- |A word's edit distance with itself is zero
prop_lDistance_of_a_word_with_itself_is_zero :: Property
prop_lDistance_of_a_word_with_itself_is_zero =
property $ do
w <- forAll genWord
lDistance w w === 0
-- |Prepend @a@ to a generated word, and check that the edit distance is one
prop_lDistance_of_two_words_one_char_apart_is_one :: Property
prop_lDistance_of_two_words_one_char_apart_is_one =
property $ do
w <- forAll genWord
let w' = 'a':w in lDistance w w' === 1
-- |A dictionary is a list of generated words
genDict :: Gen [String]
genDict =
Gen.list (Range.linear 1 1000) genWord